Module: Foobara::CommandPatternImplementation::Concerns::Subcommands
- Includes:
- Foobara::Concern
- Included in:
- Foobara::CommandPatternImplementation
- Defined in:
- foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/subcommands.rb
Defined Under Namespace
Modules: ClassMethods Classes: AlreadyRegisteredSubcommand, CannotAccessDomain, SubcommandNotRegistered
Instance Attribute Summary collapse
-
#is_subcommand ⇒ Object
Returns the value of attribute is_subcommand.
Instance Method Summary collapse
Methods included from Foobara::Concern
foobara_class_methods_module_for, foobara_concern?, included
Instance Attribute Details
#is_subcommand ⇒ Object
Returns the value of attribute is_subcommand.
11 12 13 |
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/subcommands.rb', line 11 def is_subcommand @is_subcommand end |
Instance Method Details
#run_subcommand!(subcommand_class, inputs = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/subcommands.rb', line 19 def run_subcommand!(subcommand_class, inputs = {}) domain = self.class.domain sub_domain = subcommand_class.domain unless domain.(sub_domain) raise CannotAccessDomain, "Cannot access #{sub_domain} or its commands because #{domain} does not depend on it" end verify_depends_on!(subcommand_class) subcommand = subcommand_class.new(inputs) subcommand.is_subcommand = true outcome = subcommand.run if outcome.success? outcome.result else outcome.errors.each do |error| # problem... inner command could have a different category but we want this to be a runtime error... # So I guess we should use our error class anyways but override its methods... # Or do we want to let the inner category reign? Issue with that is the subcommand could have the same # name as an input and collide (unlikely but possible.) # So what to do? Wrapper error? Maybe introduce a sub command category for the wrapper? # other solution instead.... add a runtime_path to Error add_subcommand_error(subcommand, error) end end end |
#subcommand? ⇒ Boolean
15 16 17 |
# File 'foobara-0.0.110/projects/command/src/command_pattern_implementation/concerns/subcommands.rb', line 15 def subcommand? is_subcommand end |