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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c089b2dcba0df33f1e1d8539e9b0a6a425d2b3f0937f954ad17962603d9ecd2
4
- data.tar.gz: b850d77014ef19831201f527930f8eab90f483866e6c96cb17127b129f4a26bb
3
+ metadata.gz: c3cae61e9b7a3a758680bddd45f3eb86a28e4e8f0f8a4951213b7333244cfb48
4
+ data.tar.gz: 89abb42e0c183bd97964ac8abe97d89015618caaaf5bed7d9cd29153ae7c54aa
5
5
  SHA512:
6
- metadata.gz: 580ec2c80e547ec07aca508678ddf64959c75585444b16088302fbd9fa8df770a8bb825dfa8627e6ba48808f991a549c03f70f12060f0ad58802a8e349b31f8f
7
- data.tar.gz: 332d5a7d78de72429032b91084b1a08d0ff640059069292f5f27d3984beb845fb1c2e4fa83e22c56d566a8f0ff8b684465e73c95357d6c6456e1cc57b882c2e9
6
+ metadata.gz: 0a6c812c39d19d7b87f95dc691e9e7831028ec43a928104b1fbc18babf723e7ab0871d7bdbf181d3c05b8669c94aedc955b4f783540881ab0a861399166eac9d
7
+ data.tar.gz: 70d304eb701005bbdfecc184f2499778952e0ee4d889fc4c87eae3508a6aeff12a202a374445e6dcaed8285dd673f3208c5ff47a603217b3967ea41f1a0685fc
data/.rubocop.yml CHANGED
@@ -35,3 +35,6 @@ Metrics/AbcSize:
35
35
 
36
36
  Metrics/MethodLength:
37
37
  Enabled: false
38
+
39
+ Metrics/PerceivedComplexity:
40
+ Enabled: false
data/Appraisals CHANGED
@@ -1,21 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  appraise 'rails-5.0' do
4
- gem 'activerecord', '5.0.7'
5
- gem 'activesupport', '5.0.7'
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.6'
10
- gem 'activesupport', '5.1.6'
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.1'
15
- gem 'activesupport', '5.2.1'
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.beta1'
20
- gem 'activesupport', '6.0.0.beta1'
20
+ gem 'activerecord', '6.0.0.rc1'
21
+ gem 'activesupport', '6.0.0.rc1'
21
22
  end
data/CHANGELOG.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  ### Unreleased
4
4
 
5
+ ### 0.3.0
6
+ - Add `default` option to `symbolized_enum` that is passed through to ActiveRecord `attribute`
7
+
5
8
  ### 0.2.0
6
9
  - Support rails 6.0
7
10
 
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
@@ -4,7 +4,8 @@
4
4
 
5
5
  source 'https://rubygems.org'
6
6
 
7
- gem 'activerecord', '5.0.7'
8
- gem 'activesupport', '5.0.7'
7
+ gem 'activerecord', '5.0.7.2'
8
+ gem 'activesupport', '5.0.7.2'
9
+ gem 'sqlite3', '~> 1.3.6'
9
10
 
10
11
  gemspec path: '../'
@@ -4,7 +4,7 @@
4
4
 
5
5
  source 'https://rubygems.org'
6
6
 
7
- gem 'activerecord', '5.1.6'
8
- gem 'activesupport', '5.1.6'
7
+ gem 'activerecord', '5.1.7'
8
+ gem 'activesupport', '5.1.7'
9
9
 
10
10
  gemspec path: '../'
@@ -4,7 +4,7 @@
4
4
 
5
5
  source 'https://rubygems.org'
6
6
 
7
- gem 'activerecord', '5.2.1'
8
- gem 'activesupport', '5.2.1'
7
+ gem 'activerecord', '5.2.3'
8
+ gem 'activesupport', '5.2.3'
9
9
 
10
10
  gemspec path: '../'
@@ -4,7 +4,7 @@
4
4
 
5
5
  source 'https://rubygems.org'
6
6
 
7
- gem 'activerecord', '6.0.0.beta1'
8
- gem 'activesupport', '6.0.0.beta1'
7
+ gem 'activerecord', '6.0.0.rc1'
8
+ gem 'activesupport', '6.0.0.rc1'
9
9
 
10
10
  gemspec path: '../'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SymbolizedEnum
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -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
- attribute(attr_name, :symbol)
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
@@ -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.2.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-01-22 00:00:00.000000000 Z
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: '0'
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: '0'
164
+ version: '1.3'
165
165
  - !ruby/object:Gem::Dependency
166
166
  name: with_model
167
167
  requirement: !ruby/object:Gem::Requirement