Class: BuilderBuilder
Instance Attribute Summary collapse
-
#map ⇒ Object
Returns the value of attribute map.
-
#rules ⇒ Object
Returns the value of attribute rules.
-
#target_class ⇒ Object
Returns the value of attribute target_class.
Instance Method Summary collapse
- #add_rule(&block) ⇒ Object
- #build(validate = true, skip_contingency = false) ⇒ Object
-
#initialize(target_class, rules = []) ⇒ BuilderBuilder
constructor
A new instance of BuilderBuilder.
- #validate_contradictions ⇒ Object
Constructor Details
#initialize(target_class, rules = []) ⇒ BuilderBuilder
Returns a new instance of BuilderBuilder.
7 8 9 10 11 |
# File 'lib/Builder/builder_builder.rb', line 7 def initialize(target_class, rules = []) @target_class = target_class @rules = rules @map = RuleMap.new end |
Instance Attribute Details
#map ⇒ Object
Returns the value of attribute map.
5 6 7 |
# File 'lib/Builder/builder_builder.rb', line 5 def map @map end |
#rules ⇒ Object
Returns the value of attribute rules.
5 6 7 |
# File 'lib/Builder/builder_builder.rb', line 5 def rules @rules end |
#target_class ⇒ Object
Returns the value of attribute target_class.
5 6 7 |
# File 'lib/Builder/builder_builder.rb', line 5 def target_class @target_class end |
Instance Method Details
#add_rule(&block) ⇒ Object
42 43 44 |
# File 'lib/Builder/builder_builder.rb', line 42 def add_rule(&block) rules.append(Rule.new(map, &block)) end |
#build(validate = true, skip_contingency = false) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/Builder/builder_builder.rb', line 13 def build(validate = true, skip_contingency = false) builder = Builder.new(target_class, rules) target_class.attributes.each do |attribute| builder.class.attr_accessor attribute end begin validate_contradictions if validate rescue Contingency => c raise c unless skip_contingency end builder end |
#validate_contradictions ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/Builder/builder_builder.rb', line 28 def validate_contradictions rules.each do |rule| other_rules = rules.reject do |other_rule| other_rule.equal?(rule) end next unless other_rules.any? do |other_rule| rule.contradictory?(other_rule) end raise ContradictionError end end |