Module: Addresslogic::ClassMethods

Defined in:
lib/addresslogic.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) addresslogic_options

Returns the value of attribute addresslogic_options



8
9
10
# File 'lib/addresslogic.rb', line 8

def addresslogic_options
  @addresslogic_options
end

Instance Method Details

- (Object) apply_addresslogic(options = {})

Mixes in useful methods for handling addresses.

Options

  • fields: array of fields (default: [:street1, :street2, [:city, [:state, :zip]], :country])

  • namespace: prefixes fields names with this, great for use with composed_of in ActiveRecord.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/addresslogic.rb', line 16

def apply_addresslogic(options = {})
  n = options[:namespace]
  options[:fields] ||= [
    "#{n}street1".to_sym,
    "#{n}street2".to_sym,
    ["#{n}city".to_sym, ["#{n}state".to_sym, "#{n}zip".to_sym]],
    "#{n}country".to_sym
  ]
  self.addresslogic_options = options
  
  include Addresslogic::InstanceMethods
end