power_enum 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/power_enum/reflection.rb +17 -0
  2. metadata +3 -3
@@ -5,6 +5,13 @@ module PowerEnum::Reflection
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  module ClassMethods
8
+ def self.extended(base)
9
+ class << base
10
+ alias_method_chain :reflect_on_all_associations, :enumeration
11
+ alias_method_chain :reflect_on_association, :enumeration
12
+ end
13
+ end
14
+
8
15
  def reflect_on_all_enumerated
9
16
  # Need to give it a full namespace to avoid getting Rails confused in development
10
17
  # mode where all objects are reloaded on every request.
@@ -14,6 +21,16 @@ module PowerEnum::Reflection
14
21
  def reflect_on_enumerated( enumerated )
15
22
  reflections[enumerated.to_sym].is_a?(PowerEnum::Reflection::EnumerationReflection) ? reflections[enumerated.to_sym] : nil
16
23
  end
24
+
25
+ # Extend associations with enumerations, preferring enumerations
26
+ def reflect_on_all_associations_with_enumeration
27
+ reflect_on_all_enumerated + reflect_on_all_associations_without_enumeration
28
+ end
29
+
30
+ # Extend associations with enumerations, preferring enumerations
31
+ def reflect_on_association_with_enumeration( associated )
32
+ reflect_on_enumerated(associated) || reflect_on_association_without_enumeration(associated)
33
+ end
17
34
  end
18
35
 
19
36
  class EnumerationReflection < ActiveRecord::Reflection::MacroReflection
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: 0.10.0
4
+ version: 0.11.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-12-30 00:00:00.000000000 Z
15
+ date: 2013-01-06 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: rails
@@ -145,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
145
  version: '0'
146
146
  segments:
147
147
  - 0
148
- hash: -1561438891797770640
148
+ hash: -446581841770278549
149
149
  required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  none: false
151
151
  requirements: