symbolized_enum 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/Appraisals +9 -8
- data/CHANGELOG.md +3 -0
- data/README.md +12 -0
- data/gemfiles/rails_5.0.gemfile +3 -2
- data/gemfiles/rails_5.1.gemfile +2 -2
- data/gemfiles/rails_5.2.gemfile +2 -2
- data/gemfiles/rails_6.0.gemfile +2 -2
- data/lib/symbolized_enum/version.rb +1 -1
- data/lib/symbolized_enum.rb +10 -1
- data/symbolized_enum.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3cae61e9b7a3a758680bddd45f3eb86a28e4e8f0f8a4951213b7333244cfb48
|
4
|
+
data.tar.gz: 89abb42e0c183bd97964ac8abe97d89015618caaaf5bed7d9cd29153ae7c54aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a6c812c39d19d7b87f95dc691e9e7831028ec43a928104b1fbc18babf723e7ab0871d7bdbf181d3c05b8669c94aedc955b4f783540881ab0a861399166eac9d
|
7
|
+
data.tar.gz: 70d304eb701005bbdfecc184f2499778952e0ee4d889fc4c87eae3508a6aeff12a202a374445e6dcaed8285dd673f3208c5ff47a603217b3967ea41f1a0685fc
|
data/.rubocop.yml
CHANGED
data/Appraisals
CHANGED
@@ -1,21 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
appraise 'rails-5.0' do
|
4
|
-
gem '
|
5
|
-
gem '
|
4
|
+
gem 'sqlite3', '~> 1.3.6'
|
5
|
+
gem 'activerecord', '5.0.7.2'
|
6
|
+
gem 'activesupport', '5.0.7.2'
|
6
7
|
end
|
7
8
|
|
8
9
|
appraise 'rails-5.1' do
|
9
|
-
gem 'activerecord', '5.1.
|
10
|
-
gem 'activesupport', '5.1.
|
10
|
+
gem 'activerecord', '5.1.7'
|
11
|
+
gem 'activesupport', '5.1.7'
|
11
12
|
end
|
12
13
|
|
13
14
|
appraise 'rails-5.2' do
|
14
|
-
gem 'activerecord', '5.2.
|
15
|
-
gem 'activesupport', '5.2.
|
15
|
+
gem 'activerecord', '5.2.3'
|
16
|
+
gem 'activesupport', '5.2.3'
|
16
17
|
end
|
17
18
|
|
18
19
|
appraise 'rails-6.0' do
|
19
|
-
gem 'activerecord', '6.0.0.
|
20
|
-
gem 'activesupport', '6.0.0.
|
20
|
+
gem 'activerecord', '6.0.0.rc1'
|
21
|
+
gem 'activesupport', '6.0.0.rc1'
|
21
22
|
end
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -37,6 +37,18 @@ class Post < ApplicationRecord
|
|
37
37
|
symbolized_enum :post_type, in: [:informative, :rant]
|
38
38
|
end
|
39
39
|
|
40
|
+
# Default value
|
41
|
+
class Post < ApplicationRecord
|
42
|
+
include SymbolizedEnum
|
43
|
+
|
44
|
+
# A database column 'post_type' can be used as a symbolized enumeration by:
|
45
|
+
symbolized_enum :post_type, default: :informative, in: [:informative, :rant]
|
46
|
+
end
|
47
|
+
|
48
|
+
post = Post.new
|
49
|
+
post.post_type
|
50
|
+
=> :informative
|
51
|
+
|
40
52
|
# Optional predicate methods
|
41
53
|
class Post < ApplicationRecord
|
42
54
|
include SymbolizedEnum
|
data/gemfiles/rails_5.0.gemfile
CHANGED
data/gemfiles/rails_5.1.gemfile
CHANGED
data/gemfiles/rails_5.2.gemfile
CHANGED
data/gemfiles/rails_6.0.gemfile
CHANGED
data/lib/symbolized_enum.rb
CHANGED
@@ -9,6 +9,8 @@ module SymbolizedEnum
|
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
|
11
11
|
module ClassMethods
|
12
|
+
NO_DEFAULT_PROVIDED = Object.new # :nodoc:
|
13
|
+
|
12
14
|
# @param [String, Symbol] attr_name Activerecord attribute to treat as a symbol
|
13
15
|
# @param kwargs [Boolean] :predicates (false) Generate boolean methods for each enum value.
|
14
16
|
# This must be true for any of the other predicate options to take effect
|
@@ -18,13 +20,20 @@ module SymbolizedEnum
|
|
18
20
|
# suffixed with the name of the attribute
|
19
21
|
# @param kwargs [Proc, nil] :predicate_name_generator (nil) Generate boolean methods for each enum value by calling
|
20
22
|
# the proc with attribute name and enum value
|
23
|
+
# @param kwargs [Object, nil] :default This value is passed to the activerecord attribute default option
|
21
24
|
# @param [Hash] **validates_inclusion_of_options Any options accepted by activerecord's validates_inclusion_of
|
22
25
|
def symbolized_enum(attr_name, predicates: false,
|
23
26
|
prefixed_predicate: false,
|
24
27
|
suffixed_predicate: false,
|
25
28
|
predicate_name_generator: nil,
|
29
|
+
default: NO_DEFAULT_PROVIDED,
|
26
30
|
**validates_inclusion_of_options)
|
27
|
-
|
31
|
+
if default == NO_DEFAULT_PROVIDED
|
32
|
+
attribute(attr_name, :symbol)
|
33
|
+
else
|
34
|
+
attribute(attr_name, :symbol, default: default)
|
35
|
+
end
|
36
|
+
|
28
37
|
validates_inclusion_of(attr_name, validates_inclusion_of_options)
|
29
38
|
|
30
39
|
return unless predicates
|
data/symbolized_enum.gemspec
CHANGED
@@ -40,6 +40,6 @@ Gem::Specification.new do |spec|
|
|
40
40
|
spec.add_development_dependency 'rake', '~> 10.0'
|
41
41
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
42
42
|
spec.add_development_dependency 'rubocop'
|
43
|
-
spec.add_development_dependency 'sqlite3'
|
43
|
+
spec.add_development_dependency 'sqlite3', '~> 1.3'
|
44
44
|
spec.add_development_dependency 'with_model'
|
45
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: symbolized_enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Will Leonard
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -152,16 +152,16 @@ dependencies:
|
|
152
152
|
name: sqlite3
|
153
153
|
requirement: !ruby/object:Gem::Requirement
|
154
154
|
requirements:
|
155
|
-
- - "
|
155
|
+
- - "~>"
|
156
156
|
- !ruby/object:Gem::Version
|
157
|
-
version: '
|
157
|
+
version: '1.3'
|
158
158
|
type: :development
|
159
159
|
prerelease: false
|
160
160
|
version_requirements: !ruby/object:Gem::Requirement
|
161
161
|
requirements:
|
162
|
-
- - "
|
162
|
+
- - "~>"
|
163
163
|
- !ruby/object:Gem::Version
|
164
|
-
version: '
|
164
|
+
version: '1.3'
|
165
165
|
- !ruby/object:Gem::Dependency
|
166
166
|
name: with_model
|
167
167
|
requirement: !ruby/object:Gem::Requirement
|