simple_enum 2.2.1 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 788b09549df8143f67025e1c15785ccfcf6b2ff4
4
- data.tar.gz: e1a274edb7723d4f9b354cdcae0f40179dba4a8b
3
+ metadata.gz: 3d9087e9c59c6e44c222f89f74e64ce59ddafa95
4
+ data.tar.gz: c0c6198ccfb33ef5073e13d8658ddf56f2f2674d
5
5
  SHA512:
6
- metadata.gz: 24a99e865d791190a5468b67b40345438fd32eaf7973a3d08e176ad90ef0cce5dcd9dad9614df22bff5155e74ff1bc179b41aaed007e22a0ab530a584254adab
7
- data.tar.gz: 70b69f2c0a4b1516485fba415fd62a492b680a0d4e5d09030ca2a27af790cb2a08d5f872860e399a0dca117f57384e3656eb3d6e6aa60eb61c9031b4aad0e55a
6
+ metadata.gz: 94d9588a9eaf13c492e0cafaca3b83e36692025c0c3e58cd23178dd0b130e364d959aceb3970292d64e38a48fd77390b12f15d704260819aa5a1c52ff2fb0602
7
+ data.tar.gz: 00ac3629cd9e0fb9f64691070a5150adf82edafa5be16d05621857e18c1278a469d0c3f4fdf7ffd165bea338e39c9ac6caf17e6ca4f41e132deff48333fdf8e6
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Lukas Westermann (Zurich, Switzerland)
1
+ Copyright (c) 2015 Lukas Westermann (Zurich, Switzerland)
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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-2014 by Lukas Westermann, Licensed under MIT License (see LICENSE file)
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 rspec test suite'
11
- task :spec do
12
- sh 'bundle exec rspec spec/'
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
@@ -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
- super
45
+ enum
44
46
  end
45
47
  end
46
48
  end
@@ -1,5 +1,5 @@
1
1
  module SimpleEnum
2
2
 
3
3
  # The current `SimpleEnum` version.
4
- VERSION = "2.2.1"
4
+ VERSION = "2.3.0"
5
5
  end
@@ -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
- @connection ||= begin
6
- Mongoid.configure.connect_to("simple_enum_mongoid_test")
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.list_databases
15
- rescue
16
- skip "Start MongoDB server to run Mongoid integration tests..."
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.2.1
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-14 00:00:00.000000000 Z
11
+ date: 2015-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport