Class: ArchSpec::Rules::MustImplementOneOfRule
- Inherits:
-
Object
- Object
- ArchSpec::Rules::MustImplementOneOfRule
- Defined in:
- lib/archspec/rules/protocol_rules.rb
Instance Attribute Summary collapse
-
#method_names ⇒ Object
readonly
Returns the value of attribute method_names.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #evaluate(graph) ⇒ Object
- #id ⇒ Object
-
#initialize(source, method_names) ⇒ MustImplementOneOfRule
constructor
A new instance of MustImplementOneOfRule.
- #merge!(other) ⇒ Object
- #merge_key ⇒ Object
Constructor Details
#initialize(source, method_names) ⇒ MustImplementOneOfRule
Returns a new instance of MustImplementOneOfRule.
81 82 83 84 |
# File 'lib/archspec/rules/protocol_rules.rb', line 81 def initialize(source, method_names) @source = source.to_sym @method_names = Array(method_names).flatten.map(&:to_sym) end |
Instance Attribute Details
#method_names ⇒ Object (readonly)
Returns the value of attribute method_names.
79 80 81 |
# File 'lib/archspec/rules/protocol_rules.rb', line 79 def method_names @method_names end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
79 80 81 |
# File 'lib/archspec/rules/protocol_rules.rb', line 79 def source @source end |
Instance Method Details
#evaluate(graph) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/archspec/rules/protocol_rules.rb', line 99 def evaluate(graph) constants_for(graph).filter_map do |constant| next if method_names.any? { |method_name| constant.instance_methods.include?(method_name) } Diagnostic.new( rule: id, message: "#{constant.name} must implement one of #{method_names.map { |name| "##{name}" }.join(", ")}", location: constant.location, evidence: "#{constant.name} methods: #{constant.instance_methods.to_a.sort.join(", ")}" ) end end |
#id ⇒ Object
95 96 97 |
# File 'lib/archspec/rules/protocol_rules.rb', line 95 def id "protocol.must_implement_one_of" end |
#merge!(other) ⇒ Object
90 91 92 93 |
# File 'lib/archspec/rules/protocol_rules.rb', line 90 def merge!(other) @method_names |= other.method_names self end |
#merge_key ⇒ Object
86 87 88 |
# File 'lib/archspec/rules/protocol_rules.rb', line 86 def merge_key [self.class, source] end |