logn-mongoid-enum 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84e093ff33daa4f4d60db0ca1bf3a7b7fb988dee
|
4
|
+
data.tar.gz: 86d57596ea689a80cd833f36bb0110b6d23c12a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49c6807484ebec29bcae4291cda83d7e9e72e57c1a8dbe3759e4ee968e2bb43619536686da406eba05a353ebb73c9b151f24b2c0c57676de8ee8ddd1bf931650
|
7
|
+
data.tar.gz: f0fea6346993b78e1afeca59a0cee507babea48b5117b52423b2385a9dc1be2577fbdce6a3a7c23640c2a882aa270846b1ead8dffc646d9213f27cb4e1d28406
|
data/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Logn
|
2
|
+
module Mongoid
|
3
|
+
module Enum
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :field_name_prefix
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
self.field_name_prefix = '_'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configuration
|
13
|
+
@configuration ||= Configuration.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.configure
|
17
|
+
yield(configuration) if block_given?
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Logn
|
2
|
+
module Mongoid
|
3
|
+
module Enum
|
4
|
+
module Validators
|
5
|
+
class MultipleValidator < ActiveModel::EachValidator
|
6
|
+
def validate_each(record, attribute, values)
|
7
|
+
values = Array(values)
|
8
|
+
|
9
|
+
if options[:allow_nil]
|
10
|
+
add_error_message record, attribute unless all_included?(values, options[:in])
|
11
|
+
else
|
12
|
+
add_error_message record, attribute if values.empty? || !all_included?(values, options[:in])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_error_message(record, attribute)
|
17
|
+
record.errors[attribute] << (options[:message] || "is not in #{options[:in].join ', '}")
|
18
|
+
end
|
19
|
+
|
20
|
+
def all_included?(values, allowed)
|
21
|
+
(values - allowed).empty?
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.kind
|
25
|
+
:custom
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logn-mongoid-enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kennethrosales
|
@@ -107,6 +107,7 @@ executables: []
|
|
107
107
|
extensions: []
|
108
108
|
extra_rdoc_files: []
|
109
109
|
files:
|
110
|
+
- ".DS_Store"
|
110
111
|
- ".gitignore"
|
111
112
|
- CODE_OF_CONDUCT.md
|
112
113
|
- Gemfile
|
@@ -115,7 +116,10 @@ files:
|
|
115
116
|
- Rakefile
|
116
117
|
- bin/console
|
117
118
|
- bin/setup
|
119
|
+
- gemfiles/mongoid-5.gemfile
|
118
120
|
- lib/logn/mongoid/enum.rb
|
121
|
+
- lib/logn/mongoid/enum/configuration.rb
|
122
|
+
- lib/logn/mongoid/enum/validators/multiple_validator.rb
|
119
123
|
- lib/logn/mongoid/enum/version.rb
|
120
124
|
- logn-mongoid-enum.gemspec
|
121
125
|
homepage: https://github.com/kennethrosales/logn-mongoid-enum
|