Module: ActiveAttr::QueryAttributes

Extended by:
ActiveSupport::Concern
Includes:
Attributes
Included in:
Model
Defined in:
lib/active_attr/query_attributes.rb

Overview

QueryAttributes provides instance methods for querying attributes.

Examples:

Usage

class Person
  include ActiveAttr::QueryAttributes
  attribute :name
end

person = Person.new
person.name? #=> false
person.name = "Chris Griego"
person.name? #=> true

Since:

Constant Summary

Constant Summary

Constants included from Attributes

Attributes::DEPRECATED_OBJECT_METHODS

Instance Method Summary (collapse)

Methods included from Attributes

#==, #attributes, #inspect, #read_attribute, #write_attribute

Instance Method Details

- (true, false) query_attribute(name)

Test the presence of an attribute

See Typecasting::BooleanTypecaster#call for more details.

Examples:

Query an attribute

person.query_attribute(:name)

Raises:

Since:

  • 0.3.0



44
45
46
47
48
49
50
# File 'lib/active_attr/query_attributes.rb', line 44

def query_attribute(name)
  if respond_to? "#{name}?"
    send "#{name}?"
  else
    raise UnknownAttributeError, "unknown attribute: #{name}"
  end
end