simple_enum 2.2.1 → 2.3.0
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.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/README.md +12 -1
- data/Rakefile +13 -4
- data/lib/simple_enum/mongoid.rb +5 -3
- data/lib/simple_enum/version.rb +1 -1
- data/spec/support/mongoid_support.rb +33 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d9087e9c59c6e44c222f89f74e64ce59ddafa95
|
4
|
+
data.tar.gz: c0c6198ccfb33ef5073e13d8658ddf56f2f2674d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94d9588a9eaf13c492e0cafaca3b83e36692025c0c3e58cd23178dd0b130e364d959aceb3970292d64e38a48fd77390b12f15d704260819aa5a1c52ff2fb0602
|
7
|
+
data.tar.gz: 00ac3629cd9e0fb9f64691070a5150adf82edafa5be16d05621857e18c1278a469d0c3f4fdf7ffd165bea338e39c9ac6caf17e6ca4f41e132deff48333fdf8e6
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -246,6 +246,16 @@ so expect them to change in future versions of SimpleEnum.
|
|
246
246
|
select :user, :gender_cd, enum_option_pairs(User, :gender, true)
|
247
247
|
```
|
248
248
|
|
249
|
+
## Extensions
|
250
|
+
|
251
|
+
`simple_enum` provides hooks to extend its functionality, starting with 2.3.0
|
252
|
+
the following extensions can be used:
|
253
|
+
|
254
|
+
- **Multi-select enum** support for SimpleEnum:
|
255
|
+
[simple_enum-multiple](https://github.com/bbtfr/simple_enum-multiple)
|
256
|
+
- **Persistence values**, i.e. store values in the DB:
|
257
|
+
[simple_enum-persistence](https://github.com/bbtfr/simple_enum-persistence)
|
258
|
+
|
249
259
|
## Best practices
|
250
260
|
|
251
261
|
Do not use values named after existing, or well known method names, like `new`, `create` etc.
|
@@ -277,11 +287,12 @@ Contributors
|
|
277
287
|
- [@mhuggins](https://github.com/mhuggins) - translations fixes
|
278
288
|
- [@patbenatar](https://github.com/patbenatar) - for helping move towards 2.0 (scopes et all)
|
279
289
|
- [@abacha](https://github.com/abacha) - translation helpers, README fixes
|
290
|
+
- [@bbtfr](https://github.com/bbtfr) - for support, ideas and pushing extensions
|
280
291
|
- and all others: https://github.com/lwe/simple_enum/graphs/contributors thanks
|
281
292
|
|
282
293
|
License & Copyright
|
283
294
|
-------------------
|
284
295
|
|
285
|
-
Copyright (c) 2011-
|
296
|
+
Copyright (c) 2011-2015 by Lukas Westermann, Licensed under MIT License (see LICENSE file)
|
286
297
|
|
287
298
|
[VE.rb]: https://github.com/lwe/simple_enum/blob/master/lib/simple_enum/view_helpers.rb
|
data/Rakefile
CHANGED
@@ -5,11 +5,20 @@ require 'rake/testtask'
|
|
5
5
|
Bundler::GemHelper.install_tasks
|
6
6
|
|
7
7
|
desc 'Default: run all unit tests for both ActiveRecord & Mongoid.'
|
8
|
-
task :default => :spec
|
8
|
+
task :default => :'spec:all'
|
9
9
|
|
10
|
-
desc 'Run
|
11
|
-
task :spec
|
12
|
-
|
10
|
+
desc 'Run basic specs only (skips mongoid)'
|
11
|
+
task :spec => :'spec:basic'
|
12
|
+
|
13
|
+
namespace :spec do
|
14
|
+
desc 'Run all specs'
|
15
|
+
task :all do
|
16
|
+
sh 'bundle', 'exec', 'rspec', 'spec/'
|
17
|
+
end
|
18
|
+
|
19
|
+
task :basic do
|
20
|
+
sh 'bundle', 'exec', 'rspec', 'spec/', '-t', '~mongoid'
|
21
|
+
end
|
13
22
|
end
|
14
23
|
|
15
24
|
# Mongodb
|
data/lib/simple_enum/mongoid.rb
CHANGED
@@ -33,14 +33,16 @@ module SimpleEnum
|
|
33
33
|
# Wrap method chain to create mongoid field and additional
|
34
34
|
# column options
|
35
35
|
def as_enum(name, values, options = {})
|
36
|
-
source = options[:source].to_s.presence || "#{name}#{SimpleEnum.suffix}"
|
37
36
|
field_options = options.delete(:field)
|
37
|
+
enum = super
|
38
|
+
accessor = send("#{name.to_s.pluralize}_accessor")
|
39
|
+
|
38
40
|
unless field_options === false
|
39
41
|
field_options ||= SimpleEnum.field
|
40
|
-
field(source, field_options) if field_options
|
42
|
+
field(accessor.source, field_options) if field_options
|
41
43
|
end
|
42
44
|
|
43
|
-
|
45
|
+
enum
|
44
46
|
end
|
45
47
|
end
|
46
48
|
end
|
data/lib/simple_enum/version.rb
CHANGED
@@ -1,19 +1,46 @@
|
|
1
1
|
require 'mongoid'
|
2
2
|
|
3
|
+
# Hack to disable auto-retries for Mongo::Client - unless running
|
4
|
+
# on Travis CI
|
5
|
+
if ENV['CI'] && Mongoid.respond_to?(:default_client)
|
6
|
+
require 'mongo'
|
7
|
+
|
8
|
+
module Mongo
|
9
|
+
class Cluster
|
10
|
+
def scan!
|
11
|
+
raise ArgumentError, 'no retries please.'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
3
17
|
module MongoidSupport
|
4
18
|
def self.connection
|
5
|
-
@
|
6
|
-
Mongoid.configure
|
19
|
+
@connection_config ||= begin
|
20
|
+
Mongoid.configure do |config|
|
21
|
+
config.connect_to("simple_enum_mongoid_test", max_retries: ENV['CI'] ? 5 : 0)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Disable client errors
|
25
|
+
Moped.logger.level = Logger::ERROR if defined?(Moped)
|
26
|
+
Mongo::Logger.logger.level = Logger::ERROR if defined?(Mongo)
|
27
|
+
|
28
|
+
# Return instance
|
29
|
+
return Mongoid.default_client if Mongoid.respond_to?(:default_client)
|
30
|
+
Mongoid.default_session
|
7
31
|
end
|
8
|
-
Mongoid.default_client
|
9
32
|
end
|
10
33
|
|
11
34
|
def self.included(base)
|
12
35
|
base.before {
|
13
36
|
begin
|
14
|
-
MongoidSupport.connection.
|
15
|
-
rescue
|
16
|
-
|
37
|
+
MongoidSupport.connection.database_names
|
38
|
+
rescue => e
|
39
|
+
if ENV['CI']
|
40
|
+
raise e
|
41
|
+
else
|
42
|
+
skip "Start MongoDB server to run Mongoid integration tests..."
|
43
|
+
end
|
17
44
|
end
|
18
45
|
}
|
19
46
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas Westermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|