acts_as_enum 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/CHANGELOG +5 -1
  2. data/README.rdoc +5 -13
  3. data/VERSION +1 -1
  4. data/lib/acts_as_enum.rb +16 -13
  5. metadata +5 -7
data/CHANGELOG CHANGED
@@ -8,4 +8,8 @@
8
8
  Fixed a bug
9
9
 
10
10
  0.1.3
11
- comment the validation method validates_inclusion_of
11
+ Comment the validation method validates_inclusion_of
12
+
13
+ 0.2.0
14
+ Add alias method enum_attr for acts_as_enum
15
+ Rename acts_as_enum options :enum to :in
data/README.rdoc CHANGED
@@ -4,17 +4,15 @@
4
4
 
5
5
  如:枚举数组常量,每个元素的常量和布尔方法,属性的名字,Named scope方法
6
6
 
7
- Support rails 3
8
-
9
7
 
10
8
  == Usage
11
9
 
12
10
  class User < ActiveRecord::Base
13
- acts_as_enum :status, :enum => [ ['disable', 0, '冻结'], ['enable', 1, '激活'] ]
11
+ acts_as_enum :status, :in => [ ['disable', 0, '冻结'], ['enable', 1, '激活'] ]
14
12
  end
15
13
 
16
14
  Also can usage alias enum_attr
17
- enum_attr :status, :enum => [ ['disable', 0, '冻结'], ['enable', 1, '激活'] ]
15
+ enum_attr :status, :in => [ ['disable', 0, '冻结'], ['enable', 1, '激活'] ]
18
16
 
19
17
 
20
18
  Will generate bellow:
@@ -29,7 +27,7 @@ Support rails 3
29
27
 
30
28
 
31
29
  If with option prefix is true:
32
- acts_as_enum :status, :enum => [ ['disable', 0, '冻结'], ['enable', 1, '激活'] ], :prefix => true
30
+ acts_as_enum :status, :in => [ ['disable', 0, '冻结'], ['enable', 1, '激活'] ], :prefix => true
33
31
 
34
32
  Will generate bellow:
35
33
 
@@ -38,15 +36,9 @@ Support rails 3
38
36
 
39
37
  == Install
40
38
 
41
- git clone git://github.com/wenke/acts_as_enum.git OR
42
-
43
- rails 2
44
- ./script/plugin install git://github.com/wenke/acts_as_enum.git
45
-
46
- rails 3
47
- rails plugin install git://github.com/wenke/acts_as_enum.git
39
+ git clone git://github.com/liangwenke/acts_as_enum.git
48
40
 
49
41
 
50
42
  == Note
51
43
 
52
- Copyright (c) 2010 liangwenke8@gmail.com, released under the MIT license
44
+ Copyright (c) 2010 liangwenke.com@gmail.com, released under the MIT license
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.2.0
data/lib/acts_as_enum.rb CHANGED
@@ -1,25 +1,29 @@
1
1
  # EnumAttr# == Example
2
- #
2
+ #
3
+ # acts_as_enum(attr, options)
4
+ # attr is model attribute
5
+ # options incldue :in, :prefix
6
+ #
3
7
  # class User < ActiveRecord::Base
4
- # acts_as_enum :status, :enum => [ ['disable', 0, '冻结'], ['enable', 1, '激活'] ]
8
+ # acts_as_enum :status, :in => [ ['disable', 0, '冻结'], ['enable', 1, '激活'] ]
5
9
  # end
6
- #
10
+ #
7
11
  # Also can usage alias enum_attr
8
- # enum_attr :status, :enum => [ ['disable', 0, '冻结'], ['enable', 1, '激活'] ]
12
+ # enum_attr :status, :in => [ ['disable', 0, '冻结'], ['enable', 1, '激活'] ]
9
13
  #
10
14
  # Will generate bellow:
11
15
  #
12
16
  # Constants: User::STATUSES(return hash { 0 => "冻结", 1 => "激活" }), User::DISABLE, User::ENABLE
13
17
  #
14
18
  # Named scopes: User.enable, User.disable
15
- #
19
+ #
16
20
  # Class methods: User.status_options => [["冻结", 0], ["激活", 1]]
