Module: Pinpoint::ModelSupport

Defined in:
lib/pinpoint/model_support.rb

Class Method Summary collapse

Class Method Details

.define_address_accessors(object, options = {}) ⇒ Object

Private: Defines address accessors for a given object.

object - The object to apply the accessors to options - A Hash of options to apply to the method call

:field_name - The String or Symbol representing the name of the
              field pair to create (eg: #venue and #venue=).
:prefix     - If set, then all fields which make up the Address
              will be prefixed with that string (eg: #venue_city
              instead of just #city) If you do not want field
              names to be prefixed simply set it to false.
              (defaults to the field name).

Example

# Without a Prefix
define_address_accessors my_object, field_name: :venue

# With a Prefix
define_address_accessors my_object, field_name: :address,
                                    prefix:     :venue

Returns nothing



31
32
33
34
35
36
37
38
39
# File 'lib/pinpoint/model_support.rb', line 31

def self.define_address_accessors(object, options = {})
  field_name                 = options.fetch(:field_name)
  options[:prefix]           = options.fetch(:prefix, field_name)
  options[:address_fields] ||= find_address_fields(object, options)

  define_address_reader(object, options)
  define_address_setter(object, options)
  define_address_predicates(object, options)
end