classy_enum-mongoid 0.0.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/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +26 -0
- data/Rakefile +6 -0
- data/classy_enum-mongoid.gemspec +20 -0
- data/lib/classy_enum-mongoid.rb +10 -0
- data/lib/classy_enum-mongoid/version.rb +5 -0
- data/spec/adapter_spec.rb +87 -0
- data/spec/spec_helper.rb +17 -0
- metadata +111 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 beerlington
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# ClassyEnum::Mongoid
|
2
|
+
|
3
|
+
[ClassyEnum](https://github.com/beerlington/classy_enum) is a Ruby on Rails gem that adds class-based enumerator functionality to model attributes. This adaptor works with Mongoid v2.1.0+
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'classy_enum-mongoid'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install classy_enum-mongoid
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
See the [ClassyEnum README](https://github.com/beerlington/classy_enum#readme)
|
22
|
+
for documentation and usage examples.
|
23
|
+
|
24
|
+
## Copyright
|
25
|
+
|
26
|
+
Copyright (c) 2012 [Peter Brown](https://github.com/beerlington). See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/classy_enum-mongoid/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["beerlington"]
|
6
|
+
gem.email = ["pete@lette.us"]
|
7
|
+
gem.description = %q{ClassyEnum adapter for Mongoid}
|
8
|
+
gem.summary = %q{ClassyEnum adapter for Mongoid}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "classy_enum-mongoid"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = ClassyEnum::Mongoid::VERSION
|
17
|
+
gem.add_dependency('classy_enum', '>= 3.0.1')
|
18
|
+
gem.add_dependency('mongoid', '>= 2.1')
|
19
|
+
gem.add_development_dependency('rspec-rails', '~> 2.11.0')
|
20
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
class Breed < ClassyEnum::Base; end
|
4
|
+
class Breed::GoldenRetriever < Breed; end
|
5
|
+
class Breed::Snoop < Breed; end
|
6
|
+
class Breed::Husky < Breed; end
|
7
|
+
|
8
|
+
class Dog
|
9
|
+
include Mongoid::Document
|
10
|
+
field :breed, type: String
|
11
|
+
classy_enum_attr :breed
|
12
|
+
end
|
13
|
+
|
14
|
+
class AllowBlankBreedDog
|
15
|
+
include Mongoid::Document
|
16
|
+
field :breed, type: String
|
17
|
+
classy_enum_attr :breed, :allow_blank => true
|
18
|
+
end
|
19
|
+
|
20
|
+
class AllowNilBreedDog
|
21
|
+
include Mongoid::Document
|
22
|
+
field :breed, type: String
|
23
|
+
classy_enum_attr :breed, :allow_nil => true
|
24
|
+
end
|
25
|
+
|
26
|
+
class OtherDog
|
27
|
+
include Mongoid::Document
|
28
|
+
field :other_breed, type: String
|
29
|
+
classy_enum_attr :other_breed, :enum => 'Breed'
|
30
|
+
end
|
31
|
+
|
32
|
+
describe Dog do
|
33
|
+
specify { Dog.new(:breed => nil).should_not be_valid }
|
34
|
+
specify { Dog.new(:breed => '').should_not be_valid }
|
35
|
+
|
36
|
+
context "with valid breed options" do
|
37
|
+
subject { Dog.new(:breed => :golden_retriever) }
|
38
|
+
it { should be_valid }
|
39
|
+
its(:breed) { should be_a(Breed::GoldenRetriever) }
|
40
|
+
its('breed.allow_blank') { should be_false }
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with invalid breed options" do
|
44
|
+
subject { Dog.new(:breed => :fake_breed) }
|
45
|
+
it { should_not be_valid }
|
46
|
+
it { should have(1).error_on(:breed) }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "A ClassyEnum that allows blanks" do
|
51
|
+
specify { AllowBlankBreedDog.new(:breed => nil).should be_valid }
|
52
|
+
specify { AllowBlankBreedDog.new(:breed => '').should be_valid }
|
53
|
+
|
54
|
+
context "with valid breed options" do
|
55
|
+
subject { AllowBlankBreedDog.new(:breed => :golden_retriever) }
|
56
|
+
it { should be_valid }
|
57
|
+
its('breed.allow_blank') { should be_true }
|
58
|
+
end
|
59
|
+
|
60
|
+
context "with invalid breed options" do
|
61
|
+
subject { AllowBlankBreedDog.new(:breed => :fake_breed) }
|
62
|
+
it { should_not be_valid }
|
63
|
+
it { should have(1).error_on(:breed) }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "A ClassyEnum that allows nils" do
|
68
|
+
specify { AllowNilBreedDog.new(:breed => nil).should be_valid }
|
69
|
+
specify { AllowNilBreedDog.new(:breed => '').should_not be_valid }
|
70
|
+
|
71
|
+
context "with valid breed options" do
|
72
|
+
subject { AllowNilBreedDog.new(:breed => :golden_retriever) }
|
73
|
+
it { should be_valid }
|
74
|
+
its('breed.allow_blank') { should be_true }
|
75
|
+
end
|
76
|
+
|
77
|
+
context "with invalid breed options" do
|
78
|
+
subject { AllowNilBreedDog.new(:breed => :fake_breed) }
|
79
|
+
it { should_not be_valid }
|
80
|
+
it { should have(1).error_on(:breed) }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "A ClassyEnum that has a different field name than the enum" do
|
85
|
+
subject { OtherDog.new(:other_breed => :snoop) }
|
86
|
+
its(:other_breed) { should be_a(Breed::Snoop) }
|
87
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'mongoid'
|
6
|
+
require 'action_view'
|
7
|
+
require 'action_controller'
|
8
|
+
require 'rspec/rails'
|
9
|
+
require 'classy_enum-mongoid'
|
10
|
+
|
11
|
+
Mongoid.configure do |config|
|
12
|
+
config.connect_to("mongoid-rspec-test")
|
13
|
+
end
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.color_enabled = true
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: classy_enum-mongoid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- beerlington
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: classy_enum
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.0.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: mongoid
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.1'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.1'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec-rails
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.11.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.11.0
|
62
|
+
description: ClassyEnum adapter for Mongoid
|
63
|
+
email:
|
64
|
+
- pete@lette.us
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- classy_enum-mongoid.gemspec
|
75
|
+
- lib/classy_enum-mongoid.rb
|
76
|
+
- lib/classy_enum-mongoid/version.rb
|
77
|
+
- spec/adapter_spec.rb
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
homepage: ''
|
80
|
+
licenses: []
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
hash: 4150067450634108922
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
hash: 4150067450634108922
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 1.8.24
|
106
|
+
signing_key:
|
107
|
+
specification_version: 3
|
108
|
+
summary: ClassyEnum adapter for Mongoid
|
109
|
+
test_files:
|
110
|
+
- spec/adapter_spec.rb
|
111
|
+
- spec/spec_helper.rb
|