has_enumeration 0.2.0 → 0.2.1

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/Gemfile CHANGED
@@ -1,5 +1,19 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'activerecord', '>= 3.0.0.rc'
3
+ if ENV['AR_VERSION'] == '2.3'
4
+ gem 'activerecord', '2.3.8'
5
+ else
6
+ gem 'activerecord', '>= 3.0.0.rc'
7
+ end
8
+
4
9
  gem 'rspec', '>= 2.0.0.beta.19'
5
10
  gem 'cucumber', '>= 0.8.5'
11
+
12
+ platforms :ruby do
13
+ gem 'sqlite3-ruby', :require => 'sqlite3'
14
+ end
15
+
16
+ platforms :jruby do
17
+ gem 'jdbc-sqlite3'
18
+ gem 'activerecord-jdbcsqlite3-adapter', '>= 0.9.7'
19
+ end
data/README.txt CHANGED
@@ -23,17 +23,25 @@ obj.color.green? # => false
23
23
  # Querying
24
24
  TestObject.where(:color => :red)
25
25
 
26
- # Querying with arel predicates
26
+ # Querying with arel predicates (ActiveRecord 3 only)
27
27
  attr = TestObject.arel_table[:color]
28
28
  TestObject.where(attr.not_in([:red, :green]))
29
29
 
30
+ == Installation
31
+ gem install has_enumeration
32
+
30
33
  == Getting the Latest Version
31
34
  The repository for has_enumeration is hosted at GitHub:
32
35
  Web page: http://github.com/gregspurrier/has_enumeration
33
36
  Clone URL: git://github.com/gregspurrier/has_enumeration.git
34
37
 
35
38
  == Supported Versions
36
- has_enumeration has been tested with:
37
- - ActiveRecord 3.0.0rc
38
- - Ruby 1.8.7-p299
39
- - Ruby 1.9.2-head (revision 28788)
39
+ has_enumeration has been tested with all combinations for the following:
40
+
41
+ Rubies:
42
+ - 1.8.7-p302
43
+ - 1.9.2-p0
44
+ - JRuby 1.5.1
45
+ ActiveRecord:
46
+ - 2.3.8
47
+ - 3.0.0.rc
data/Rakefile CHANGED
@@ -1,17 +1,70 @@
1
- require 'jeweler'
2
-
3
- Jeweler::Tasks.new do |gemspec|
4
- gemspec.name = "has_enumeration"
5
- gemspec.summary = "Support for symbol-based enumerations in ActiveRecord"
6
- gemspec.description = <<-EOF
7
- Extends ActiveRecord with the has_enumeration method that allows an
8
- attribute to be declared as storing an enumeration. The enumeration
9
- is specified as a mapping between symbols and their underlying
10
- representation in the database. Predicates are provided for each
11
- symbol in the enumeration and the symbols may be used in finder methods.
12
- EOF
13
- gemspec.email = "greg@rujubu.com"
14
- gemspec.homepage = "http://github.com/gregspurrier/has_enumeration"
15
- gemspec.author = "Greg Spurrier"
1
+ require 'rubygems'
2
+ require 'cucumber'
3
+ require 'cucumber/rake/task'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gemspec|
8
+ gemspec.name = "has_enumeration"
9
+ gemspec.summary = "Support for symbol-based enumerations in ActiveRecord"
10
+ gemspec.description = <<-EOF
11
+ Extends ActiveRecord with the has_enumeration method allowing a symbolic
12
+ enumeration to be stored in an ActiveRecord attribute. The enumeration is
13
+ specified as a mapping between symbols and their underlying representation
14
+ in the database. Predicates are provided for each symbol in the enumeration
15
+ and the symbols may be used in finder methods. For example:
16
+
17
+ class TrafficLight < ActiveRecord::Base
18
+ # Implicit mapping when the attribute is a string storing the string
19
+ # version of the symbol:
20
+ has_enumeration :color, [:red, :yellow, :green]
21
+
22
+ # Explicit mappings between symbols and underlying values are also
23
+ # supported. E.g.:
24
+ # has_enumeration :color, :red => 1, :yellow => 2, :green => 3
25
+ end
26
+
27
+ tl = TrafficLight.new
28
+ tl.color = :red
29
+ tl.color.value # ==> :red
30
+ tl.color.red? # ==> true
31
+ tl.color.yellow? # ==> false
32
+
33
+ TrafficLight.all(:conditions => {:color => :red}) # ==> all red traffic lights
34
+
35
+ When using ActiveRecord 3, the symbolic values can also be used when interacting
36
+ with the underlying Arel attributes for a model:
37
+
38
+ attr = TrafficLight.arel_table[:color]
39
+ TrafficLight.where(attr.in([:yellow, :green])) # ==> yellow or green lights
40
+
41
+ has_enumeration has been tested with:
42
+
43
+ Rubies: Ruby 1.8.7, Ruby 1.9.2, and JRuby 1.5.1.
44
+ ActiveRecord: 2.3.8 and 3.0.0.rc
45
+ EOF
46
+ gemspec.email = "greg@rujubu.com"
47
+ gemspec.homepage = "http://github.com/gregspurrier/has_enumeration"
48
+ gemspec.author = "Greg Spurrier"
49
+ end
50
+ Jeweler::GemcutterTasks.new
51
+ rescue LoadError
52
+ puts "Jeweler not available. Install it with: gem install jeweler"
53
+ end
54
+
55
+ task :features => 'features:all'
56
+ namespace :features do
57
+ task :all => [:common, :rails3]
58
+
59
+ Cucumber::Rake::Task.new(:common) do |t|
60
+ features = %w(explicitly_mapped_enumeration implicitly_mapped_enumeration)
61
+ feature_files = features.map {|f| "features/#{f}.feature"}.join(' ')
62
+ t.cucumber_opts = feature_files
63
+ end
64
+
65
+ Cucumber::Rake::Task.new(:rails3) do |t|
66
+ features = %w(arel_attributes)
67
+ feature_files = features.map {|f| "features/#{f}.feature"}.join(' ')
68
+ t.cucumber_opts = feature_files
69
+ end
16
70
  end
