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.
64 65 66 |
# File 'lib/pincushion.rb', line 64 def predicate_pincushion_root @predicate_pincushion_root end |
Instance Method Details
#all_predicates ⇒ Object
66 67 68 |
# File 'lib/pincushion.rb', line 66 def all_predicates predicate_pincushion_root.predicates end |
#all_predicates_hash ⇒ Object
70 71 72 73 |
# File 'lib/pincushion.rb', line 70 def all_predicates_hash obj = new "" predicate_pincushion_root.predicates.map { |p| [p, obj.is?(p)] }.to_h end |
#identifiers ⇒ Object
75 76 77 |
# File 'lib/pincushion.rb', line 75 def identifiers predicate_pincushion_root.identifiers end |
#included(mod) ⇒ Object
120 121 122 123 124 125 126 127 128 |
# File 'lib/pincushion.rb', line 120 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
79 80 81 82 83 |
# File 'lib/pincushion.rb', line 79 def is(*preds) Pincushion.validate(predicate_pincushion_root, preds) preds.each { |pred| define_method(:"#{pred}?") { true } } self end |
#is_not(*preds) ⇒ Object
85 86 87 88 89 |
# File 'lib/pincushion.rb', line 85 def is_not(*preds) Pincushion.validate(predicate_pincushion_root, preds) preds.each { |pred| define_method(:"#{pred}?") { false } } self end |
#named(*given_identifiers) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/pincushion.rb', line 91 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
104 105 106 107 108 109 110 |
# File 'lib/pincushion.rb', line 104 def that_are(*preds) Pincushion.validate(self, preds) mod = Module.new mod.include self mod.is(*preds) mod end |
#that_is(*preds) ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/pincushion.rb', line 112 def that_is(*preds) Pincushion.validate(self, preds) klass = Class.new klass.include self klass.is(*preds) klass end |