JustinAiken/my_timeline-github

View on GitHub
app/scrapers/my_timeline/github/fork_event_builder.rb

Summary

Maintainability
A
0 mins
Test Coverage
module MyTimeline
  module Github
    class ForkEventBuilder < GithubBuilder

      def build_event
        return false if already_exists_in_db?

        event.linkable = fork_event
        event.user = user if MyTimeline.user_class
        event.save

        fork_event.event = event
        fork_event.save
      end

    private

      def event
        @event ||= MyTimeline::Event.create(
          happened_on:   github_event.created_at,
          original_id:   github_event.id,
          external_link: "https://www.github.com/#{user.settings(:github).user_name}/#{github_event.repo.name}",
          icon_name:     "github.png",
          importance:    5,
          public:        1,
          description:   "Forked #{link_user_repo(github_event.repo.name)}"
        )
      end

      def fork_event
        @fork_event ||= MyTimeline::Github::ForkEvent.new(
         happened_on: github_event.created_at,
         original_id: github_event.id,
         repo:        github_event.repo.name
        )
      end
    end
  end
end