17
- Jeweler::GemcutterTasks.new
data/TODO ADDED
@@ -0,0 +1,5 @@
1
+ Prior to 1.0.0:
2
+ - Raise exception when assigning an invalid value
3
+ - meta_where interoperability (?)
4
+ - rdoc documentation for has_enumeration
5
+ - Rake task to automate testing the supported Rubies and ActiveRecord versions
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -0,0 +1,20 @@
1
+ Feature:
2
+
3
+ As a programmer using has_enumeration in Rails 3
4
+ I want to be able to refer to the enumeration symbolically when working with
5
+ the underlying arel attributes for a model
6
+ So that I can write pretty, concise code.
7
+
8
+
9
+ Scenario Outline: find objects with a specific enumerated value via arel
10
+ Given a model with an explicitly-mapped enumeration of red, green, and blue
11
+ And a set of objects with a variety of values for the enumeration
12
+ When I query for objects with the value <value> via arel
13
+ Then I should get all of the objects having that value
14
+ And I should not get any objects having other values
15
+
16
+ Scenarios: querying various values
17
+ | value |
18
+ | :red |
19
+ | :green |
20
+ | :blue |
@@ -49,16 +49,3 @@ Feature:
49
49
  | :red |
50
50
  | :green |
51
51
  | :blue |
52
-
53
- Scenario Outline: find objects with a specific enumerated value via arel
54
- Given a model with an explicitly-mapped enumeration of red, green, and blue
55
- And a set of objects with a variety of values for the enumeration
56
- When I query for objects with the value <value> via arel
57
- Then I should get all of the objects having that value
58
- And I should not get any objects having other values
59
-
60
- Scenarios: querying various values
61
- | value |
62
- | :red |
63
- | :green |
64
- | :blue |
@@ -49,16 +49,3 @@ Feature:
49
49
  | :red |
50
50
  | :green |
51
51
  | :blue |
52
-
53
- Scenario Outline: find objects with a specific enumerated value via arel
54
- Given a model with an implicitly-mapped enumeration of red, green, and blue
55
- And a set of objects with a variety of values for the enumeration
56
- When I query for objects with the value <value> via arel
57
- Then I should get all of the objects having that value
58
- And I should not get any objects having other values
59
-
60
- Scenarios: querying various values
61
- | value |
62
- | :red |
63
- | :green |
64
- | :blue |
@@ -46,7 +46,7 @@ end
46
46
 
