hipaa-enum 0.1.0 → 0.2.0
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 +4 -4
- data/hipaa-enum-0.1.0.gem +0 -0
- data/hipaa-enum.gemspec +1 -1
- data/lib/hipaa/enum/configuration.rb +19 -0
- data/lib/hipaa/enum/validators/multiple_validator.rb +29 -0
- data/lib/hipaa/enum/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47417d4abf6feb3799a686883e042257f3d42a39
|
4
|
+
data.tar.gz: ccc871962873010d54a7c45b4a7b4b9082ff940f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 707be5d088ab6a78b0033b236af1f90f2cb1d85f21884b7e2c28e8e9dc03348ddd17953a2ddff9faf038c30379687b098b9dfa492de7fc2520251620a0a72518
|
7
|
+
data.tar.gz: 3588be762c356de672e60d303fab98224e50dcfe3f0fc0234f4d41b668c306ef4b6cf379f88bc9b757ca263a78ade026a9fb7ff63a1c35a5f8100e79f8807252
|
Binary file
|
data/hipaa-enum.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.description = %q{Heavily inspired by DDH's ActiveRecord::Enum, this little library is there to help you cut down the cruft in your models and make the world a happier place at the same time.}
|
13
13
|
spec.summary = %q{Sweet enum sugar for your Mongoid documents}
|
14
|
-
spec.homepage = "https://github.com/kennethrosales/
|
14
|
+
spec.homepage = "https://github.com/kennethrosales/hipaa-enum"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
spec.files = `git ls-files`.split($/)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Hipaa
|
2
|
+
module Enum
|
3
|
+
class Configuration
|
4
|
+
attr_accessor :field_name_prefix
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
self.field_name_prefix = "_"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.configuration
|
12
|
+
@configuration ||= Configuration.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.configure
|
16
|
+
yield(configuration) if block_given?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Hipaa
|
2
|
+
module Enum
|
3
|
+
module Validators
|
4
|
+
class MultipleValidator < ActiveModel::EachValidator
|
5
|
+
def validate_each(record, attribute, values)
|
6
|
+
values = Array(values)
|
7
|
+
|
8
|
+
if options[:allow_nil]
|
9
|
+
add_error_message record, attribute if !all_included?(values, options[:in])
|
10
|
+
else
|
11
|
+
add_error_message record, attribute if values.empty? || !all_included?(values, options[:in])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_error_message(record, attribute)
|
16
|
+
record.errors[attribute] << (options[:message] || "is not in #{options[:in].join ", "}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def all_included?(values, allowed)
|
20
|
+
(values - allowed).empty?
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.kind
|
24
|
+
:custom
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/hipaa/enum/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hipaa-enum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kennethrosales
|
@@ -85,10 +85,13 @@ files:
|
|
85
85
|
- Rakefile
|
86
86
|
- bin/console
|
87
87
|
- bin/setup
|
88
|
+
- hipaa-enum-0.1.0.gem
|
88
89
|
- hipaa-enum.gemspec
|
89
90
|
- lib/hipaa/enum.rb
|
91
|
+
- lib/hipaa/enum/configuration.rb
|
92
|
+
- lib/hipaa/enum/validators/multiple_validator.rb
|
90
93
|
- lib/hipaa/enum/version.rb
|
91
|
-
homepage: https://github.com/kennethrosales/
|
94
|
+
homepage: https://github.com/kennethrosales/hipaa-enum
|
92
95
|
licenses:
|
93
96
|
- MIT
|
94
97
|
metadata: {}
|