Permalink
Browse files

ap - adding scopes for ip columns

  • Loading branch information...
1 parent 57e0b6f commit 6c17ad3079c7f697fbe34f1dda801674c1d25081 @apeckham committed Jan 6, 2009
Showing with 9 additions and 7 deletions.
  1. +9 −7 lib/ip_column.rb
View
16 lib/ip_column.rb
@@ -11,19 +11,21 @@ def inet_aton(ascii)
end
end
- def has_ip_column(name)
+ def has_ip_column(column_name)
extend Helper
- named_scope :with_ipaddress, lambda {|value| {:conditions => {:ipaddress => inet_aton(value)}}}
+ named_scope "with_#{column_name}", lambda { |value|
+ { :conditions => { column_name => inet_aton(value) } }
+ }
- define_method name do
- return unless read_attribute(name)
- self.class.inet_ntoa(read_attribute(name))
+ define_method column_name do
+ return unless read_attribute(column_name)
+ self.class.inet_ntoa(read_attribute(column_name))
end
- define_method "#{name}=" do |value|
+ define_method "#{column_name}=" do |value|
new_value = self.class.inet_aton(value)
- write_attribute(name, new_value)
+ write_attribute(column_name, new_value)
end
end
end

0 comments on commit 6c17ad3

Please sign in to comment.