47
47
  When /^I query for objects with the value :([a-z_]+)$/ do |value|
48
48
  @desired_color = value.to_sym
49
- @results = @model_class.where(:color => @desired_color).order(:id)
49
+ @results = @model_class.all(:conditions => {:color => @desired_color}, :order => :id)
50
50
  end
51
51
 
52
52
  When /^I query for objects with the value :([a-z_]+) via arel$/ do |value|
@@ -1,8 +1,13 @@
1
1
  $LOAD_PATH << File.expand_path('../../../lib', __FILE__)
2
+
3
+ ENV['AR_VERSION'] ||= '3_0'
4
+
5
+ require 'rubygems'
6
+ require 'bundler/setup'
2
7
  require 'has_enumeration'
3
8
 
4
9
  ActiveRecord::Base.establish_connection(
5
- :adapter => 'sqlite3',
10
+ :adapter => defined?(JRUBY_VERSION) ? 'jdbcsqlite3': 'sqlite3',
6
11
  :database => File.expand_path('../database', __FILE__)
7
12
  )
8
13
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_enumeration
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Greg Spurrier
@@ -15,11 +15,46 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-09 00:00:00 -07:00
18
+ date: 2010-08-18 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
22
- description: " Extends ActiveRecord with the has_enumeration method that allows an\n attribute to be declared as storing an enumeration. The enumeration\n is specified as a mapping between symbols and their underlying\n representation in the database. Predicates are provided for each\n symbol in the enumeration and the symbols may be used in finder methods.\n"
22
+ description: |
23
+ Extends ActiveRecord with the has_enumeration method allowing a symbolic
24
+ enumeration to be stored in an ActiveRecord attribute. The enumeration is
25
+ specified as a mapping between symbols and their underlying representation
26
+ in the database. Predicates are provided for each symbol in the enumeration
27
+ and the symbols may be used in finder methods. For example:
28
+
29
+ class TrafficLight < ActiveRecord::Base
30
+ # Implicit mapping when the attribute is a string storing the string
31
+ # version of the symbol:
32
+ has_enumeration :color, [:red, :yellow, :green]
33
+
34
+ # Explicit mappings between symbols and underlying values are also
35
+ # supported. E.g.:
36
+ # has_enumeration :color, :red => 1, :yellow => 2, :green => 3
37
+ end
38
+
39
+ tl = TrafficLight.new
40
+ tl.color = :red
41
+ tl.color.value # ==> :red
42
+ tl.color.red? # ==> true
43
+ tl.color.yellow? # ==> false
44
+
45
+ TrafficLight.all(:conditions => {:color => :red}) # ==> all red traffic lights
46
+
47
+ When using ActiveRecord 3, the symbolic values can also be used when interacting
48
+ with the underlying Arel attributes for a model:
49
+
50
+ attr = TrafficLight.arel_table[:color]
51
+ TrafficLight.where(attr.in([:yellow, :green])) # ==> yellow or green lights
52
+
53
+ has_enumeration has been tested with:
54
+
55
+ Rubies: Ruby 1.8.7, Ruby 1.9.2, and JRuby 1.5.1.
56
+ ActiveRecord: 2.3.8 and 3.0.0.rc
57
+
23
58
  email: greg@rujubu.com
24
59
  executables: []
25
60
 
@@ -28,12 +63,15 @@ extensions: []
28
63
  extra_rdoc_files:
29
64
  - LICENSE.txt
30
65
  - README.txt
66
+ - TODO
31
67
  files:
32
68
  - Gemfile
33
69
  - LICENSE.txt
34
70
  - README.txt
35
71
  - Rakefile
72
+ - TODO
36
73
  - VERSION
74
+ - features/arel_attributes.feature
37
75
  - features/explicitly_mapped_enumeration.feature
38
76
  - features/implicitly_mapped_enumeration.feature
39
77
  - features/step_definitions/has_enumeration_steps.rb