Module: Masterplan::DefineRules

Defined in:
lib/masterplan/define_rules.rb

Overview

Include this module into whatever code generates Masterplan::Documents - you get methods that make it easier to generate Masterplan::Rule objects.

Instance Method Summary collapse

Instance Method Details

#iterating_rule(example_value, options = {}) ⇒ Object

for iterating over each example in an array intead of using only the first to compare the data array with



21
22
23
24
25
# File 'lib/masterplan/define_rules.rb', line 21

def iterating_rule(example_value, options = {})
  if example_value
    Rule.new(example_value, :compare_each => true) 
  end
end

#rule(example_value, options = {}) ⇒ Object

This turns the supplied example_value (any object) into an object that carries rules about itself with it. The rules will be applied when a template is compared with assert_masterplan or Masterplan.compare. Rules are: (default): This always applies - the value must be of the same class as the example_value ‘allow_nil’: This allows the value to be nil (breaking the first rule) ‘included_in’: Pass an array of values - the value must be one of these ‘matches’: Pass a regexp - the value must match it, and be a String

There is one special rule that only works on hash keys: ‘optional’ : This makes the hash key optional, i.e. no error will occur if the key (and its value) are missing.



16
17
18
# File 'lib/masterplan/define_rules.rb', line 16

def rule(example_value, options = {})
  Rule.new(example_value, options)
end