Class: ArchSpec::Rules::CannotDefineMethodRule

Inherits:
Object
  • Object
show all
Defined in:
lib/archspec/rules/protocol_rules.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, methods) ⇒ CannotDefineMethodRule

Returns a new instance of CannotDefineMethodRule.



126
127
128
129
# File 'lib/archspec/rules/protocol_rules.rb', line 126

def initialize(source, methods)
  @source = source.to_sym
  @method_names = Array(methods).flatten.map(&:to_sym)
end

Instance Attribute Details

#method_namesObject (readonly)

Returns the value of attribute method_names.



124
125
126
# File 'lib/archspec/rules/protocol_rules.rb', line 124

def method_names
  @method_names
end

#sourceObject (readonly)

Returns the value of attribute source.



124
125
126
# File 'lib/archspec/rules/protocol_rules.rb', line 124

def source
  @source
end

Instance Method Details

#evaluate(graph) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/archspec/rules/protocol_rules.rb', line 144

def evaluate(graph)
  graph.method_definitions_for_component(source).filter_map do |method_definition|
    next unless method_names.include?(method_definition.name)

    Diagnostic.new(
      rule: id,
      message: "#{source} must not define ##{method_definition.name}",
      location: method_definition.location,
      evidence: "#{method_definition.owner} defines #{method_definition.scope} method #{method_definition.name}"
    )
  end
end

#idObject



140
141
142
# File 'lib/archspec/rules/protocol_rules.rb', line 140

def id
  'methods.define_forbid'
end

#merge!(other) ⇒ Object



135
136
137
138
# File 'lib/archspec/rules/protocol_rules.rb', line 135

def merge!(other)
  @method_names |= other.method_names
  self
end

#merge_keyObject



131
132
133
# File 'lib/archspec/rules/protocol_rules.rb', line 131

def merge_key
  [self.class, source]
end