Class: FoodCritic::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/foodcritic/domain.rb

Overview

A rule to be matched against.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, name) ⇒ Rule

Returns a new instance of Rule.



82
83
84
85
86
# File 'lib/foodcritic/domain.rb', line 82

def initialize(code, name)
  @code, @name = code, name
  @tags = [code]
  @applies_to = Proc.new { |version| true }
end

Instance Attribute Details

#applies_toObject

Returns the value of attribute applies_to.



76
77
78
# File 'lib/foodcritic/domain.rb', line 76

def applies_to
  @applies_to
end

#attributesObject

Returns the value of attribute attributes.



76
77
78
# File 'lib/foodcritic/domain.rb', line 76

def attributes
  @attributes
end

#codeObject

Returns the value of attribute code.



76
77
78
# File 'lib/foodcritic/domain.rb', line 76

def code
  @code
end

#cookbookObject

Returns the value of attribute cookbook.



76
77
78
# File 'lib/foodcritic/domain.rb', line 76

def cookbook
  @cookbook
end

#environmentObject

Returns the value of attribute environment.



76
77
78
# File 'lib/foodcritic/domain.rb', line 76

def environment
  @environment
end

#libraryObject

Returns the value of attribute library.



76
77
78
# File 'lib/foodcritic/domain.rb', line 76

def library
  @library
end

#metadataObject

Returns the value of attribute metadata.



76
77
78
# File 'lib/foodcritic/domain.rb', line 76

def 
  @metadata
end

#nameObject

Returns the value of attribute name.



76
77
78
# File 'lib/foodcritic/domain.rb', line 76

def name
  @name
end

#providerObject

Returns the value of attribute provider.



76
77
78
# File 'lib/foodcritic/domain.rb', line 76

def provider
  @provider
end

#recipeObject

Returns the value of attribute recipe.



76
77
78
# File 'lib/foodcritic/domain.rb', line 76

def recipe
  @recipe
end

#resourceObject

Returns the value of attribute resource.



76
77
78
# File 'lib/foodcritic/domain.rb', line 76

def resource
  @resource
end

#roleObject

Returns the value of attribute role.



76
77
78
# File 'lib/foodcritic/domain.rb', line 76

def role
  @role
end

#tagsObject

The tags associated with this rule. Rule is always tagged with the tag ‘any` and the rule code.



90
91
92
# File 'lib/foodcritic/domain.rb', line 90

def tags
  ["any"] + @tags
end

#templateObject

Returns the value of attribute template.



76
77
78
# File 'lib/foodcritic/domain.rb', line 76

def template
  @template
end

Instance Method Details

#matches_tags?(tag_expr) ⇒ Boolean

Checks the rule tags to see if they match a Gherkin (Cucumber) expression

Returns:

  • (Boolean)


95
96
97
98
99
# File 'lib/foodcritic/domain.rb', line 95

def matches_tags?(tag_expr)
  ::Foodcritic::Gherkin::TagExpression.new(tag_expr).evaluate(
    tags.map { |tag| ::Foodcritic::Gherkin::Tag.new(nil, tag) }
  )
end

#to_sObject

Returns a string representation of this rule.



102
103
104
# File 'lib/foodcritic/domain.rb', line 102

def to_s
  "#{@code}: #{@name}"
end