Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixing rails 3.2 deprecation warnings #2

Open
wants to merge 1 commit into from

1 participant

@nathansamson

No description provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 20, 2012
  1. Fixing rails 3.2 support

    Nathan Samson authored
This page is out of date. Refresh to see the latest.
Showing with 38 additions and 40 deletions.
  1. +38 −40 lib/addresslogic.rb
View
78 lib/addresslogic.rb
@@ -23,49 +23,47 @@ def apply_addresslogic(options = {})
]
self.addresslogic_options = options
- include Addresslogic::InstanceMethods
- end
- end
-
- module InstanceMethods
- # Returns the parts of an address in an array. Example:
- #
- # ["Street1", "Street2", "City", "State Zip", "Country"]
- #
- # This makes displaying addresses on your view pretty simple:
- #
- # address.address_parts.join("<br />")
- #
- # === Options
- #
- # * <tt>only:</tt> fields you want included in the result
- # * <tt>except:</tt> any fields you want excluded from the result
- def address_parts(*args)
- options = args.last.is_a?(Hash) ? args.pop : {}
- options[:only] = [options[:only]] if options[:only] && !options[:only].is_a?(Array)
- options[:except] = [options[:except]] if options[:except] && !options[:except].is_a?(Array)
- fields = args[0] || self.class.addresslogic_options[:fields]
- level = args[1] || 0
-
- parts = []
- fields.each do |field|
- if field.is_a?(Array)
- has_sub_array = field.find { |item| item.is_a?(Array) }
- separator = has_sub_array ? ", " : " "
- sub_parts = address_parts(field, level + 1, options).join(separator)
- next if sub_parts.empty?
- parts << sub_parts
- else
- next if !respond_to?(field)
- value = send(field)
- next if value.to_s.strip == "" || (options[:only] && !options[:only].include?(field)) || (options[:except] && options[:except].include?(field))
- parts << value
+ class_eval do
+ # Returns the parts of an address in an array. Example:
+ #
+ # ["Street1", "Street2", "City", "State Zip", "Country"]
+ #
+ # This makes displaying addresses on your view pretty simple:
+ #
+ # address.address_parts.join("<br />")
+ #
+ # === Options
+ #
+ # * <tt>only:</tt> fields you want included in the result
+ # * <tt>except:</tt> any fields you want excluded from the result
+ def address_parts(*args)
+ options = args.last.is_a?(Hash) ? args.pop : {}
+ options[:only] = [options[:only]] if options[:only] && !options[:only].is_a?(Array)
+ options[:except] = [options[:except]] if options[:except] && !options[:except].is_a?(Array)
+ fields = args[0] || self.class.addresslogic_options[:fields]
+ level = args[1] || 0
+
+ parts = []
+ fields.each do |field|
+ if field.is_a?(Array)
+ has_sub_array = field.find { |item| item.is_a?(Array) }
+ separator = has_sub_array ? ", " : " "
+ sub_parts = address_parts(field, level + 1, options).join(separator)
+ next if sub_parts.empty?
+ parts << sub_parts
+ else
+ next if !respond_to?(field)
+ value = send(field)
+ next if value.to_s.strip == "" || (options[:only] && !options[:only].include?(field)) || (options[:except] && options[:except].include?(field))
+ parts << value
+ end
+ end
+
+ parts
end
end
-
- parts
end
end
end
-Object.send(:include, Addresslogic)
+Object.send(:include, Addresslogic)
Something went wrong with that request. Please try again.