active_conformity 0.2.15 → 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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c32351157e33885331f0055a5e56aab6cd86d4e9
|
4
|
+
data.tar.gz: b9c1876e583d0b9ade88f3cdd9c2bf93b8f4e1ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a870a58b3cf208a0ae5333d3283d9d2b49f7002ea7ac762274253ef071bd35ede94e66bcc15580d79d387b41183986f05e78bab9156cb54460bfd41ace0d197
|
7
|
+
data.tar.gz: 5b05c250df7dcf2455ae555b144efea870511051f11e176b270738c1fb9dc46bc6eb12febf7f5ea721b222048e77883380d03bc824fe93a1cfe19e99641f1775
|
data/README.md
CHANGED
@@ -83,7 +83,7 @@ Please note, lack of conformity does not prevent persistence as it does with .va
|
|
83
83
|
|
84
84
|
ActiveConformity refers to the objects that tell other objects what do as conformables and the objects that are being told what to do as conformists. In the example above, the car is the conformist and the engine is the conformable.
|
85
85
|
|
86
|
-
There are several methods available to inspect what makes an object
|
86
|
+
There are several methods available to inspect what makes an object conform. In the previous example if you want to see all of the rules the car must conform to you can do the following.
|
87
87
|
|
88
88
|
```ruby
|
89
89
|
car.aggregate_conformity_set # {:size=> {:numericality => { :greater_than => 2000} } }
|
@@ -120,7 +120,7 @@ diesel_engine.remove_coformity_rule!(:size)
|
|
120
120
|
Additionally, if you want to remove all of the conformity sets for a conformable, you can do the following:
|
121
121
|
|
122
122
|
```ruby
|
123
|
-
diesel_engine.remove_rules
|
123
|
+
diesel_engine.remove_rules
|
124
124
|
```
|
125
125
|
|
126
126
|
##
|
@@ -67,8 +67,16 @@ module ActiveConformity
|
|
67
67
|
end
|
68
68
|
|
69
69
|
def conformable_references
|
70
|
-
|
71
|
-
.
|
70
|
+
return @conformable_references if defined? @conformable_references
|
71
|
+
@conformable_references = Set.new
|
72
|
+
@conformable_references.merge conformable_references_from_associations
|
73
|
+
@conformable_references.add add_self_to_conformable_references
|
74
|
+
@conformable_references = @conformable_references.to_a.compact
|
75
|
+
end
|
76
|
+
|
77
|
+
def add_self_to_conformable_references
|
78
|
+
self if Conformable.where(conformable_id: self.id,
|
79
|
+
conformable_type: self.class.name).any?
|
72
80
|
end
|
73
81
|
|
74
82
|
def remove_conformity_rule!(attr)
|
@@ -103,11 +111,6 @@ module ActiveConformity
|
|
103
111
|
end
|
104
112
|
end
|
105
113
|
|
106
|
-
def add_self_to_conformable_references
|
107
|
-
[self] if Conformable.where(conformable_id: self.id,
|
108
|
-
conformable_type: self.class.name).any?
|
109
|
-
end
|
110
|
-
|
111
114
|
def conformable_types
|
112
115
|
return @conformable_types if defined?(@conformable_types)
|
113
116
|
@conformable_types = conformables_for_class.pluck(:conformable_type)
|
@@ -57,19 +57,16 @@ class ConformitySetValidator < ActiveModel::EachValidator
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def is_a_conformists_attribute?(str)
|
60
|
-
|
61
|
-
if !
|
62
|
-
|
60
|
+
# Raise if conformist is not an ActiveRecord model
|
61
|
+
if !(conformable.conformist_type.constantize <= ActiveRecord::Base)
|
62
|
+
raise "#{conformable.conformist_type} is not a valid conformist, must be an ActiveRecord Model"
|
63
63
|
end
|
64
|
-
return true
|
65
|
-
end
|
66
64
|
|
67
|
-
|
68
|
-
if !conformable.conformist_type.constantize.respond_to?(
|
69
|
-
|
70
|
-
else
|
71
|
-
conformable.conformist_type.constantize.column_names
|
65
|
+
str = str.to_s
|
66
|
+
if !conformable.conformist_type.constantize.new.respond_to?("#{str}=")
|
67
|
+
return add_errors("#{str} is not a setter for #{conformable.conformist_type.to_s}!")
|
72
68
|
end
|
69
|
+
return true
|
73
70
|
end
|
74
71
|
|
75
72
|
def add_errors(msg)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_conformity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dandlezzz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -128,8 +128,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
version: '0'
|
129
129
|
requirements: []
|
130
130
|
rubyforge_project:
|
131
|
-
rubygems_version: 2.
|
131
|
+
rubygems_version: 2.5.1
|
132
132
|
signing_key:
|
133
133
|
specification_version: 4
|
134
134
|
summary: Database driven validations.
|
135
135
|
test_files: []
|
136
|
+
has_rdoc:
|