acts_as_enum 1.1.1 → 1.1.2

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 (6) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +3 -0
  3. data/README.rdoc +50 -27
  4. data/VERSION +1 -1
  5. data/lib/acts_as_enum.rb +5 -3
  6. metadata +7 -9
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7ac2afb80554558a88e461d25a98ae25a79f3e62
4
+ data.tar.gz: a3044cee763770de2f2577c3899a514b1d55883c
5
+ SHA512:
6
+ metadata.gz: 38fc2138e8c9d766d987d0b5ba2e2ac84520eb7f77b1555eac9479f32bb9921db4a1e47feff6d5362c77f9bc1106ed2c78af1c47cb64bc468947b472037b8fdc
7
+ data.tar.gz: ab2d645e42018c7c72b3580ed8e4463fe9d7a1ae8ec5dfc9cc852677311b82d13f024a63f799467dbbefafa20c9571d9be2dd00f06a41953fd6df79be1a39ba4
data/CHANGELOG CHANGED
@@ -25,3 +25,6 @@
25
25
 
26
26
  1.1.1
27
27
  Fix a bug for scope method
28
+
29
+ 1.1.2
30
+ Support Rails 4
data/README.rdoc CHANGED
@@ -5,50 +5,73 @@
5
5
  如:枚举数组常量,每个元素的常量和布尔方法,属性的名字,Named scope方法
6
6
 
7
7
 
8
+ == Getting Started
9
+
10
+ In your Gemfile:
11
+
12
+ gem 'acts_as_enum'# Last officially released gem
13
+ # gem "acts_as_enum", :git => "git://github.com/liangwenke/acts_as_enum.git" # Track git repo
14
+
15
+ or, to install as a gem:
16
+
17
+ gem install acts_as_enum
18
+
19
+ or, to install as a plugin:
20
+
21
+ rails plugin install git://github.com/liangwenke/acts_as_enum.git
22
+
23
+
8
24
  == Usage
9
25
 
10
- Table column type as Varchar or Varchar2
26
+ Table column type as String
27
+
11
28
  class User < ActiveRecord::Base
12
29
  acts_as_enum :status, :in => [ ['disable', '冻结'], ['enable', '激活'] ]
13
30
  end
14
31
 
15
- Table column type as Integer
32
+ Table column type as Integer
33
+
16
34
  class User < ActiveRecord::Base
17
35
  acts_as_enum :status, :in => [ ['disable', 0, '冻结'], ['enable', 1, '激活'] ]
18
36
  end
19
37
 
20
- Table column type as Varchar and Number
38
+ Table column type as String and Number
39
+
21
40
  class User < ActiveRecord::Base
22
41
  acts_as_enum :status, :in => [ ['disable', '0', '冻结'], ['enable', '1', '激活'] ]
23
42
  end
24
43
 
25
- Also can usage alias enum_attr
44
+ Table column type as Boolean
45
+
46
+ class User < ActiveRecord::Base
47
+ acts_as_enum :status, :in => [ ['disable', false, '冻结'], ['enable', true, '激活'] ]
48
+ end
49
+
50
+
51
+ Also can usage alias enum_attr
52
+
26
53
  enum_attr :status, :in => [ ['disable', '冻结'], ['enable', '激活'] ]
27
54
  enum_attr :status, :in => [ ['disable', 0, '冻结'], ['enable', 1, '激活'] ]
28
55
 
29
-
30
- Will generate bellow:
31
-
32
- Constants: User::STATUSES, User::DISABLE, User::ENABLE
33
-
34
- Named scopes: User.enable, User.disable
35
-
36
- Class methods: User.status_options
37
-
38
- Instance methods: user.status_name, user.enable?, user.disable?
39
-
40
-
41
- If with option prefix is true:
42
- acts_as_enum :status, :in => [ ['disable', '冻结'], ['enable', '激活'] ], :prefix => true
43
-
44
- Will generate bellow:
45
-
46
- User::STATUS_DISABLE, User::STATUS_ENABLE, User.status_enable, User.status_disable, user.status_enable?, user.status_disable?
47
-
48
-
49
- == Install
50
-
51
- git clone git://github.com/liangwenke/acts_as_enum.git
56
+
57
+ Will generate bellow:
58
+
59
+ Constants: User::STATUSES, User::DISABLE, User::ENABLE
60
+
61
+ Named scopes: User.enable, User.disable
62
+
63
+ Class methods: User.status_options
64
+
65
+ Instance methods: user.status_name, user.enable?, user.disable?
66
+
67
+
68
+ If with option prefix is true:
69
+
70
+ acts_as_enum :status, :in => [ ['disable', '冻结'], ['enable', '激活'] ], :prefix => true
71
+
72
+ Will generate bellow:
73
+
74
+ User::STATUS_DISABLE, User::STATUS_ENABLE, User.status_enable, User.status_disable, user.status_enable?, user.status_disable?
52
75
 
53
76
 
54
77
  == Note
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.1
1
+ 1.1.2
data/lib/acts_as_enum.rb CHANGED
@@ -78,10 +78,12 @@ module ActsAsEnum
78
78
 
79
79
  const_set("#{method_name}".upcase, attr_value)
80
80
 
81
- if Rails.version =~ /^2/
82
- named_scope method_name.to_sym, :conditions => { attr.to_sym => attr_value }
83
- else
81
+ if Rails.version =~ /^4/
82
+ scope method_name.to_sym, -> { where(["#{self.table_name}.#{attr} = ?", attr_value]) }
83
+ elsif Rails.version =~ /^3/
84
84
  scope method_name.to_sym, where(["#{self.table_name}.#{attr} = ?", attr_value])
85
+ else
86
+ named_scope method_name.to_sym, :conditions => { attr.to_sym => attr_value }
85
87
  end
86
88
 
87
89
  class_eval(%Q{
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
5
- prerelease:
4
+ version: 1.1.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mike Liang
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-08-01 00:00:00.000000000 Z
11
+ date: 2013-07-19 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: For multiple values activerecord attributes. This gem have some very
15
14
  useful methods and constants for attribute.
@@ -29,26 +28,25 @@ files:
29
28
  - init.rb
30
29
  homepage: http://github.com/liangwenke/acts_as_enum
31
30
  licenses: []
31
+ metadata: {}
32
32
  post_install_message:
33
33
  rdoc_options: []
34
34
  require_paths:
35
35
  - lib
36
36
  required_ruby_version: !ruby/object:Gem::Requirement
37
- none: false
38
37
  requirements:
39
- - - ! '>='
38
+ - - '>='
40
39
  - !ruby/object:Gem::Version
41
40
  version: '0'
42
41
  required_rubygems_version: !ruby/object:Gem::Requirement
43
- none: false
44
42
  requirements:
45
- - - ! '>='
43
+ - - '>='
46
44
  - !ruby/object:Gem::Version
47
45
  version: 1.3.4
48
46
  requirements: []
49
47
  rubyforge_project: acts_as_enum
50
- rubygems_version: 1.8.24
48
+ rubygems_version: 2.0.0
51
49
  signing_key:
52
- specification_version: 3
50
+ specification_version: 4
53
51
  summary: Enum Attribute for Rails ActiveRecord
54
52
  test_files: []