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? ⇒ Boolean
-
#apply!(option_case = cli_name) ⇒ Object
Links the usecase to the Cli via
option_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
24 25 26 27 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 24 def usecase raise "#{self} is to use to extend a class" unless self.is_a?(Class) @usecase ||= Kernel.const_get(self.to_s.split('::')[0..-2].join('::')) end |
Instance Method Details
#add_option(arg, desc = nil, &block) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 58 def add_option(arg, desc = nil, &block) self.tap do "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 = true end |
#applied? ⇒ Boolean
14 15 16 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 14 def applied? @applied || false end |
#apply!(option_case = cli_name) ⇒ Object
Links the usecase to the Cli via option_case
7 8 9 10 11 12 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 7 def apply!(option_case = cli_name) cli_config_case(option_case) (option_case) applied! self end |
#callback(&block) ⇒ Object
50 51 52 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 50 def callback(&block) @callback = block end |
#cli_name(arg_name = nil) ⇒ Object
It defaults to the use case preceded by dash
43 44 45 46 47 48 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 43 def cli_name(arg_name = nil) @cli_name = (arg_name.nil? ? @cli_name : arg_name).yield_self do |value| value = "-#{name}" if value.nil? value end end |
#description(value = nil) ⇒ Object Also known as: desc
29 30 31 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 29 def description(value = nil) @description = (value.nil? ? @description : value) end |
#name ⇒ Object
38 39 40 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 38 def name usecase.name end |
#options ⇒ Object
54 55 56 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 54 def @options ||= {} end |
#type ⇒ Object
34 35 36 |
# File 'lib/eco/api/usecases/cli/dsl.rb', line 34 def type usecase.type end |