Module: Pincushion::InstanceMethods

Defined in:
lib/pincushion.rb

Overview

module ModuleMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



132
133
134
# File 'lib/pincushion.rb', line 132

def name
  @name
end

Instance Method Details

#all?(*preds) ⇒ Boolean

Returns:

  • (Boolean)


177
178
179
# File 'lib/pincushion.rb', line 177

def all?(*preds)
  preds.all? { |pred| is?(pred) }
end

#all_predicatesObject



139
140
141
# File 'lib/pincushion.rb', line 139

def all_predicates
  self.class.all_predicates.merge(@additional_predicates)
end

#all_predicates_hashObject



143
144
145
# File 'lib/pincushion.rb', line 143

def all_predicates_hash
  Hash[all_predicates.map { |p| [p, is?(p)] }]
end

#any?(*preds) ⇒ Boolean

Returns:

  • (Boolean)


173
174
175
# File 'lib/pincushion.rb', line 173

def any?(*preds)
  preds.any? { |pred| is?(pred) }
end

#initialize(name, *_) ⇒ Object



134
135
136
137
# File 'lib/pincushion.rb', line 134

def initialize(name, *_)
  @name = name
  @additional_predicates = Set.new
end

#is(*preds) ⇒ Object



147
148
149
150
151
152
153
154
# File 'lib/pincushion.rb', line 147

def is(*preds)
  preds.each do |pred|
    define_singleton_method(:"#{pred}?") { true }
    @additional_predicates << pred
  end

  self
end

#is?(predicate) ⇒ Boolean

Returns:

  • (Boolean)


165
166
167
168
169
170
171
# File 'lib/pincushion.rb', line 165

def is?(predicate)
  unless all_predicates.include?(predicate)
    fail MissingPredicateError, "Unknown predicate #{predicate}"
  end

  send(:"#{predicate}?")
end

#is_not(*preds) ⇒ Object



156
157
158
159
160
161
162
163
# File 'lib/pincushion.rb', line 156

def is_not(*preds)
  preds.each do |pred|
    define_singleton_method(:"#{pred}?") { false }
    @additional_predicates << pred
  end

  self
end