power_enum 1.3.1 → 1.3.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.
data.tar.gz.sig CHANGED
Binary file
@@ -114,7 +114,9 @@ module ActiveRecord # :nodoc:
114
114
  end
115
115
  end
116
116
 
117
- def self.inject_class_options( virtual_enum_class, options ) # :nodoc:
117
+ # Evals the given set of options within the context of the given class
118
+ # @private
119
+ def self.inject_class_options( virtual_enum_class, options )
118
120
  # Declare it acts_as_enumerated
119
121
  virtual_enum_class.class_eval do
120
122
  acts_as_enumerated :conditions => options[:conditions],
@@ -1,8 +1,10 @@
1
+ # Helper logic for the enum generator
1
2
  module EnumGeneratorHelpers
2
3
  # Helper methods to figure out the migration number.
3
4
  module MigrationNumber
4
5
 
5
6
  # Returns the number of the last migration.
7
+ # @return [Fixnum]
6
8
  def current_migration_number
7
9
  dirname = "#{Rails.root}/db/migrate/[0-9]*_*.rb"
8
10
  Dir.glob(dirname).collect do |file|
@@ -12,6 +14,7 @@ module EnumGeneratorHelpers
12
14
 
13
15
  # Returns the next upcoming migration number. Sadly, Rails has no API for
14
16
  # this, so we're reduced to copying from ActiveRecord::Generators::Migration
17
+ # @return [Fixnum]
15
18
  def next_migration_number
16
19
  # Lifted directly from ActiveRecord::Generators::Migration
17
20
  # Unfortunately, no API is provided by Rails at this time.
@@ -7,6 +7,7 @@ class VirtualEnumerationsInitializerGenerator < Rails::Generators::Base
7
7
 
8
8
  argument :initializer_name, :type => :string, :default => 'virtual_enumerations'
9
9
 
10
+ # Writes the virtual enumerations initializer to config/initializers
10
11
  def generate_virtual_enum_initializer
11
12
  template 'virtual_enumerations.rb.erb', "config/initializers/#{initializer_name}.rb"
12
13
  end
data/lib/power_enum.rb CHANGED
@@ -1,6 +1,12 @@
1
1
  require "rails"
2
2
  require 'testing/rspec'
3
3
 
4
+ # Power Enum allows you to treat instances of your ActiveRecord models as
5
+ # though they were an enumeration of values. It allows you to cleanly solve
6
+ # many of the problems that the traditional Rails alternatives handle poorly
7
+ # if at all. It is particularly suitable for scenarios where your Rails
8
+ # application is not the only user of the database, such as when it's used for
9
+ # analytics or reporting.
4
10
  class PowerEnum < Rails::Engine
5
11
  config.autoload_paths << File.expand_path(File.join(__FILE__, "../"))
6
12
 
@@ -2,9 +2,11 @@
2
2
  # Copyright (c) 2012 Arthur Shagall
3
3
  # Released under the MIT License. See the LICENSE file for more details.
4
4
 
5
+ # Implementation of acts_as_enumerated
5
6
  module PowerEnum::Enumerated
6
7
  extend ActiveSupport::Concern
7
8
 
9
+ # Class level methods injected into ActiveRecord.
8
10
  module ClassMethods
9
11
 
10
12
  # Returns false for ActiveRecord models that do not act as enumerated.
@@ -129,6 +131,8 @@ module PowerEnum::Enumerated
129
131
  private :get_name_column
130
132
  end
131
133
 
134
+ # These are class level methods which are patched into classes that act as
135
+ # enumerated
132
136
  module EnumClassMethods
133
137
  attr_accessor :enumeration_model_updates_permitted
134
138
 
@@ -277,8 +281,8 @@ module PowerEnum::Enumerated
277
281
 
278
282
  def load_all
279
283
  conditions = self.acts_enumerated_conditions
280
- order = self.acts_enumerated_order
281
- where(conditions).order(order)
284
+ order = self.acts_enumerated_order
285
+ unscoped.where(conditions).order(order)
282
286
  end
283
287
  private :load_all
284
288
 
@@ -336,7 +340,7 @@ module PowerEnum::Enumerated
336
340
  end
337
341
  private :all_by_name
338
342
 
