enum_attributes_validation 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/enum_attributes_validation.rb +46 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 42d2adee0b850e2f791721d188b738c2f5fc76a9
|
4
|
+
data.tar.gz: 403c062de6b05496ab0418541c65b61cf20aebd4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 62a8457498e1446b5c10fa9e22f6e501ea6a55d0ec4cc89c39cbb2d8f5208744dcd33b5694af7ffc712d75b99b290f7b27afff33a11e7ddf3860b26b237a1280
|
7
|
+
data.tar.gz: b4e2b43b301d286fc0e44646fdea8f89a601922bfbcc700d11740f2ac2b7f1fbcc7d0a5cef240810d75d24ab2286ae541ad3325e5669e3c1949c14640b268b36
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "enum_attributes_validation"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "enum_attributes_validation/version"
|
2
|
+
require 'active_support'
|
3
|
+
require 'active_record'
|
4
|
+
|
5
|
+
module EnumAttributesValidation
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
attr_writer :enum_invalid_attributes
|
10
|
+
def enum_invalid_attributes
|
11
|
+
@enum_invalid_attributes ||= {}
|
12
|
+
end
|
13
|
+
validate :check_enum_invalid_attributes
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def check_enum_invalid_attributes
|
18
|
+
if enum_invalid_attributes.present?
|
19
|
+
enum_invalid_attributes.each do |key, value|
|
20
|
+
errors.add(key, "invalid #{value}")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class_methods do
|
27
|
+
def validate_enum_attributes(*attributes)
|
28
|
+
attributes.each do |attribute|
|
29
|
+
string_attribute = attribute.to_s
|
30
|
+
|
31
|
+
define_method (string_attribute+"=").to_sym do |argument|
|
32
|
+
string_argument = argument.to_s
|
33
|
+
self[string_attribute] = string_argument if User.send(string_attribute.pluralize).keys.include?(string_argument)
|
34
|
+
self.enum_invalid_attributes[attribute] = string_argument unless User.send(string_attribute.pluralize).keys.include?(string_argument)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def validate_enum_attribute(*attributes)
|
40
|
+
self.validate_enum_attributes(*attributes)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# include the extension in active record
|
46
|
+
ActiveRecord::Base.send(:include, EnumAttributesValidation)
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: enum_attributes_validation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cristi Stefan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Enum Attributes Validation provides validation functionality for enum
|
42
|
+
attributes in models.
|
43
|
+
email:
|
44
|
+
- cristi.r.stefan@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- bin/console
|
50
|
+
- bin/setup
|
51
|
+
- lib/enum_attributes_validation.rb
|
52
|
+
homepage: https://github.com/CristiRazvi/enum_attributes_validation
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 2.6.8
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: Validate model enum attributes
|
76
|
+
test_files: []
|