Module: Guise::Introspection
- Defined in:
- lib/guise/introspection.rb
Overview
Introspection handles checking if a record has one or more guise
records
associated with it.
Instance Method Summary collapse
-
#has_any_guises?(*values) ⇒ true, false
Checks if the record has any
guise
records with identified by any of the specifiedvalues
. -
#has_guise?(value) ⇒ true, false
Checks if the record has a
guise
record identified by on the specifiedvalue
. -
#has_guises?(*values) ⇒ true, false
Checks if the record has
guise
records for all of the specifiedvalues
.
Instance Method Details
#has_any_guises?(*values) ⇒ true, false
Checks if the record has any guise
records with identified by any of
the specified values
.
30 31 32 |
# File 'lib/guise/introspection.rb', line 30 def has_any_guises?(*values) values.any? { |value| has_guise?(value) } end |
#has_guise?(value) ⇒ true, false
Checks if the record has a guise
record identified by on the specified
value
.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/guise/introspection.rb', line 12 def has_guise?(value) value = value.to_s.classify unless .values.include?(value) raise ArgumentError, "no such guise #{value}" end association(.association_name).reader.any? do |record| !record.marked_for_destruction? && record[.attribute] == value end end |
#has_guises?(*values) ⇒ true, false
Checks if the record has guise
records for all of the specified
values
.
39 40 41 |
# File 'lib/guise/introspection.rb', line 39 def has_guises?(*values) values.all? { |value| has_guise?(value) } end |