usecasing_validations 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile.lock +2 -2
- data/lib/usecasing_validations/helpers.rb +26 -2
- data/lib/usecasing_validations/target.rb +17 -15
- data/lib/usecasing_validations/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzFjZDA5NDdjYWY1MWU0ZWVhNDc3MmZmNDg4YmUwNjVmZDgwMzBiNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MTdmYzQ4MDUxN2VmZDFmZTgyMTM2NDFmYWY0YjAzYjY3OTRkNGFlMQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
Y2U1NjJhMzRmMGJlYWRmYzE5ZDYyYWM0MjFkOTM5MTIzYzg2MjU1NDRhM2Rl
|
10
|
+
MDNlNDQ5NDU1ZmQxZWY2MzA5ZTM0NGIxY2NiMjVkZTEwZTBiYTUxNjFiMTgy
|
11
|
+
ZGUwZTU0ZGY5ZWVhOWE2MzdlZWE1NjJmZWFkNjNiY2FhNTE3ZGU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MDE0NWMyMWEyZjgyYzkxNTY5YjY4ZGMxZGMxNzc2NGViMTYzYjAxODk5Mjgx
|
14
|
+
OTFmYjgyMjE3OWJiMTRmNzg5OTQwNDVkNTQ0MjIwZDczMTQ0MjI1YTY4NmQ1
|
15
|
+
ZmUzMmQ2ODIxZjJhZjNkODdhZWNiOTBhZDFkZjkzMzkwZThlMjc=
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,33 @@
|
|
1
1
|
module UseCaseValidations
|
2
|
-
|
2
|
+
|
3
3
|
module Helpers
|
4
4
|
|
5
5
|
extend self
|
6
6
|
|
7
|
+
def _super_method(object, method_name, *args)
|
8
|
+
if object.superclass.respond_to?(method_name)
|
9
|
+
object.superclass.send(method_name, *args)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def _get_instance_variable(object, variable, default_value)
|
14
|
+
instance_var = object.instance_variable_get("@#{variable}")
|
15
|
+
|
16
|
+
return instance_var unless instance_var.nil?
|
17
|
+
|
18
|
+
instance_var = (_super_method(object, variable) || default_value)
|
19
|
+
|
20
|
+
if instance_var.class == Class
|
21
|
+
object.instance_variable_set("@#{variable}", instance_var)
|
22
|
+
else
|
23
|
+
object.instance_variable_set("@#{variable}", _duplicate(instance_var))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def _duplicate(object)
|
28
|
+
object.dup rescue object
|
29
|
+
end
|
30
|
+
|
7
31
|
def _blank?(object)
|
8
32
|
if object.is_a?(String)
|
9
33
|
object !~ /[^[:space:]]/
|
@@ -15,7 +39,7 @@ module UseCaseValidations
|
|
15
39
|
def _marked_for_destruction?(object)
|
16
40
|
object.respond_to?(:marked_for_destruction?) ? object.marked_for_destruction? : false
|
17
41
|
end
|
18
|
-
|
42
|
+
|
19
43
|
def _extract_options!(array)
|
20
44
|
if array.last.is_a?(Hash) && array.last.instance_of?(Hash)
|
21
45
|
array.pop
|
@@ -1,44 +1,46 @@
|
|
1
1
|
module UseCaseValidations
|
2
|
-
|
2
|
+
|
3
3
|
module Target
|
4
4
|
|
5
5
|
def self.included(base)
|
6
6
|
base.extend(ClassMethods)
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
self.class.target_sym
|
11
|
-
end
|
12
|
-
|
13
|
-
def parent_target_sym
|
9
|
+
def parent_target_name
|
14
10
|
self.class.options.key?(:in) ? self.class.options[:in] : nil
|
15
11
|
end
|
16
12
|
|
17
13
|
def target
|
18
|
-
send(
|
14
|
+
send(self.class.target_name)
|
19
15
|
end
|
20
16
|
|
21
17
|
def parent_target
|
22
|
-
|
18
|
+
parent_target_name ? send(parent_target_name) : nil
|
23
19
|
end
|
24
20
|
|
25
21
|
module ClassMethods
|
26
22
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
def target_name
|
24
|
+
Helpers._get_instance_variable(self, :target_name, nil)
|
25
|
+
end
|
26
|
+
|
27
|
+
def options
|
28
|
+
Helpers._get_instance_variable(self, :options, {})
|
29
|
+
end
|
30
|
+
|
31
|
+
def target(target_name, options = {})
|
32
|
+
@target_name, @options = target_name, options
|
31
33
|
|
32
34
|
if options.key?(:in)
|
33
35
|
define_method(options[:in]) { context.send(options[:in]) }
|
34
|
-
define_method(
|
36
|
+
define_method(target_name) { send(options[:in]).send(target_name) }
|
35
37
|
else
|
36
|
-
define_method(
|
38
|
+
define_method(target_name) { context.send(target_name) }
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
40
42
|
end
|
41
|
-
|
43
|
+
|
42
44
|
end
|
43
45
|
|
44
46
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usecasing_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- João Gonçalves
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
145
|
version: '0'
|
146
146
|
requirements: []
|
147
147
|
rubyforge_project:
|
148
|
-
rubygems_version: 2.
|
148
|
+
rubygems_version: 2.2.2
|
149
149
|
signing_key:
|
150
150
|
specification_version: 4
|
151
151
|
summary: UseCase Gem Extention to add Rails like validations
|