Sha256: 3f4c1abb0c81b7d3b3e624196c0647f24390af4f92d6a0f671a224d11c52ebba
Contents?: true
Size: 1.15 KB
Versions: 7
Compression:
Stored size: 1.15 KB
Contents
# frozen_string_literal: true require_relative 'validation' require_relative '../../model' module Lino module Builders module Mixins module Subcommands include Validation def initialize(state) @subcommands = Hamster::Vector.new(state[:subcommands] || []) super end 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 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 private def state super.merge(subcommands: @subcommands) end def build_subcommands @subcommands.map(&:build) end end end end end
Version data entries
7 entries across 7 versions & 1 rubygems