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.



84
85
86
87
88
# File 'lib/foodcritic/domain.rb', line 84

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.



78
79
80
# File 'lib/foodcritic/domain.rb', line 78

def applies_to
  @applies_to
end

#attributesObject

Returns the value of attribute attributes.



78
79
80
# File 'lib/foodcritic/domain.rb', line 78

def attributes
  @attributes
end

#codeObject

Returns the value of attribute code.



78
79
80
# File 'lib/foodcritic/domain.rb', line 78

def code
  @code
end

#cookbookObject

Returns the value of attribute cookbook.



78
79
80
# File 'lib/foodcritic/domain.rb', line 78

def cookbook
  @cookbook
end

#environmentObject

Returns the value of attribute environment.



78
79
80
# File 'lib/foodcritic/domain.rb', line 78

def environment
  @environment
end

#libraryObject

Returns the value of attribute library.



78
79
80
# File 'lib/foodcritic/domain.rb', line 78

def library
  @library
end

#metadataObject

Returns the value of attribute metadata.



78
79
80
# File 'lib/foodcritic/domain.rb', line 78

def 
  @metadata
end

#nameObject

Returns the value of attribute name.



78
79
80
# File 'lib/foodcritic/domain.rb', line 78

def name
  @name
end

#providerObject

Returns the value of attribute provider.



78
79
80
# File 'lib/foodcritic/domain.rb', line 78

def provider
  @provider
end

#recipeObject

Returns the value of attribute recipe.



78
79
80
# File 'lib/foodcritic/domain.rb', line 78

def recipe
  @recipe
end

#resourceObject

Returns the value of attribute resource.



78
79
80
# File 'lib/foodcritic/domain.rb', line 78

def resource
  @resource
end

#roleObject

Returns the value of attribute role.



78
79
80
# File 'lib/foodcritic/domain.rb', line 78

def role
  @role
end

#tagsObject

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



92
93
94
# File 'lib/foodcritic/domain.rb', line 92

def tags
  ["any"] + @tags
end

#templateObject

Returns the value of attribute template.



78
79
80
# File 'lib/foodcritic/domain.rb', line 78

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)


97
98
99
100
101
# File 'lib/foodcritic/domain.rb', line 97

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

#to_sObject

Returns a string representation of this rule.



104
105
106
# File 'lib/foodcritic/domain.rb', line 104

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