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 CHANGED
@@ -1,3 +1,7 @@
1
+ == 1.1.4
2
+
3
+ * Added :composition_namespace option.
4
+
1
5
  == 1.1.3
2
6
 
3
7
  * Include into Object so that we can use this in any class we want.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
- :minor: 1
4
- :patch: 3
3
+ :minor: 2
4
+ :patch: 0
data/addresslogic.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{addresslogic}
8
- s.version = "1.1.3"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ben Johnson of Binary Logic"]
data/lib/addresslogic.rb CHANGED
@@ -1,16 +1,4 @@
1
- # = Address Logic
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
- def apply_addresslogic(args = {})
23
- self.address_parts_fields = args[:fields] || [:street1, :street2, [:city, [:state, :zip]], :country]
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: addresslogic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Johnson of Binary Logic