17
- #
21
+ #
18
22
  # Instance methods: user.status_name, user.enable?, user.disable?
19
23
  #
20
24
  #
21
25
  # If with option prefix is true:
22
- # acts_as_enum :status, :enum => [ ['disable', 0, '冻结'], ['enable', 1, '激活'] ], :prefix => true
26
+ # acts_as_enum :status, :in => [ ['disable', 0, '冻结'], ['enable', 1, '激活'] ], :prefix => true
23
27
  #
24
28
  # Will generate bellow:
25
29
  # User::STATUS_DISABLE, User::STATUS_ENABLE, User.status_enable, User.status_disable, user.status_enable?, user.status_disable?
@@ -30,14 +34,14 @@ module ActsAsEnum
30
34
  end
31
35
 
32
36
  module ClassMethods
33
- def acts_as_enum(attr, opts = { :enum => [], :prefix => false })
37
+ def acts_as_enum(attr, opts = { :in => [], :prefix => false })
34
38
  attr = attr.to_s
35
39
  plural_upcase_attr = attr.pluralize.upcase
36
- enum = opts[:enum]
40
+ enum = opts[:in]
37
41
 
38
42
  rails "Can not load Rails" unless defined?(Rails)
39
- rails "Options enum can not be empty" if enum.blank?
40
- rails "Options enum must be an array object" unless enum.is_a?(Array)
43
+ rails "Options in can not be empty" if enum.blank?
44
+ rails "Options in must be an array object" unless enum.is_a?(Array)
41
45
 
42
46
  # validates_inclusion_of attr, :in => enum.collect { |arr| arr[1] }, :allow_blank => true
43
47
 
@@ -74,9 +78,8 @@ module ActsAsEnum
74
78
  })
75
79
  end
76
80
 
77
- # alias enum_attr acts_as_enum
81
+ alias enum_attr acts_as_enum
78
82
  end
79
-
80
83
  end
81
84
 
82
85
  ActiveRecord::Base.send(:include, ActsAsEnum)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: acts_as_enum
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.3
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - LiangWenKe
@@ -10,12 +10,11 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-14 00:00:00 +08:00
14
- default_executable:
13
+ date: 2011-06-01 00:00:00 Z
15
14
  dependencies: []
16
15
 
17
16
  description: "\xE4\xB8\xBB\xE8\xA6\x81\xE5\xBA\x94\xE7\x94\xA8\xE4\xBA\x8E\xE6\x9C\x89\xE6\x9E\x9A\xE4\xB8\xBE\xE7\xB1\xBB\xE5\x9E\x8B\xE5\xB1\x9E\xE6\x80\xA7\xE7\x9A\x84Model\xEF\xBC\x8C\xE8\xBF\x99\xE4\xB8\xAA\xE6\x8F\x92\xE4\xBB\xB6\xE4\xBC\x9A\xE5\xB8\xAE\xE6\x88\x91\xE4\xBB\xAC\xE7\x94\x9F\xE6\x88\x90\xE4\xB8\x80\xE4\xBA\x9B\xE5\xB8\xB8\xE7\x94\xA8\xE5\x88\xB0\xE7\x9A\x84\xE6\x96\xB9\xE6\xB3\x95\xE3\x80\x82"
18
- email: liangwenke8@gmail.com
17
+ email: liangwenke.com@gmail.com
19
18
  executables: []
20
19
 
21
20
  extensions: []
@@ -31,8 +30,7 @@ files:
31
30
  - README.rdoc
32
31
  - VERSION
33
32
  - init.rb
34
- has_rdoc: true
35
- homepage: http://github.com/wenke/acts_as_enum
33
+ homepage: http://github.com/liangwenke/acts_as_enum
36
34
  licenses: []
37
35
 
38
36
  post_install_message:
@@ -55,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
53
  requirements: []
56
54
 
57
55
  rubyforge_project: acts_as_enum
58
- rubygems_version: 1.6.2
56
+ rubygems_version: 1.8.5
59
57
  signing_key:
60
58
  specification_version: 3
61
59
  summary: Enum Attribute for Rails ActiveRecord