Module: Lino::Builders::Mixins::Subcommands
Instance Method Summary collapse
- #initialize(state) ⇒ Object
- #with_subcommand(subcommand, &block) ⇒ Object
- #with_subcommands(subcommands) ⇒ Object
Methods included from Validation
Instance Method Details
#initialize(state) ⇒ Object
12 13 14 15 |
# File 'lib/lino/builders/mixins/subcommands.rb', line 12 def initialize(state) @subcommands = Hamster::Vector.new(state[:subcommands] || []) super end |
#with_subcommand(subcommand, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/lino/builders/mixins/subcommands.rb', line 17 def with_subcommand(subcommand, &block) return self if nil_or_empty?(subcommand) with( subcommands: @subcommands.add( (block || ->(sub) { sub }).call( Builders::Subcommand.for_subcommand(subcommand) ) ) ) end |
#with_subcommands(subcommands) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/lino/builders/mixins/subcommands.rb', line 29 def with_subcommands(subcommands, &) return self if nil_or_empty?(subcommands) without_block = subcommands[0...-1] with_block = subcommands.last without_block .inject(self) { |s, sc| s.with_subcommand(sc) } .with_subcommand(with_block, &) end |