Sha256: 0a4a34d272e54630530ed4a0dab3bebebf87f5732e08d4bf3946fe6e831b1125

Contents?: true

Size: 1.27 KB

Versions: 5

Compression:

Stored size: 1.27 KB

Contents

module LearnOpen
  class Opener
    attr_reader :editor,
                :target_lesson,
                :get_next_lesson,
                :clone_only,
                :io,
                :logger,
                :options

    def self.run(lesson:, editor_specified:, get_next_lesson:, clone_only:)
      new(lesson, editor_specified, get_next_lesson, clone_only).run
    end

    def initialize(target_lesson, editor, get_next_lesson, clone_only, options = {})
      @target_lesson = target_lesson
      @editor = editor
      @get_next_lesson = get_next_lesson
      @clone_only = clone_only

      @io = options.fetch(:io, LearnOpen.default_io)
      @logger = options.fetch(:logger, LearnOpen.logger)

      @options = options
    end

    def run
      logger.log('Getting lesson...')
      io.puts "Looking for lesson..."

      lesson_data = LearnOpen::Adapters::LearnWebAdapter
                        .new(options)
                        .fetch_lesson_data(
                            target_lesson: target_lesson,
                            fetch_next_lesson: get_next_lesson
                        )

      lesson = Lessons.classify(lesson_data, options)
      environment = LearnOpen::Environments.classify(options)
      lesson.open(environment, editor, clone_only)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
learn-open-1.2.28 lib/learn_open/opener.rb
learn-open-1.2.27 lib/learn_open/opener.rb
learn-open-1.2.26 lib/learn_open/opener.rb
learn-open-1.2.24 lib/learn_open/opener.rb
learn-open-1.2.23 lib/learn_open/opener.rb