enumerize 0.11.0 → 1.0.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: e4e3454dcf7faa010477afaa0c7de0b49e3e7e7e
4
- data.tar.gz: fe8517318865f32bfe0421493e2431f90ca568dc
3
+ metadata.gz: 4a571fc9e3b62621d40cfddd9ba755389dda8115
4
+ data.tar.gz: e6a8a7e2043a36b8072a2f28cc547efab248770a
5
5
  SHA512:
6
- metadata.gz: 9e54b9a844cf53b5570f82b4da4fbf509e4f62ef0b947ee16776b0608d2dfdde6b49d56c401abc7a16ed242bf57c64bf51450279513e70c7b577a2cbf67a4c87
7
- data.tar.gz: 0a607cef37922a25e47df3fa99b03ae4e86e06ced6b58d77c4faa91cce771ac373bdbad30244da1d052488bac2c7bfb6ab497669581430fa2253ac16e821e470
6
+ metadata.gz: bda0563e282a121e0b5e0a26144a81efc8bde072ebf1a56a357da909421f272cc02b5c7dd85dac6cf7780b42a88e302f7aef020434255682dc9a7d7840e21e9a
7
+ data.tar.gz: 5c0d858c82b33958edd3a3c8e2b347822641966e6765ad87c7fae7158b1fee0ddaac08ecbc5b88849e392b928c474435e372ceeb2beec7a9c0b3052f937073a3
data/.gitignore CHANGED
@@ -2,6 +2,7 @@
2
2
  *.rbc
3
3
  .bundle
4
4
  .config
5
+ .ruby-version
5
6
  .yardoc
6
7
  .idea/
7
8
  enumerize.iml
@@ -5,7 +5,6 @@ before_install:
5
5
  - gem install bundler
6
6
  gemfile:
7
7
  - Gemfile
8
- - Gemfile.rails32
9
8
  rvm:
10
9
  - 1.9.3
11
10
  - 2.0.0
@@ -13,9 +12,6 @@ rvm:
13
12
  - 2.2
14
13
  - jruby-19mode
15
14
  matrix:
16
- exclude:
17
- - rvm: 2.2
18
- gemfile: Gemfile.rails32
19
15
  include:
20
16
  - rvm: 2.2
21
17
  gemfile: Gemfile.rails40
@@ -4,6 +4,16 @@
4
4
 
5
5
  ### bug fix
6
6
 
