Module: Eco::API::UseCases::Cli::DSL
- Included in:
- Eco::API::UseCases::Cli
- Defined in:
- lib/eco/api/usecases/cli/dsl.rb
Instance Attribute Summary collapse
-
#usecase ⇒ Object
Unless specified, assume Cli class hangs from its case namespace.
Instance Method Summary collapse
- #add_option(arg, desc = nil, &block) ⇒ Object
- #applied ⇒ Object
- #applied!(arg_case) ⇒ Object
- #applied?(arg_case) ⇒ Boolean
-
#apply!(arg_case = cli_name) ⇒ Object
Links the usecase to the Cli via
arg_case. - #callback(&block) ⇒ Object
-
#cli_name(arg_name = nil) ⇒ Object
It defaults to the use case preceded by dash.
- #description(value = nil) ⇒ Object (also: #desc)
- #name ⇒ Object
- #options ⇒ Object
- #type ⇒ Object
Instance Attribute Details
#usecase ⇒ Object
Unless specified, assume Cli class hangs from its case namespace
33 34 35 36 37 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 33 def usecase raise "#{self} is to use to extend a class" unless is_a?(Class) @usecase ||= Kernel.const_get(to_s.split('::')[0..-2].join('::')) end |
Instance Method Details
#add_option(arg, desc = nil, &block) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 70 def add_option(arg, desc = nil, &block) tap do puts "Overriding option '#{arg}' on case '#{name}'" if .key?(arg) @options[arg] = Eco::API::UseCases::Cli::Option.new(arg, desc, &block) end end |
#applied ⇒ Object
18 19 20 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 18 def applied @applied ||= {} end |
#applied!(arg_case) ⇒ Object
26 27 28 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 26 def applied!(arg_case) applied[arg_case] = true end |
#applied?(arg_case) ⇒ Boolean
22 23 24 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 22 def applied?(arg_case) applied[arg_case] || false end |
#apply!(arg_case = cli_name) ⇒ Object
Links the usecase to the Cli via arg_case
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 7 def apply!(arg_case = cli_name) # puts "Debug: (#{self}) Tried to call again cli.apply! on '#{arg_case}'" return self if applied?(arg_case) cli_config_case(arg_case) (arg_case) applied!(arg_case) self end |
#callback(&block) ⇒ Object
60 61 62 63 64 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 60 def callback(&block) return @callback unless block_given? @callback = block end |
#cli_name(arg_name = nil) ⇒ Object
It defaults to the use case preceded by dash
53 54 55 56 57 58 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 53 def cli_name(arg_name = nil) @cli_name = (arg_name.nil? ? @cli_name : arg_name).then do |value| value = "-#{name}" if value.nil? value end end |
#description(value = nil) ⇒ Object Also known as: desc
39 40 41 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 39 def description(value = nil) @description = (value.nil? ? @description : value) end |
#name ⇒ Object
48 49 50 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 48 def name usecase.name end |
#options ⇒ Object
66 67 68 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 66 def @options ||= {} end |
#type ⇒ Object
44 45 46 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 44 def type usecase.type end |