Class: Necropsy::ConventionRules::Rule

Inherits:
Data
  • Object
show all
Defined in:
lib/necropsy/convention_rules.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, family:, methods: [], owner_patterns: [], ancestor_patterns: [], frameworks: []) ⇒ Rule

Returns a new instance of Rule.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/necropsy/convention_rules.rb', line 6

def initialize(id:, family:, methods: [], owner_patterns: [], ancestor_patterns: [], frameworks: [])
  id = id.to_s
  family = family.to_sym
  raise ArgumentError, 'rule id must not be empty' if id.empty?
  raise ArgumentError, 'rule family must not be empty' if family.to_s.empty?
  raise ArgumentError, 'rule methods must be bounded strings' unless Array(methods).all? do |name|
    name.is_a?(String) && !name.empty? && name.bytesize <= 128
  end
  raise ArgumentError, 'rule owner patterns must be bounded strings' unless Array(owner_patterns).all? do |pattern|
    pattern.is_a?(String) && !pattern.empty? && pattern.bytesize <= 256
  end
  raise ArgumentError, 'rule ancestor patterns must be bounded strings' unless Array(ancestor_patterns).all? do |pattern|
    pattern.is_a?(String) && !pattern.empty? && pattern.bytesize <= 256
  end
  raise ArgumentError, 'rule frameworks must be bounded strings' unless Array(frameworks).all? do |name|
    name.is_a?(String) && !name.empty? && name.bytesize <= 64
  end
  raise ArgumentError, 'rules may not be unscoped' if Array(owner_patterns).empty? && Array(ancestor_patterns).empty?

  super(
    id: id.freeze,
    family: family,
    method_names: Array(methods).map(&:to_s).uniq.sort.freeze,
    owner_patterns: Array(owner_patterns).map(&:to_s).uniq.sort.freeze,
    ancestor_patterns: Array(ancestor_patterns).map(&:to_s).uniq.sort.freeze,
    frameworks: Array(frameworks).map(&:to_s).uniq.sort.freeze
  )
end

Instance Attribute Details

#ancestor_patternsObject (readonly)

Returns the value of attribute ancestor_patterns

Returns:

  • (Object)

    the current value of ancestor_patterns



5
6
7
# File 'lib/necropsy/convention_rules.rb', line 5

def ancestor_patterns
  @ancestor_patterns
end

#familyObject (readonly)

Returns the value of attribute family

Returns:

  • (Object)

    the current value of family



5
6
7
# File 'lib/necropsy/convention_rules.rb', line 5

def family
  @family
end

#frameworksObject (readonly)

Returns the value of attribute frameworks

Returns:

  • (Object)

    the current value of frameworks



5
6
7
# File 'lib/necropsy/convention_rules.rb', line 5

def frameworks
  @frameworks
end

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



5
6
7
# File 'lib/necropsy/convention_rules.rb', line 5

def id
  @id
end

#method_namesObject (readonly)

Returns the value of attribute method_names

Returns:

  • (Object)

    the current value of method_names



5
6
7
# File 'lib/necropsy/convention_rules.rb', line 5

def method_names
  @method_names
end

#owner_patternsObject (readonly)

Returns the value of attribute owner_patterns

Returns:

  • (Object)

    the current value of owner_patterns



5
6
7
# File 'lib/necropsy/convention_rules.rb', line 5

def owner_patterns
  @owner_patterns
end