7
+ ## 1.0.0 (August 2, 2015)
8
+
9
+ ### enhancements
10
+ * Add `texts` method for getting an array of text values of the enumerized field with multiple type. (by [@huynhquancam](https://github.com/huynhquancam))
11
+ * Drop Rails 3.2 support. (by [@nashby](https://github.com/nashby))
12
+
13
+ ### bug fix
14
+
15
+ * Fix conflicts when Active Record and Mongoid are used at the same time. (by [@matsu911](https://github.com/matsu911))
16
+
7
17
  ## 0.11.0 (March 29, 2015) ##
8
18
 
9
19
  ### enhancements
@@ -91,11 +91,9 @@ module Enumerize
91
91
 
92
92
  def _set_default_value_for_enumerized_attributes
93
93
  self.class.enumerized_attributes.each do |attr|
94
- # remove after dropping support for Rails 3.x
95
- # https://github.com/brainspec/enumerize/issues/101
96
- begin
94
+ if respond_to?(attr.name)
97
95
  attr_value = public_send(attr.name)
98
- rescue ActiveModel::MissingAttributeError
96
+ else
99
97
  next
100
98
  end
101
99
 
@@ -7,7 +7,7 @@ module Enumerize
7
7
  _enumerize_module.dependent_eval do
8
8
  if self < ::ActiveRecord::Base
9
9
  if options[:scope]
10
- _define_scope_methods!(name, options)
10
+ _define_activerecord_scope_methods!(name, options)
11
11
  end
12
12
  end
13
13
  end
@@ -15,7 +15,7 @@ module Enumerize
15
15
 
16
16
  private
17
17
 
18
- def _define_scope_methods!(name, options)
18
+ def _define_activerecord_scope_methods!(name, options)
19
19
  scope_name = options[:scope] == true ? "with_#{name}" : options[:scope]
20
20
 
21
21
  define_singleton_method scope_name do |*values|
@@ -7,7 +7,7 @@ module Enumerize
7
7
  _enumerize_module.dependent_eval do
8
8
  if self < ::Mongoid::Document
9
9
  if options[:scope]
10
- _define_scope_methods!(name, options)
10
+ _define_mongoid_scope_methods!(name, options)
11
11
  end
12
12
  end
13
13
  end
@@ -15,7 +15,7 @@ module Enumerize
15
15
 
16
16
  private
17
17
 
18
- def _define_scope_methods!(name, options)
18
+ def _define_mongoid_scope_methods!(name, options)
19
19
  scope_name = options[:scope] == true ? "with_#{name}" : options[:scope]
20
20
 
21
21
  define_singleton_method scope_name do |*values|
@@ -36,6 +36,10 @@ module Enumerize
36
36
  @values.to_a
37
37
  end
38
38
 
39
+ def texts
40
+ @values.collect { |value| value.text }
41
+ end
42
+
39
43
  delegate :join, to: :to_ary
40
44
 
41
45
  def ==(other)
@@ -1,3 +1,3 @@
1
1
  module Enumerize
2
- VERSION = "0.11.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -190,6 +190,13 @@ describe Enumerize::ActiveRecordSupport do
190
190
  interests.must_equal %w(music dancing)
191
191
  end
192
192
 
193
+ it 'stores multiple value passed passed to new' do
194
+ user = User.new(interests: [:music, :dancing])
195
+ user.save!
196
+ user.interests.must_equal %w(music dancing)
197
+ User.find(user.id).interests.must_equal %w(music dancing)
198
+ end
199
+
193
200
  it 'returns invalid multiple value for validation' do
194
201
  user = User.new
195
202
  user.interests << :music
@@ -104,6 +104,12 @@ describe Enumerize::Set do
104
104
  end
105
105
  end
106
106
 
107
+ describe '#texts' do
108
+ it 'returns array of text values' do
109
+ set.texts.must_equal ['A']
110
+ end
111
+ end
112
+
107
113
  describe '#join' do
108
114
  it 'joins values' do
109
115
  set << :b
@@ -3,6 +3,10 @@ require 'minitest/spec'
3
3
  require 'active_support/core_ext/kernel/reporting'
4
4
  require 'active_model'
5
5
  require 'rails'
6
+ begin
7
+ require 'mongoid'
8
+ rescue LoadError
9
+ end
6
10
 
7
11
  module RailsAdmin
8
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enumerize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Nartimov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-29 00:00:00.000000000 Z
11
+ date: 2015-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -32,12 +32,10 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - ".gitignore"
35
- - ".ruby-version"
36
35
  - ".travis.yml"
37
36
  - CHANGELOG.md
38
37
  - Gemfile
39
38
  - Gemfile.mongo_mapper
40
- - Gemfile.rails32
41
39
  - Gemfile.rails40
42
40
  - MIT-LICENSE
43
41
  - README.md
@@ -48,7 +46,6 @@ files:
48
46
  - lib/enumerize/attribute.rb
49
47
  - lib/enumerize/attribute_map.rb
50
48
  - lib/enumerize/base.rb
51
- - lib/enumerize/form_helper.rb
52
49
  - lib/enumerize/hooks/formtastic.rb
53
50
  - lib/enumerize/hooks/simple_form.rb
54
51
  - lib/enumerize/hooks/uniqueness.rb
@@ -103,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
100
  version: '0'
104
101
  requirements: []
105
102
  rubyforge_project:
106
- rubygems_version: 2.2.2
103
+ rubygems_version: 2.4.7
107
104
  signing_key:
108
105
  specification_version: 4
109
106
  summary: Enumerated attributes with I18n and ActiveRecord/Mongoid/MongoMapper support
@@ -1 +0,0 @@
1
- 2.1.5
@@ -1,23 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- gem 'rake'
6
- gem 'minitest', '~> 4.1'
7
- gem 'rspec', :require => false
8
-
9
- gem 'rails', '~> 3.2.0', :require => false
10
- gem 'sqlite3', :platform => [:ruby, :mswin, :mingw]
11
- gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
12
-
13
- platforms :rbx do
14
- gem 'rubysl', '~> 2.0'
15
- gem 'psych'
16
- gem 'rubinius-developer_tools'
17
- gem 'rubysl-test-unit'
18
- end
19
-
20
- gem 'mongoid'
21
- gem 'mongo_mapper'
22
- gem 'simple_form'
23
- gem 'formtastic'
@@ -1,25 +0,0 @@
1
- # backport of https://github.com/rails/rails/commit/3be9e8a0c2187744b6c9879ca2836cef5ebed693
2
- if defined?(ActionView::Helpers::InstanceTag)
3
- ActionView::Helpers::InstanceTag.singleton_class.class_eval do
4
- remove_method :check_box_checked?
5
-
6
- def check_box_checked?(value, checked_value)
7
- case value
8
- when TrueClass, FalseClass
9
- value
10
- when NilClass
11
- false
12
- when Integer
13
- value != 0
14
- when String
15
- value == checked_value
16
- else
17
- if value.respond_to?(:include?)
18
- value.include?(checked_value)
19
- else
20
- value.to_i != 0
21
- end
22
- end
23
- end
24
- end
25
- end