mongoid-enum_attribute 0.1.0 → 1.0.1

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: 2e0c939d3c2c2a5677c00e67b188c2f1121a74b514481a26850ae44132d8b58b
4
- data.tar.gz: 7a81b66ee67d78377af402636a31be30594f3558103fc9b4868b5373f6aba3ee
3
+ metadata.gz: c85c88df691e9234b725d9426676a137c4b7feff5fba0fe40a34b8c6d06298a2
4
+ data.tar.gz: 2547e88eb4f8e120bf9fd183dbb1beb6154f588d98d6227c1e070e67133acd10
5
5
  SHA512:
6
- metadata.gz: eb7c9892acf4df44ea84e40019a7db574fe5ce5638707d621e527ca456655d4dede81f56c9c56d8ea6bad1aebf675bf34bd89d2891512fff3759a9f2ab3033cc
7
- data.tar.gz: b799c8b3c833c15751ae2e5f8f792232717ebea7a895d63bfbb9b9ff23cce1c478d4ffe415f83d02ce516e970fb087608419b7098dde82962906c70559717fda
6
+ metadata.gz: 8115f38cd0ef33ec05157f05691f6dd8988dc392bf84b5cd1d074125f41e0d60e3b20ee6c07501505180f591a596cd77bb56cacc3069bd9f6747e140b83d7060
7
+ data.tar.gz: e6f1ab33617bc6fbe8ea1a187af56c64d66a8392a9a29d4fee0c90d5a734b238be029d4df6143a28eb0f4de06a314db524b96ae1e68d7d5890264744840187ff
@@ -0,0 +1,29 @@
1
+ name: Tests
2
+ on: [push, pull_request]
3
+ concurrency:
4
+ group: ${{ github.ref }}
5
+ cancel-in-progress: true
6
+ jobs:
7
+ test:
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ gemfile: ["7", "8"]
12
+ ruby: ["2.7", "3.0", "3.1", "3.2"]
13
+ include:
14
+ - gemfile: "6"
15
+ ruby: "2.7"
16
+ runs-on: ubuntu-latest
17
+ services:
18
+ mongodb:
19
+ image: mongo
20
+ ports: ["27017:27017"]
21
+ env:
22
+ BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
23
+ steps:
24
+ - uses: actions/checkout@v3
25
+ - uses: ruby/setup-ruby@v1
26
+ with:
27
+ ruby-version: ${{ matrix.ruby }}
28
+ bundler-cache: true
29
+ - run: bundle exec rake
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /tmp/
9
9
 
10
10
  Gemfile.lock
