Module: Pincushion::ModuleMethods
- Defined in:
- lib/pincushion.rb
Overview
module RootModuleMethods
Instance Attribute Summary collapse
-
#predicate_pincushion_root ⇒ Object
readonly
Returns the value of attribute predicate_pincushion_root.
Instance Method Summary collapse
- #all_predicates ⇒ Object
- #all_predicates_hash ⇒ Object
- #identifiers ⇒ Object
- #included(mod) ⇒ Object
- #is(*preds) ⇒ Object
- #is_not(*preds) ⇒ Object
- #named(*given_identifiers) ⇒ Object
- #that_are(*preds) ⇒ Object
- #that_is(*preds) ⇒ Object
Instance Attribute Details
#predicate_pincushion_root ⇒ Object (readonly)
Returns the value of attribute predicate_pincushion_root.
61 62 63 |
# File 'lib/pincushion.rb', line 61 def predicate_pincushion_root @predicate_pincushion_root end |
Instance Method Details
#all_predicates ⇒ Object
63 64 65 |
# File 'lib/pincushion.rb', line 63 def all_predicates predicate_pincushion_root.predicates end |
#all_predicates_hash ⇒ Object
67 68 69 70 |
# File 'lib/pincushion.rb', line 67 def all_predicates_hash obj = new "" Hash[predicate_pincushion_root.predicates.map { |p| [p, obj.is?(p)] }] end |
#identifiers ⇒ Object
72 73 74 |
# File 'lib/pincushion.rb', line 72 def identifiers predicate_pincushion_root.identifiers end |
#included(mod) ⇒ Object
117 118 119 120 121 122 123 124 125 |
# File 'lib/pincushion.rb', line 117 def included(mod) base = self mod.instance_eval do @predicate_pincushion_root = base.predicate_pincushion_root extend ModuleMethods include InstanceMethods end end |
#is(*preds) ⇒ Object
76 77 78 79 80 |
# File 'lib/pincushion.rb', line 76 def is(*preds) Pincushion.validate(predicate_pincushion_root, preds) preds.each { |pred| define_method(:"#{pred}?") { true } } self end |
#is_not(*preds) ⇒ Object
82 83 84 85 86 |
# File 'lib/pincushion.rb', line 82 def is_not(*preds) Pincushion.validate(predicate_pincushion_root, preds) preds.each { |pred| define_method(:"#{pred}?") { false } } self end |
#named(*given_identifiers) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/pincushion.rb', line 88 def named(*given_identifiers) given_identifiers.each do |id| if identifiers.key?(id) fail DuplicateIdentifierError, "Identifier #{id} not unique: #{identifiers[id]} <> #{self}" end identifiers[id] = self end self end |
#that_are(*preds) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/pincushion.rb', line 101 def that_are(*preds) Pincushion.validate(predicate_pincushion_root, preds) base = self mod = Module.new { include base } mod.is(*preds) mod end |
#that_is(*preds) ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/pincushion.rb', line 109 def that_is(*preds) Pincushion.validate(predicate_pincushion_root, preds) base = self klass = Class.new { include base } klass.is(*preds) klass end |