power_enum 2.7.1 → 2.8.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: d7106c64cd85124483414f071a41693b1db42d7f
4
- data.tar.gz: 7c47e87dc6bc4733972a84fc7236a9c32c002a8c
3
+ metadata.gz: e1ae76f99b2ab01315cd8580800c3f24dad92f4c
4
+ data.tar.gz: 8a25997728648e1a3c2ae8378a5f3ee006cba18a
5
5
  SHA512:
6
- metadata.gz: b18dae6376623e5556ef9b79a5e3e237602efd74db5ad27de7e0caa9e00a7c14327e7a2d5b71c2b8c2c32f9d7adee96e531871f80d9b9b69b8bcf2cf5ebafebc
7
- data.tar.gz: d3b3af4731a65de4f2b6d55ec95216fc60c753d2f42ac91ed632a50e962c7bd1c4b74172764624ad6a73207c80cf54b7e5755a91e90ecfacd5666dbaf1266c7c
6
+ metadata.gz: ae5ca031835e1190255e0583300b518c5ae743425c08b77c2b5314d77da2922ea01fb794fd857c280748b33f30cfbb235106a85336fe352715d76c62d5baa1fc
7
+ data.tar.gz: a0558ae37ba8aff1b6b556c6af0f7c2a87deee1eed197779173fdd3e8c0c80b1bec51baa5e1c60963da506cb4dfe984aab89b5b80a0efde56c273e661b64122c
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -6,11 +6,11 @@ https://github.com/albertosaurus/power_enum_2
6
6
  [![Code Climate](https://codeclimate.com/github/albertosaurus/power_enum_2.png)](https://codeclimate.com/github/albertosaurus/power_enum_2)
7
7
  [![Gem Version](https://badge.fury.io/rb/power_enum.png)](http://badge.fury.io/rb/power_enum)
8
8
 
9
- Enumerations for Rails 4 Done Right.
9
+ Enumerations for Rails 4.X Done Right.
10
10
 
11
11
  ## Versions
12
12
 
13
- * PowerEnum 2.X (this version) supports Rails 4.
13
+ * PowerEnum 2.X (this version) supports Rails 4.X
14
14
  * PowerEnum 1.X supports Rails 3.1/3.2, available here: https://github.com/albertosaurus/power_enum
15
15
 
16
16
  ## What is this?:
@@ -177,7 +177,8 @@ end
177
177
  # It's highly recommended to add a foreign key constraint here.
178
178
  # Ideally, you would use a gem of some sort to handle this.
179
179
  # I have been using PgPower https://rubygems.org/gems/pg_power with much
180
- # success.
180
+ # success. It's fork, PgSaurus https://rubygems.org/gems/pg_saurus should
181
+ # work just as well.
181
182
  execute "ALTER TABLE bookings ADD 'bookings_bookings_status_id_fk'"\
182
183
  " FOREIGN KEY (status_id) REFERENCES booking_statuses (id);"
183
184
  ```
@@ -125,9 +125,14 @@ 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.2 handles this differently.
128
+ # ActiveRecord >= 4.1 handles this differently.
129
129
  if self.respond_to? :_reflections=
130
- self._reflections = self._reflections.merge(part_id => reflection)
130
+ if Rails.version =~ /^4\.2.*/
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
+
131
136
  else
132
137
  self.reflections = self.reflections.merge(part_id => reflection)
133
138
  end
@@ -27,7 +27,12 @@ module PowerEnum::Reflection
27
27
  # the reflection, otherwise returns nil.
28
28
  # @return [PowerEnum::Reflection::EnumerationReflection]
29
29
  def reflect_on_enumerated( enumerated )
30
- reflections[enumerated.to_sym].is_a?(PowerEnum::Reflection::EnumerationReflection) ? reflections[enumerated.to_sym] : nil
30
+ key = if Rails.version =~ /^4\.2.*/
31
+ enumerated.to_s
32
+ else
33
+ enumerated.to_sym
34
+ end
35
+ reflections[key].is_a?(PowerEnum::Reflection::EnumerationReflection) ? reflections[key] : nil
31
36
  end
32
37
 
33
38
  # Extend associations with enumerations, preferring enumerations
@@ -46,9 +51,48 @@ module PowerEnum::Reflection
46
51
  attr_reader :counter_cache_column
47
52
  attr_accessor :parent_reflection
48
53
 
49
- # See ActiveRecore::Reflection::MacroReflection
54
+ # See ActiveRecord::Reflection::MacroReflection
50
55
  def initialize( name, options, active_record )
51
- super :has_enumerated, name, nil, options, active_record
56
+ if Rails.version =~ /^4\.2.*/
57
+ super name, nil, options, active_record
58
+ else
59
+ super :has_enumerated, name, nil, options, active_record
60
+ end
61
+ end
62
+
63
+ if Rails.version =~ /^4\.2.*/
64
+ def macro
65
+ :has_enumerated
66
+ end
67
+
68
+ def check_preloadable!
69
+ return unless scope
70
+ if scope.arity > 0
71
+ ActiveSupport::Deprecation.warn(<<-MSG.squish)
72
+ The association scope '#{name}' is instance dependent (the scope
73
+ block takes an argument). Preloading happens before the individual
74
+ instances are created. This means that there is no instance being
75
+ passed to the association scope. This will most likely result in
76
+ broken or incorrect behavior. Joining, Preloading and eager loading
77
+ of these associations is deprecated and will be removed in the future.
78
+ MSG
79
+ end
80
+ end
81
+ alias :check_eager_loadable! :check_preloadable!
82
+
83
+ def active_record_primary_key
84
+ @active_record_primary_key ||= options[:primary_key] || active_record.primary_key
85
+ end
86
+
87
+ def klass
88
+ @klass ||= active_record.send(:compute_type, class_name)
89
+ end
90
+
91
+ EnumJoinKeys = Struct.new(:key, :foreign_key)
92
+
93
+ def join_keys(_)
94
+ EnumJoinKeys.new(active_record_primary_key, foreign_key)
95
+ end
52
96
  end
53
97
 
54
98
  # Returns the class name of the enum
@@ -80,7 +80,7 @@ module PowerEnum::Schema
80
80
  def create_enum(enum_name, options = {}, &block)
81
81
  enum_table_name = enum_name.pluralize
82
82
 
83
- # For compatibility with PgPower
83
+ # For compatibility with PgPower/PgSaurus
84
84
  schema_name = options[:schema]
85
85
  enum_table_name = "#{schema_name}.#{enum_table_name}" if schema_name
86
86
 
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.7.1
4
+ version: 2.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Trevor Squires
@@ -33,7 +33,7 @@ cert_chain:
33
33
  GeAMWE+ojHN5Yf9ycx76Wig/hxvGZ7y1dUA89/lJ8cUWfnS+FSILVnmIrhPfrDqw
34
34
  inXoFunB72EL6opwukc7cD9pUmsNsV0HdAStCG5jOhc5TxL1ZXhX8Qqe2iNong==
35
35
  -----END CERTIFICATE-----
36
- date: 2014-06-28 00:00:00.000000000 Z
36
+ date: 2014-12-20 00:00:00.000000000 Z
37
37
  dependencies:
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: rails
@@ -81,16 +81,16 @@ dependencies:
81
81
  name: rspec
82
82
  requirement: !ruby/object:Gem::Requirement
83
83
  requirements:
84
- - - ">="
84
+ - - "~>"
85
85
  - !ruby/object:Gem::Version
86
- version: '0'
86
+ version: '3.1'
87
87
  type: :development
88
88
  prerelease: false
89
89
  version_requirements: !ruby/object:Gem::Requirement
90
90
  requirements:
91
- - - ">="
91
+ - - "~>"
92
92
  - !ruby/object:Gem::Version
93
- version: '0'
93
+ version: '3.1'
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: sqlite3
96
96
  requirement: !ruby/object:Gem::Requirement
@@ -105,20 +105,6 @@ dependencies:
105
105
  - - ">="
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
- - !ruby/object:Gem::Dependency
109
- name: genspec
110
- requirement: !ruby/object:Gem::Requirement
111
- requirements:
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- version: 0.2.8
115
- type: :development
116
- prerelease: false
117
- version_requirements: !ruby/object:Gem::Requirement
118
- requirements:
119
- - - ">="
120
- - !ruby/object:Gem::Version
121
- version: 0.2.8
122
108
  description: |
123
109
  Power Enum allows you to treat instances of your ActiveRecord models as though they were an enumeration of values.
124
110
  It allows you to cleanly solve many of the problems that the traditional Rails alternatives handle poorly if at all.
@@ -175,4 +161,3 @@ specification_version: 4
175
161
  summary: Allows you to treat instances of your ActiveRecord models as though they
176
162
  were an enumeration of values
177
163
  test_files: []
178
- has_rdoc:
metadata.gz.sig CHANGED
Binary file