addresslogic 1.1.3 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +4 -0
- data/VERSION.yml +2 -2
- data/addresslogic.gemspec +1 -1
- data/lib/addresslogic.rb +16 -21
- metadata +1 -1
data/CHANGELOG.rdoc
CHANGED
data/VERSION.yml
CHANGED
data/addresslogic.gemspec
CHANGED
data/lib/addresslogic.rb
CHANGED
@@ -1,16 +1,4 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# This is a simple module that you can include into any classm as long as it has a street1, street2, city, state, zip, and country (optional)
|
4
|
-
# methods. Just include it into your class like so:
|
5
|
-
#
|
6
|
-
# class Address
|
7
|
-
# apply_addresslogic :fields => [:street1, :street2, :city, [:state, :zip], :country]
|
8
|
-
# end
|
9
|
-
#
|
10
|
-
# The above will return:
|
11
|
-
# ["Street1", "Street2", "City", "State Zip", "Country"]
|
12
|
-
#
|
13
|
-
# This adds a sigle method: address_parts. More on this method below...
|
1
|
+
# Provides common methods and tools for using addresses
|
14
2
|
module Addresslogic
|
15
3
|
def self.included(base)
|
16
4
|
base.extend ClassMethods
|
@@ -19,8 +7,20 @@ module Addresslogic
|
|
19
7
|
module ClassMethods
|
20
8
|
attr_accessor :address_parts_fields
|
21
9
|
|
22
|
-
|
23
|
-
|
10
|
+
# Mixes in useful methods for handling addresses.
|
11
|
+
#
|
12
|
+
# === Options
|
13
|
+
#
|
14
|
+
# * <tt>fields:</tt> array of fields (default: [:street1, :street2, [:city, [:state, :zip]], :country])
|
15
|
+
# * <tt>composition_namespace:</tt> prefixes fields names with this, great for use with composed_of in ActiveRecord.
|
16
|
+
def apply_addresslogic(options = {})
|
17
|
+
n = options[:composition_namespace]
|
18
|
+
self.address_parts_fields = options[:fields] || [
|
19
|
+
"#{n}street1".to_sym,
|
20
|
+
"#{n}street2".to_sym,
|
21
|
+
["#{n}city".to_sym, ["#{n}state".to_sym, "#{n}zip".to_sym]],
|
22
|
+
"#{n}country".to_sym
|
23
|
+
]
|
24
24
|
include Addresslogic::InstanceMethods
|
25
25
|
end
|
26
26
|
end
|
@@ -42,7 +42,7 @@ module Addresslogic
|
|
42
42
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
43
43
|
options[:only] = [options[:only]] if options[:only] && !options[:only].is_a?(Array)
|
44
44
|
options[:except] = [options[:except]] if options[:except] && !options[:except].is_a?(Array)
|
45
|
-
fields = args[0] || address_parts_fields
|
45
|
+
fields = args[0] || self.class.address_parts_fields
|
46
46
|
level = args[1] || 0
|
47
47
|
|
48
48
|
parts = []
|
@@ -63,11 +63,6 @@ module Addresslogic
|
|
63
63
|
|
64
64
|
parts
|
65
65
|
end
|
66
|
-
|
67
|
-
private
|
68
|
-
def address_parts_fields
|
69
|
-
self.class.address_parts_fields
|
70
|
-
end
|
71
66
|
end
|
72
67
|
end
|
73
68
|
|