Module: Foobara::CommandPatternImplementation::Concerns::Subcommands::ClassMethods

Defined in:
foobara-0.1.7/projects/command/src/command_pattern_implementation/concerns/subcommands.rb

Instance Method Summary collapse

Instance Method Details

#depends_on(*subcommand_classes) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'foobara-0.1.7/projects/command/src/command_pattern_implementation/concerns/subcommands.rb', line 58

def depends_on(*subcommand_classes)
  if subcommand_classes.empty?
    return @depends_on if defined?(@depends_on)

    # TODO: get Command and DomainMapper out of here!
    @depends_on = if self == Foobara::Command || self == Foobara::DomainMapper
                    Set.new
                  else
                    superclass.depends_on.dup
                  end

    return @depends_on
  end

  if subcommand_classes.length == 1
    subcommand_classes = Util.array(subcommand_classes.first)
  end

  subcommand_classes.each do |subcommand_class|
    subcommand_name = subcommand_class.scoped_full_name.to_sym

    if depends_on.include?(subcommand_name)
      # :nocov:
      raise AlreadyRegisteredSubcommand,
            "Already registered #{subcommand_class} as a dependency of #{self}"
      # :nocov:
    end

    depends_on << subcommand_name

    register_possible_subcommand_errors(subcommand_class)
  end
end

#depends_on?(subcommand_name) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
# File 'foobara-0.1.7/projects/command/src/command_pattern_implementation/concerns/subcommands.rb', line 50

def depends_on?(subcommand_name)
  if subcommand_name.is_a?(Class)
    subcommand_name = subcommand_name.scoped_full_name.to_sym
  end

  depends_on.include?(subcommand_name.to_sym)
end

#verify_depends_on!(subcommand_class) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
# File 'foobara-0.1.7/projects/command/src/command_pattern_implementation/concerns/subcommands.rb', line 92

def verify_depends_on!(subcommand_class)
  unless domain_map_criteria
    return if subcommand_class < DomainMapper
  end

  unless depends_on?(subcommand_class)
    # :nocov:
    raise SubcommandNotRegistered, "Need to declare #{subcommand_class} on #{self} with .depends_on"
    # :nocov:
  end
end