Skip to content

Automagically store attributes ending with _ip as an integer in the DB

License

Notifications You must be signed in to change notification settings

belt/ip_attribute

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

= IpAttribute

Provides conventions for attributes of an AR instance ending w/_ip.

String based _ip attributes will appear as either an IPv4 or an IPv6 string,
but will be stored as an integer.


== Example

Table name: users

  id          :integer(4)     not null, primary key
  login       :string(255)    not null
  login_ip    :decimal(10)    default(2130706433), not null
  created_at  :datetime
  updated_at  :datetime
 
Class: User

  class User < ActiveRecord::Base
    include IpAttribute
  end

Yields:

  user = User.new
  user.login_ip = '127.0.0.1'   # => 2130706433
  user.login_ip = 'wuff'        # => nil
  user.login_ip = 2130706433    # => 2130706433
  user.login_ip                 # => #<IPAddr: IPv4:127.0.0.1/255.255.255.255>
  user.login_ip.to_s            # => '127.0.0.1'
  user.login_ip.to_i            # => 2130706433

Copyright (c) 2009 [Paul Belt], released under the MIT license

About

Automagically store attributes ending with _ip as an integer in the DB

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages