power_enum 2.12.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64844e550c505a4a4f76be6db166cb8cfe619211
4
- data.tar.gz: a52e8c4606a8466f4427e8c311d77bc5d0191586
3
+ metadata.gz: b2ba1df5d5a34dddc9be7b609aa4199fc2c6a996
4
+ data.tar.gz: 9bb8768b88f047dc4a51aa65e37fe693aa4fde3d
5
5
  SHA512:
6
- metadata.gz: 8c4eefff7165c2465455555eba9f73a7ecf81d92db1288ebfee7fabf0848cc10ec8c0d71c56485e32df98e5ed1178e827f95c4a6987907f344a8fc188bd29b45
7
- data.tar.gz: 79fabb30097902433ad93e59ecc1b3397924c65e9ea5526c8fc12334fb51d3fa5d812abd76f7879eba4a8e7735af2a27e27da87c1dae84ba6e9d965bfffc35db
6
+ metadata.gz: 5422edc2be751e1600cbbb121d08fdebeae474906466326fc71f3b79650af60a54766bca362a63edf817bc992414e3dd40c962b4f0e6f4308fa6389cd8bb0571
7
+ data.tar.gz: a23a77a642de5ded4564d3aec2e946a87dd5ec39ccad94bced7f50cc70431c3b0114ff7d6a4d96514638887c47223dc330820ec8e59752291f8b1c2cf2df64ab
@@ -10,7 +10,8 @@ Enumerations for Rails Done Right.
10
10
 
11
11
  ## Versions
12
12
 
13
- * PowerEnum 2.X (this version) supports Rails 4.X and Rails 5.0
13
+ * PowerEnum 3.X (this version) supports Rails 4.2 and Rails 5.X
14
+ * PowerEnum 2.X supports Rails 4.X and Rails 5.0
14
15
  * PowerEnum 1.X supports Rails 3.1/3.2, available here: https://github.com/albertosaurus/power_enum
15
16
 
16
17
  ## What is this?:
@@ -50,10 +51,15 @@ See "How to use it" below for more information.
50
51
 
51
52
  ## Requirements
52
53
 
54
+ ### PowerEnum 3.X
55
+
56
+ * Ruby 2.1 or later (JRuby should work but isn't extensively tested; Travis is being difficult).
57
+ * Rails 4.2, 5.0, 5.1
58
+
53
59
  ### PowerEnum 2.X
54
60
 
55
61
  * Ruby 1.9.3, 2.0, JRuby 1.7+ (Ruby 1.9.3 or 2.0 required for development)
56
- * Rails 4.0
62
+ * Rails 4.0, 4.1, 4.2, 5.0
57
63
 
58
64
  ## Installation
59
65
 
@@ -125,17 +125,7 @@ module PowerEnum::HasEnumerated
125
125
  def create_ar_reflection(part_id, options)
126
126
  reflection = PowerEnum::Reflection::EnumerationReflection.new(part_id, options, self)
127
127
 
128
- # ActiveRecord >= 4.1 handles this differently.
129
- if self.respond_to? :_reflections=
130
- if Rails.version =~ /^4\.2\.*/ || Rails.version =~ /^5\.0\.*/
131
- self._reflections = self._reflections.merge(part_id.to_s => reflection)
132
- else
133
- self._reflections = self._reflections.merge(part_id => reflection)
134
- end
135
-
136
- else
137
- self.reflections = self.reflections.merge(part_id => reflection)
138
- end
128
+ self._reflections = self._reflections.merge(part_id.to_s => reflection)
139
129
  reflection
140
130
  end
141
131
  private :create_ar_reflection
@@ -17,11 +17,7 @@ module PowerEnum::Reflection
17
17
  # the reflection, otherwise returns nil.
18
18
  # @return [PowerEnum::Reflection::EnumerationReflection]
19
19
  def reflect_on_enumerated( enumerated )
20
- key = if Rails.version =~ /^4\.2\.*/ || Rails.version =~ /^5\.*/
21
- enumerated.to_s
22
- else
23
- enumerated.to_sym
24
- end
20
+ key = enumerated.to_s
25
21
  reflections[key].is_a?(PowerEnum::Reflection::EnumerationReflection) ? reflections[key] : nil
26
22
  end
27
23
 
@@ -39,47 +35,42 @@ module PowerEnum::Reflection
39
35
  attr_accessor :parent_reflection
40
36
 
41
37
  # See ActiveRecord::Reflection::MacroReflection
42
- def initialize( name, options, active_record )
43
- if Rails.version =~ /^4\.2\.*/ || Rails.version =~ /^5\.0\.*/
44
- super name, nil, options, active_record
45
- else
46
- super :has_enumerated, name, nil, options, active_record
47
- end
38
+ def initialize(name, options, active_record)
39
+ super name, nil, options, active_record
48
40
  end
49
41
 
50
- if Rails.version =~ /^4\.2\.*/ || Rails.version =~ /^5\.0\.*/
51
- def macro
52
- :has_enumerated
53
- end
42
+ def macro
43
+ :has_enumerated
44
+ end
54
45
 
55
- def check_preloadable!
56
- return unless scope
57
- if scope.arity > 0
58
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
46
+ def check_preloadable!
47
+ return unless scope
48
+ if scope.arity > 0
49
+ ActiveSupport::Deprecation.warn(<<-MSG.squish)
59
50
  The association scope '#{name}' is instance dependent (the scope
60
51
  block takes an argument). Preloading happens before the individual
61
52
  instances are created. This means that there is no instance being
62
53
  passed to the association scope. This will most likely result in
63
54
  broken or incorrect behavior. Joining, Preloading and eager loading
64
55
  of these associations is deprecated and will be removed in the future.
65
- MSG
66
- end
56
+ MSG
67
57
  end
68
- alias :check_eager_loadable! :check_preloadable!
58
+ end
69
59
 
70
- def active_record_primary_key
71
- @active_record_primary_key ||= options[:primary_key] || active_record.primary_key
72
- end
60
+ alias :check_eager_loadable! :check_preloadable!
73
61
 
74
- def klass
75
- @klass ||= active_record.send(:compute_type, class_name)
76
- end
62
+ def active_record_primary_key
63
+ @active_record_primary_key ||= options[:primary_key] || active_record.primary_key
64
+ end
77
65
 
78
- EnumJoinKeys = Struct.new(:key, :foreign_key)
66
+ def klass
67
+ @klass ||= active_record.send(:compute_type, class_name)
68
+ end
79
69
 
80
- def join_keys(_)
81
- EnumJoinKeys.new(active_record_primary_key, foreign_key)
82
- end
70
+ EnumJoinKeys = Struct.new(:key, :foreign_key)
71
+
72
+ def join_keys(*_)
73
+ EnumJoinKeys.new(active_record_primary_key, foreign_key)
83
74
  end
84
75
 
85
76
  # Returns the class name of the enum
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: power_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.12.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trevor Squires
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-08-19 00:00:00.000000000 Z
14
+ date: 2017-08-20 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -61,60 +61,60 @@ dependencies:
61
61
  requirements:
62
62
  - - ">="
63
63
  - !ruby/object:Gem::Version
64
- version: '4.0'
64
+ version: '4.2'
65
65
  - - "<"
66
66
  - !ruby/object:Gem::Version
67
- version: '5.1'
67
+ version: '5.2'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: '4.0'
74
+ version: '4.2'
75
75
  - - "<"
76
76
  - !ruby/object:Gem::Version
77
- version: '5.1'
77
+ version: '5.2'
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: railties
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  requirements:
82
82
  - - ">="
83
83
  - !ruby/object:Gem::Version
84
- version: '4.0'
84
+ version: '4.2'
85
85
  - - "<"
86
86
  - !ruby/object:Gem::Version
87
- version: '5.1'
87
+ version: '5.2'
88
88
  type: :runtime
89
89
  prerelease: false
90
90
  version_requirements: !ruby/object:Gem::Requirement
91
91
  requirements:
92
92
  - - ">="
93
93
  - !ruby/object:Gem::Version
94
- version: '4.0'
94
+ version: '4.2'
95
95
  - - "<"
96
96
  - !ruby/object:Gem::Version
97
- version: '5.1'
97
+ version: '5.2'
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: activerecord
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - ">="
103
103
  - !ruby/object:Gem::Version
104
- version: '4.0'
104
+ version: '4.2'
105
105
  - - "<"
106
106
  - !ruby/object:Gem::Version
107
- version: '5.1'
107
+ version: '5.2'
108
108
  type: :runtime
109
109
  prerelease: false
110
110
  version_requirements: !ruby/object:Gem::Requirement
111
111
  requirements:
112
112
  - - ">="
113
113
  - !ruby/object:Gem::Version
114
- version: '4.0'
114
+ version: '4.2'
115
115
  - - "<"
116
116
  - !ruby/object:Gem::Version
117
- version: '5.1'
117
+ version: '5.2'
118
118
  description: |
119
119
  Power Enum allows you to treat instances of your ActiveRecord models as though they were an enumeration of values.
120
120
  It allows you to cleanly solve many of the problems that the traditional Rails alternatives handle poorly if at all.