Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* Include into Object so that we can use this in any class we want.

  • Loading branch information...
commit 8c72629f17af4a0fdc98bc6386e7ecd3ebfcb917 1 parent fac7db0
@binarylogic authored
Showing with 10 additions and 16 deletions.
  1. +4 −0 CHANGELOG.rdoc
  2. +3 −10 Rakefile
  3. +3 −6 lib/addresslogic.rb
View
4 CHANGELOG.rdoc
@@ -1,3 +1,7 @@
+== 1.1.3
+
+* Include into Object so that we can use this in any class we want.
+
== 1.1.2
* Update defaults to use changes in 1.1.1
View
13 Rakefile
@@ -11,6 +11,7 @@ begin
gem.authors = ["Ben Johnson of Binary Logic"]
gem.rubyforge_project = "addresslogic"
end
+ Jeweler::RubyforgeTasks.new
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
end
@@ -35,14 +36,6 @@ rescue LoadError
end
end
-task :default => :test
+task :test => :check_dependencies
-begin
- require 'rake/contrib/sshpublisher'
- namespace :rubyforge do
- desc "Release gem to RubyForge"
- task :release => ["rubyforge:release:gem"]
- end
-rescue LoadError
- puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
-end
+task :default => :test
View
9 lib/addresslogic.rb
@@ -1,5 +1,3 @@
-require 'activerecord'
-
# = Address Logic
#
# 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)
@@ -14,7 +12,6 @@
#
# This adds a sigle method: address_parts. More on this method below...
module Addresslogic
-
def self.included(base)
base.extend ClassMethods
end
@@ -42,7 +39,7 @@ module InstanceMethods
# * <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.extract_options!
+ 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] || address_parts_fields
@@ -54,7 +51,7 @@ def address_parts(*args)
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.blank?
+ next if sub_parts.empty?
parts << sub_parts
else
next if !respond_to?(field)
@@ -74,4 +71,4 @@ def address_parts_fields
end
end
-ActiveRecord::Base.send(:include, Addresslogic)
+Object.send(:include, Addresslogic)
Please sign in to comment.
Something went wrong with that request. Please try again.