-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
36 lines (24 loc) · 912 Bytes
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
= 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