339
- def all_by_attribute(attr)
343
+ def all_by_attribute(attr) # :nodoc:
340
344
  aba = all.inject({}) { |memo, item|
341
345
  memo[item.send(attr)] = item
342
346
  memo
@@ -346,34 +350,36 @@ module PowerEnum::Enumerated
346
350
  end
347
351
  private :all_by_attribute
348
352
 
349
- def enforce_none(arg)
353
+ def enforce_none(arg) # :nodoc:
350
354
  nil
351
355
  end
352
356
  private :enforce_none
353
357
 
354
- def enforce_strict(arg)
358
+ def enforce_strict(arg) # :nodoc:
355
359
  raise_record_not_found(arg)
356
360
  end
357
361
  private :enforce_strict
358
362
 
359
- def enforce_strict_literals(arg)
363
+ def enforce_strict_literals(arg) # :nodoc:
360
364
  raise_record_not_found(arg) if (Fixnum === arg) || (Symbol === arg)
361
365
  nil
362
366
  end
363
367
  private :enforce_strict_literals
364
368
 
365
- def enforce_strict_ids(arg)
369
+ def enforce_strict_ids(arg) # :nodoc:
366
370
  raise_record_not_found(arg) if Fixnum === arg
367
371
  nil
368
372
  end
369
373
  private :enforce_strict_ids
370
374
 
371
- def enforce_strict_symbols(arg)
375
+ def enforce_strict_symbols(arg) # :nodoc:
372
376
  raise_record_not_found(arg) if Symbol === arg
373
377
  nil
374
378
  end
375
379
  private :enforce_strict_symbols
376
380
 
381
+ # raise the {ActiveRecord::RecordNotFound} error.
382
+ # @private
377
383
  def raise_record_not_found(arg)
378
384
  raise ActiveRecord::RecordNotFound, "Couldn't find a #{self.name} identified by (#{arg.inspect})"
379
385
  end
@@ -381,6 +387,7 @@ module PowerEnum::Enumerated
381
387
 
382
388
  end
383
389
 
390
+ # These are instance methods for objects which are enums.
384
391
  module EnumInstanceMethods
385
392
  # Behavior depends on the type of +arg+.
386
393
  #
@@ -465,4 +472,4 @@ module PowerEnum::Enumerated
465
472
  end
466
473
  private :enumeration_model_update
467
474
  end # module EnumInstanceMethods
468
- end # module PowerEnum::Enumerated
475
+ end # module PowerEnum::Enumerated
@@ -2,10 +2,12 @@
2
2
  # Copyright (c) 2012 Arthur Shagall
3
3
  # Released under the MIT License. See the LICENSE file for more details.
4
4
 
5
- module PowerEnum::HasEnumerated # :nodoc:
5
+ # Implementation of has_enumerated
6
+ module PowerEnum::HasEnumerated
6
7
 
7
8
  extend ActiveSupport::Concern
8
9
 
10
+ # Class-level behavior injected into ActiveRecord to support has_enumerated
9
11
  module ClassMethods
10
12
 
11
13
  # Returns a list of all the attributes on the ActiveRecord model which are enumerated.
@@ -1,17 +1,23 @@
1
1
  # Copyright (c) 2011 Arthur Shagall
2
2
  # Released under the MIT license. See LICENSE for details.
3
3
 
4
- module PowerEnum::Migration
4
+ module PowerEnum::Migration # :nodoc:
5
5
 
6
+ # Extensions for CommandRecorder
6
7
  module CommandRecorder
8
+ # Records create_enum
7
9
  def create_enum(*args)
8
10
  record(:create_enum, args)
9
11
  end
10
12
 
13
+ # Records remove_enum
11
14
  def remove_enum(*args)
12
15
  record(:remove_enum, args)
13
16
  end
14
17
 
18
+ # The inversion of create_enum is remove_enum
19
+ # @param [Array] args Arguments to create_enum
20
+ # @return [Array] [:remove_enum, [enum_name]]
15
21
  def invert_create_enum(args)
16
22
  enum_name = args[0]
17
23
  [:remove_enum, [enum_name]]
@@ -7,20 +7,25 @@
7
7
  module PowerEnum::Reflection
8
8
  extend ActiveSupport::Concern
9
9
 
10
+ # Class-level extensions injected into ActiveRecord
10
11
  module ClassMethods
11
- def self.extended(base)
12
+ def self.extended(base) # :nodoc:
12
13
  class << base
13
14
  alias_method_chain :reflect_on_all_associations, :enumeration
14
15
  alias_method_chain :reflect_on_association, :enumeration
15
16
  end
16
17
  end
17
18
 
19
+ # All {PowerEnum::Reflection::EnumerationReflection} reflections
18
20
  def reflect_on_all_enumerated
19
21
  # Need to give it a full namespace to avoid getting Rails confused in development
20
22
  # mode where all objects are reloaded on every request.
21
23
  reflections.values.grep(PowerEnum::Reflection::EnumerationReflection)
22
24
  end
23
25
 
26
+ # If the reflection of the given name is an EnumerationReflection, returns
27
+ # the reflection, otherwise returns nil.
28
+ # @return [PowerEnum::Reflection::EnumerationReflection]
24
29
  def reflect_on_enumerated( enumerated )
25
30
  reflections[enumerated.to_sym].is_a?(PowerEnum::Reflection::EnumerationReflection) ? reflections[enumerated.to_sym] : nil
26
31
  end
@@ -1,10 +1,12 @@
1
1
  # Copyright (c) 2011 Arthur Shagall
2
2
  # Released under the MIT license. See LICENSE for details.
3
3
 
4
+ # Extensions to the migrations DSL
4
5
  module PowerEnum::Schema
6
+ # Patches AbstractAdapter with {PowerEnum::Schema::AbstractAdapter}
5
7
  module SchemaStatements
6
8
 
7
- def self.included(base)
9
+ def self.included(base) # :nodoc:
8
10
  base::AbstractAdapter.class_eval do
9
11
  include PowerEnum::Schema::AbstractAdapter
10
12
  end
@@ -12,6 +14,7 @@ module PowerEnum::Schema
12
14
 
13
15
  end
14
16
 
17
+ # Implementation of the PowerEnum extensions to the migrations DSL.
15
18
  module AbstractAdapter
16
19
 
17
20
  # Creates a new enum table. +enum_name+ will be automatically pluralized.
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: power_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Trevor Squires
@@ -39,11 +40,12 @@ cert_chain:
39
40
  amZaYUtWM2wwYTFkR2wyUVNMa2pScFFaRDFiRCtVSDdnT3F5N1piZGNzUkJM
40
41
  NEg3VTV6VQpibEtkZEg2dXhDckRTTTdLYWJrelNPVmYKLS0tLS1FTkQgQ0VS
41
42
  VElGSUNBVEUtLS0tLQo=
42
- date: 2013-04-13 00:00:00.000000000 Z
43
+ date: 2013-05-14 00:00:00.000000000 Z
43
44
  dependencies:
44
45
  - !ruby/object:Gem::Dependency
45
46
  name: rails
46
47
  requirement: !ruby/object:Gem::Requirement
48
+ none: false
47
49
  requirements:
48
50
  - - ~>
49
51
  - !ruby/object:Gem::Version
@@ -51,6 +53,7 @@ dependencies:
51
53
  type: :runtime
52
54
  prerelease: false
53
55
  version_requirements: !ruby/object:Gem::Requirement
56
+ none: false
54
57
  requirements:
55
58
  - - ~>
56
59
  - !ruby/object:Gem::Version
@@ -58,6 +61,7 @@ dependencies:
58
61
  - !ruby/object:Gem::Dependency
59
62
  name: jeweler
60
63
  requirement: !ruby/object:Gem::Requirement
64
+ none: false
61
65
  requirements:
62
66
  - - ! '>='
63
67
  - !ruby/object:Gem::Version
@@ -65,6 +69,23 @@ dependencies:
65
69
  type: :development
66
70
  prerelease: false
67
71
  version_requirements: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ - !ruby/object:Gem::Dependency
78
+ name: yard
79
+ requirement: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ none: false
68
89
  requirements:
69
90
  - - ! '>='
70
91
  - !ruby/object:Gem::Version
@@ -72,6 +93,7 @@ dependencies:
72
93
  - !ruby/object:Gem::Dependency
73
94
  name: rspec
74
95
  requirement: !ruby/object:Gem::Requirement
96
+ none: false
75
97
  requirements:
76
98
  - - ! '>='
77
99
  - !ruby/object:Gem::Version
@@ -79,6 +101,7 @@ dependencies:
79
101
  type: :development
80
102
  prerelease: false
81
103
  version_requirements: !ruby/object:Gem::Requirement
104
+ none: false
82
105
  requirements:
83
106
  - - ! '>='
84
107
  - !ruby/object:Gem::Version
@@ -86,6 +109,7 @@ dependencies:
86
109
  - !ruby/object:Gem::Dependency
87
110
  name: sqlite3
88
111
  requirement: !ruby/object:Gem::Requirement
112
+ none: false
89
113
  requirements:
90
114
  - - ! '>='
91
115
  - !ruby/object:Gem::Version
@@ -93,6 +117,7 @@ dependencies:
93
117
  type: :development
94
118
  prerelease: false
95
119
  version_requirements: !ruby/object:Gem::Requirement
120
+ none: false
96
121
  requirements:
97
122
  - - ! '>='
98
123
  - !ruby/object:Gem::Version
@@ -100,6 +125,7 @@ dependencies:
100
125
  - !ruby/object:Gem::Dependency
101
126
  name: genspec
102
127
  requirement: !ruby/object:Gem::Requirement
128
+ none: false
103
129
  requirements:
104
130
  - - ! '>='
105
131
  - !ruby/object:Gem::Version
@@ -107,6 +133,7 @@ dependencies:
107
133
  type: :development
108
134
  prerelease: false
109
135
  version_requirements: !ruby/object:Gem::Requirement
136
+ none: false
110
137
  requirements:
111
138
  - - ! '>='
112
139
  - !ruby/object:Gem::Version
@@ -150,26 +177,28 @@ files:
150
177
  - README.markdown
151
178
  homepage: http://github.com/albertosaurus/power_enum
152
179
  licenses: []
153
- metadata: {}
154
180
  post_install_message:
155
181
  rdoc_options: []
156
182
  require_paths:
157
183
  - lib
158
184
  required_ruby_version: !ruby/object:Gem::Requirement
185
+ none: false
159
186
  requirements:
160
187
  - - ! '>='
161
188
  - !ruby/object:Gem::Version
162
189
  version: '0'
163
190
  required_rubygems_version: !ruby/object:Gem::Requirement
191
+ none: false
164
192
  requirements:
165
193
  - - ! '>='
166
194
  - !ruby/object:Gem::Version
167
195
  version: '0'
168
196
  requirements: []
169
197
  rubyforge_project:
170
- rubygems_version: 2.0.3
198
+ rubygems_version: 1.8.25
171
199
  signing_key:
172
- specification_version: 4
200
+ specification_version: 3
173
201
  summary: Allows you to treat instances of your ActiveRecord models as though they
174
202
  were an enumeration of values
175
203
  test_files: []
204
+ has_rdoc:
metadata.gz.sig CHANGED
Binary file
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZjcwMzlkY2EyNzFmMzAwYjc4ZTEwNDdjMWMwMWI4NjE0MDQzMjBjYg==
5
- data.tar.gz: !binary |-
6
- OTZiODFjYTg2NjkzZWU1OTUzZTA1NTMxN2U5YWVmMjEzM2Q4ODc2Mg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- OTk1NTY2ZTViZTdjZDljZjIzZDA0ZTc2NDlkZGJhMzMyMWIyOGVmMDgyNDdj
10
- NDVmZTUwYmFjMzI1ZGUwYzY1NjcyZDg2ZTA2ZjA3NzZhNjUyOWE4N2IzZDAx
11
- MDE2NTA5ZjZiZDNiZGE4MzdmM2Q2MmMwYWYyODMwOTJjMmI3YWY=
12
- data.tar.gz: !binary |-
13
- OGY4ZGE4ZTQ5OGIxYzE0YjJjMzA5MTAxNTIxZjI2ZWM3MjNjYjE5ZTM3MWRl
14
- YjE3MjgzOGFjZGI2NmY1NWUxZjRmMTFkNTM3NzVjNzc2MGZmYTYyZWU2MzJk
15
- Y2ZiYzNlNjBlYmQwMGE2Y2M5ODk1ZTVlY2VlMDhjNjZlMDljNjc=
checksums.yaml.gz.sig DELETED
@@ -1 +0,0 @@
1
- ���