Sha256: d7d6c335e82e79bf37c3379381e82a4956be96c215099d5752ab311b4e50c45c

Contents?: true

Size: 1.79 KB

Versions: 24

Compression:

Stored size: 1.79 KB

Contents

module Eco
  class CLI
    class Config

      attr_reader :cli

      def initialize(cli:)
        @cli = cli
      end

      def options
        cli.options
      end

      def args
        cli.args
      end

      def options_set
        @opions_set ||= Eco::CLI::Config::OptionsSet.new(core_config: self)
        @opions_set.tap do |opts_set|
          yield(opts_set, options) if block_given?
        end
      end

      def input(default_option: nil)
        @input ||= Eco::CLI::Config::Input.new(core_config: self, default_option: default_option)
        if block_given?
          @input.define(&Proc.new)
          self
        else
          @input
        end
      end

      def people(io: nil)
        if block_given?
          @people_load = Proc.new
          self
        else
          raise "There is no definition on how to load people" unless instance_variable_defined?(:@people_load) && @people_load
          unless io && io.is_a?(Eco::API::UseCases::BaseIO)
            raise "You need to provide Eco::API::UseCases::BaseIO object. Given: #{io.class}"
          end

          io = io.new(type: :import)
          @people_load.call(*io.params)
        end
      end

      def people_filters
        @people_filters ||= Eco::CLI::Config::PeopleFilters.new(core_config: self)
        @people_filters.tap do |filters|
          yield(filters) if block_given?
        end
      end

      def usecases
        @usecases ||= Eco::CLI::Config::UseCases.new(core_config: self)
        @usecases.tap do |cases|
          yield(cases) if block_given?
        end
      end

    end
  end
end

require_relative 'config/options_set'
require_relative 'config/input'
require_relative 'config/people_filters'
require_relative 'config/use_cases'

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
eco-helpers-1.1.8 lib/eco/cli/config.rb
eco-helpers-1.1.7 lib/eco/cli/config.rb
eco-helpers-1.1.6 lib/eco/cli/config.rb
eco-helpers-1.1.5 lib/eco/cli/config.rb
eco-helpers-1.1.4 lib/eco/cli/config.rb
eco-helpers-1.1.3 lib/eco/cli/config.rb
eco-helpers-1.1.2 lib/eco/cli/config.rb
eco-helpers-1.1.1 lib/eco/cli/config.rb
eco-helpers-1.0.14 lib/eco/cli/config.rb
eco-helpers-1.0.13 lib/eco/cli/config.rb
eco-helpers-1.0.12 lib/eco/cli/config.rb
eco-helpers-1.0.11 lib/eco/cli/config.rb
eco-helpers-1.0.10 lib/eco/cli/config.rb
eco-helpers-1.0.9 lib/eco/cli/config.rb
eco-helpers-1.0.8 lib/eco/cli/config.rb
eco-helpers-1.0.7 lib/eco/cli/config.rb
eco-helpers-1.0.6 lib/eco/cli/config.rb
eco-helpers-1.0.5 lib/eco/cli/config.rb
eco-helpers-1.0.4 lib/eco/cli/config.rb
eco-helpers-1.0.3 lib/eco/cli/config.rb