module Guise::Introspection

{Introspection} handles checking if a record has one or more `guise` records associated with it.

Public Instance Methods

has_any_guises?(*values) click to toggle source

Checks if the record has any `guise` records with identified by any of the specified `values`.

@param [Array<String, Class, Symbol>] value `guise` to check @return [true, false]

# File lib/guise/introspection.rb, line 30
def has_any_guises?(*values)
  values.any? { |value| has_guise?(value) }
end
has_guise?(value) click to toggle source

Checks if the record has a `guise` record identified by on the specified `value`.

@param [String, Class, Symbol] value `guise` to check @return [true, false]

# File lib/guise/introspection.rb, line 12
def has_guise?(value)
  value = value.to_s.classify

  unless guise_options.values.include?(value)
    raise ArgumentError, "no such guise #{value}"
  end

  association(guise_options.association_name).reader.any? do |record|
    !record.marked_for_destruction? &&
      record[guise_options.attribute] == value
  end
end
has_guises?(*values) click to toggle source

Checks if the record has `guise` records for all of the specified `values`.

@param [Array<String, Class, Symbol>] value `guise` to check @return [true, false]

# File lib/guise/introspection.rb, line 39
def has_guises?(*values)
  values.all? { |value| has_guise?(value) }
end