Sha256: 09c1df0f1a0ed3d194ef51bb90db6cc8af96c3957ae3fc668afb77c609319a9f

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

require "optparse"
require "platina_world/runners/dry"
require "platina_world/runners/production"
require "platina_world/file_loader"

module PlatinaWorld
  class Command
    def initialize(argv = ARGV)
      @argv = argv
    end

    def call
      runner.run
    end

    private

    def runner
      runner_class.new(loaded_file)
    end

    def runner_class
      if dry_run?
        PlatinaWorld::Runners::Dry
      else
        PlatinaWorld::Runners::Production
      end
    end

    def loaded_file
      @loaded_file ||= PlatinaWorld::FileLoader.new(file_path).load
    end

    def file_path
      options["path"]
    end

    def dry_run?
      options["dry-run"]
    end

    def options
      @options ||= option_parser.getopts(@argv)
    end

    def option_parser
      @optin_parser ||= OptionParser.new do |opt|
        opt.version = PlatinaWorld::VERSION
        opt.on("-p", "--path [file]", "Configuration file path")
        opt.on("-n", "--dry-run", "run in dry-run mode")
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
platina_world-0.1.3 lib/platina_world/command.rb
platina_world-0.1.2.1 lib/platina_world/command.rb
platina_world-0.1.2 lib/platina_world/command.rb
platina_world-0.1.1 lib/platina_world/command.rb