11
+ /gemfiles/*.gemfile.lock
data/Appraisals ADDED
@@ -0,0 +1,11 @@
1
+ appraise "6" do
2
+ gem "mongoid", "~> 6.0"
3
+ end
4
+
5
+ appraise "7" do
6
+ gem "mongoid", "~> 7.0"
7
+ end
8
+
9
+ appraise "8" do
10
+ gem "mongoid", "~> 8.0"
11
+ end
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.0.1
4
+
5
+ * Mongoid 8 compatibility
6
+
7
+ ## 1.0.0
8
+
9
+ * switch from deprecated Symbol type to string, [PR #1](https://github.com/tomasc/mongoid-enum_attribute/pull/1), thanks [@romansavrulin](https://github.com/romansavrulin)
10
+
3
11
  ## 0.1.0
4
12
 
5
13
  * first release
data/README.md CHANGED
@@ -25,7 +25,7 @@ Or install it yourself as:
25
25
  ```ruby
26
26
  class Payment
27
27
  include Mongoid::Document
28
- include Mongoid::Enum
28
+ include Mongoid::EnumAttribute
29
29
 
30
30
  enum :status, [:pending, :approved, :declined]
31
31
  end
@@ -101,4 +101,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
101
101
 
102
102
  ## Contributing
103
103
 
104
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mongoid-enum_attribute.
104
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tomasc/mongoid-enum_attribute.
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "mongoid", "~> 6.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "mongoid", "~> 7.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "mongoid", "~> 8.0"
6
+
7
+ gemspec path: "../"
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module EnumAttribute
3
- VERSION = "0.1.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
@@ -8,11 +8,10 @@ module Mongoid
8
8
 
9
9
  module ClassMethods
10
10
  def enum(name, values, options = {})
11
- field_name = "#{Mongoid::EnumAttribute.configuration.field_name_prefix}#{name}"
12
11
  options = default_options(values).merge(options)
13
12
 
14
13
  set_values_constant(name, values)
15
- create_field(field_name, options)
14
+ field_name = create_field(name, options)
16
15
 
17
16
  create_validations(field_name, values, options)
18
17
  define_value_scopes_and_accessors(name, field_name, values, options)
@@ -27,7 +26,9 @@ module Mongoid
27
26
  required: true,
28
27
  validate: true,
29
28
  prefix: Mongoid::EnumAttribute.configuration.prefix,
30
- suffix: Mongoid::EnumAttribute.configuration.suffix
29
+ suffix: Mongoid::EnumAttribute.configuration.suffix,
30
+ field_name_prefix: Mongoid::EnumAttribute.configuration.field_name_prefix,
31
+ field_name: nil
31
32
  }
32
33
  end
33
34
 
@@ -36,9 +37,12 @@ module Mongoid
36
37
  const_set(const_name, values)
37
38
  end
38
39
 
39
- def create_field(field_name, options)
40
- type = options[:multiple] && Array || Symbol
40
+ def create_field(name, options)
41
+ type = options[:multiple] && Array || String
42
+ field_name = (options[:field_name] || "#{options[:field_name_prefix]}#{name}").to_s
43
+ raise "enum name #{name} and field_name option cannot be equal!" if name.to_s == field_name.to_s
41
44
  field field_name, type: type, default: options[:default]
45
+ field_name
42
46
  end
43
47
 
44
48
  def create_validations(field_name, values, options)
@@ -53,7 +57,7 @@ module Mongoid
53
57
  elsif options[:validate]
54
58
  validates(
55
59
  field_name,
56
- inclusion: { in: values.map(&:to_sym) },
60
+ inclusion: { in: values.map(&:to_s) },
57
61
  allow_nil: !options[:required]
58
62
  )
59
63
  end
@@ -100,7 +104,7 @@ module Mongoid
100
104
 
101
105
  def define_string_field_accessor(name, field_name)
102
106
  class_eval "def #{name}=(val) self.write_attribute(:#{field_name}, val && val.to_sym || nil) end"
103
- class_eval "def #{name}() self.send(:#{field_name}) end"
107
+ class_eval "def #{name}() self.send(:#{field_name}).to_sym end"
104
108
  end
105
109
 
106
110
  def define_array_accessor(accessor_name, field_name, value)
@@ -109,7 +113,7 @@ module Mongoid
109
113
  end
110
114
 
111
115
  def define_string_accessor(accessor_name, field_name, value)
112
- class_eval "def #{accessor_name}?() self.#{field_name} == :#{value} end"
116
+ class_eval "def #{accessor_name}?() self.#{field_name}.to_sym == :#{value} end"
113
117
  class_eval "def #{accessor_name}!() update_attributes! :#{field_name} => :#{value} end"
114
118
  end
115
119
  end
@@ -19,10 +19,11 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency 'mongoid', '>= 5', '< 8'
22
+ spec.add_dependency "mongoid", ">= 5"
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.16"
25
- spec.add_development_dependency "minitest", "~> 5.0"
26
- spec.add_development_dependency "rake", "~> 10.0"
27
- spec.add_development_dependency "database_cleaner"
24
+ spec.add_development_dependency "appraisal"
25
+ spec.add_development_dependency "bundler"
26
+ spec.add_development_dependency "database_cleaner-mongoid"
27
+ spec.add_development_dependency "minitest"
28
+ spec.add_development_dependency "rake"
28
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-enum_attribute
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomáš Celizna
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-03 00:00:00.000000000 Z
11
+ date: 2023-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '8'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,53 +24,64 @@ dependencies:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '5'
30
- - - "<"
27
+ - !ruby/object:Gem::Dependency
28
+ name: appraisal
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
31
32
  - !ruby/object:Gem::Version
32
- version: '8'
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
33
41
  - !ruby/object:Gem::Dependency
34
42
  name: bundler
35
43
  requirement: !ruby/object:Gem::Requirement
36
44
  requirements:
37
- - - "~>"
45
+ - - ">="
38
46
  - !ruby/object:Gem::Version
39
- version: '1.16'
47
+ version: '0'
40
48
  type: :development
41
49
  prerelease: false
42
50
  version_requirements: !ruby/object:Gem::Requirement
43
51
  requirements:
44
- - - "~>"
52
+ - - ">="
45
53
  - !ruby/object:Gem::Version
46
- version: '1.16'
54
+ version: '0'
47
55
  - !ruby/object:Gem::Dependency
48
- name: minitest
56
+ name: database_cleaner-mongoid
49
57
  requirement: !ruby/object:Gem::Requirement
50
58
  requirements:
51
- - - "~>"
59
+ - - ">="
52
60
  - !ruby/object:Gem::Version
53
- version: '5.0'
61
+ version: '0'
54
62
  type: :development
55
63
  prerelease: false
56
64
  version_requirements: !ruby/object:Gem::Requirement
57
65
  requirements:
58
- - - "~>"
66
+ - - ">="
59
67
  - !ruby/object:Gem::Version
60
- version: '5.0'
68
+ version: '0'
61
69
  - !ruby/object:Gem::Dependency
62
- name: rake
70
+ name: minitest
63
71
  requirement: !ruby/object:Gem::Requirement
64
72
  requirements:
65
- - - "~>"
73
+ - - ">="
66
74
  - !ruby/object:Gem::Version
67
- version: '10.0'
75
+ version: '0'
68
76
  type: :development
69
77
  prerelease: false
70
78
  version_requirements: !ruby/object:Gem::Requirement
71
79
  requirements:
72
- - - "~>"
80
+ - - ">="
73
81
  - !ruby/object:Gem::Version
74
- version: '10.0'
82
+ version: '0'
75
83
  - !ruby/object:Gem::Dependency
76
- name: database_cleaner
84
+ name: rake
77
85
  requirement: !ruby/object:Gem::Requirement
78
86
  requirements:
79
87
  - - ">="
@@ -86,21 +94,25 @@ dependencies:
86
94
  - - ">="
87
95
  - !ruby/object:Gem::Version
88
96
  version: '0'
89
- description:
97
+ description:
90
98
  email:
91
99
  - tomas.celizna@gmail.com
92
100
  executables: []
93
101
  extensions: []
94
102
  extra_rdoc_files: []
95
103
  files:
104
+ - ".github/workflows/test.yml"
96
105
  - ".gitignore"
97
- - ".travis.yml"
106
+ - Appraisals
98
107
  - CHANGELOG.md
99
108
  - Gemfile
100
109
  - README.md
101
110
  - Rakefile
102
111
  - bin/console
103
112
  - bin/setup
113
+ - gemfiles/6.gemfile
114
+ - gemfiles/7.gemfile
115
+ - gemfiles/8.gemfile
104
116
  - lib/mongoid/enum_attribute.rb
105
117
  - lib/mongoid/enum_attribute/configuration.rb
106
118
  - lib/mongoid/enum_attribute/validators/multiple_validator.rb
@@ -109,7 +121,7 @@ files:
109
121
  homepage: https://github.com/tomasc/mongoid-enum_attribute
110
122
  licenses: []
111
123
  metadata: {}
112
- post_install_message:
124
+ post_install_message:
113
125
  rdoc_options: []
114
126
  require_paths:
115
127
  - lib
@@ -124,9 +136,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
136
  - !ruby/object:Gem::Version
125
137
  version: '0'
126
138
  requirements: []
127
- rubyforge_project:
128
- rubygems_version: 2.7.3
129
- signing_key:
139
+ rubygems_version: 3.3.14
140
+ signing_key:
130
141
  specification_version: 4
131
142
  summary: Take on ActiveRecord::Enum in Mongoid
132
143
  test_files: []
data/.travis.yml DELETED
@@ -1,23 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- script: 'bundle exec rake'
4
- rvm:
5
- - 2.5.0
6
- services:
7
- - mongodb
8
-
9
- notifications:
10
- email:
11
- recipients:
12
- - tomas.celizna@gmail.com
13
- on_failure: change
14
- on_success: never
15
-
16
- matrix:
17
- include:
18
- - rvm: 2.3.3
19
- env: MONGOID_VERSION=5
20
- - rvm: 2.3.3
21
- env: MONGOID_VERSION=6
22
- - rvm: 2.5.0
23
- env: MONGOID_VERSION=7