Module: Pincushion::ModuleMethods

Defined in:
lib/pincushion.rb

Overview

module RootModuleMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#predicate_pincushion_rootObject (readonly)

Returns the value of attribute predicate_pincushion_root.



40
41
42
# File 'lib/pincushion.rb', line 40

def predicate_pincushion_root
  @predicate_pincushion_root
end

Instance Method Details

#all_predicatesObject



42
43
44
# File 'lib/pincushion.rb', line 42

def all_predicates
  predicate_pincushion_root.predicates
end

#all_predicates_hashObject



46
47
48
49
# File 'lib/pincushion.rb', line 46

def all_predicates_hash
  obj = new ""
  predicate_pincushion_root.predicates.map { |p| [p, obj.is?(p)] }.to_h
end

#identifiersObject



51
52
53
# File 'lib/pincushion.rb', line 51

def identifiers
  predicate_pincushion_root.identifiers
end

#included(mod) ⇒ Object



92
93
94
95
96
97
98
99
100
# File 'lib/pincushion.rb', line 92

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



55
56
57
58
# File 'lib/pincushion.rb', line 55

def is(*preds)
  preds.each { |pred| define_method(:"#{pred}?") { true } }
  self
end

#is_not(*preds) ⇒ Object



60
61
62
63
# File 'lib/pincushion.rb', line 60

def is_not(*preds)
  preds.each { |pred| define_method(:"#{pred}?") { false } }
  self
end

#named(*given_identifiers) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/pincushion.rb', line 65

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



78
79
80
81
82
83
# File 'lib/pincushion.rb', line 78

def that_are(*preds)
  mod = Module.new
  mod.include self
  mod.is(*preds)
  mod
end

#that_is(*preds) ⇒ Object



85
86
87
88
89
90
# File 'lib/pincushion.rb', line 85

def that_is(*preds)
  klass = Class.new
  klass.include self
  klass.is(*preds)
  klass
end