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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YTMxZGE1YmE0MzAxZDM2OTM0M2E4NWU3NTZhMGU4ODhkNjM5MTE1OQ==
4
+ YzFjZDA5NDdjYWY1MWU0ZWVhNDc3MmZmNDg4YmUwNjVmZDgwMzBiNw==
5
5
  data.tar.gz: !binary |-
6
- OTQwYzIzZTEwYTAxMjY0ZjQzMTdkZDhmZjU2MDgyMTBkMTY0ZTU1Yw==
6
+ MTdmYzQ4MDUxN2VmZDFmZTgyMTM2NDFmYWY0YjAzYjY3OTRkNGFlMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTYyMGM4OTJlYjhhYjEwZWM4M2EyN2FjMzg0NWNhMjQzNDU4MTM3YjBlYzhj
10
- MjAwZTY2NWQwMzNlYmE2YjAzNjA4ZjNjYzcxZTRkOWJjMjE2YjA4NzI5YzM4
11
- YWUzYmM3NGVlNGYyNDlhNWY1OTA1MDY4MjQ5OGU0ZDU4YzI2YTI=
9
+ Y2U1NjJhMzRmMGJlYWRmYzE5ZDYyYWM0MjFkOTM5MTIzYzg2MjU1NDRhM2Rl
10
+ MDNlNDQ5NDU1ZmQxZWY2MzA5ZTM0NGIxY2NiMjVkZTEwZTBiYTUxNjFiMTgy
11
+ ZGUwZTU0ZGY5ZWVhOWE2MzdlZWE1NjJmZWFkNjNiY2FhNTE3ZGU=
12
12
  data.tar.gz: !binary |-
13
- ZjEzYzRiOGVjYTA2YmJmYTNhNGZjNGY3MmJkYmY4ZDQxNWJjMjM4Y2IwNjhk
14
- MWQ5MmVmYWI5NzJmYTQzYTRhNzM4NTY5YWI5MzcyY2YwZmEzOGM4ZWRkZmIz
15
- MjAwZjgxNzY0YzRkOGY3MWIwZjAyYzI1ZjBhMjRjOGM5Y2M2ZmY=
13
+ MDE0NWMyMWEyZjgyYzkxNTY5YjY4ZGMxZGMxNzc2NGViMTYzYjAxODk5Mjgx
14
+ OTFmYjgyMjE3OWJiMTRmNzg5OTQwNDVkNTQ0MjIwZDczMTQ0MjI1YTY4NmQ1
15
+ ZmUzMmQ2ODIxZjJhZjNkODdhZWNiOTBhZDFkZjkzMzkwZThlMjc=
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usecasing_validations (0.5.1)
5
- usecasing (= 0.1.4)
4
+ usecasing_validations (0.5.3)
5
+ usecasing
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -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 target_sym
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(target_sym)
14
+ send(self.class.target_name)
19
15
  end
20
16
 
21
17
  def parent_target
22
- parent_target_sym ? send(parent_target_sym) : nil
18
+ parent_target_name ? send(parent_target_name) : nil
23
19
  end
24
20
 
25
21
  module ClassMethods
26
22
 
27
- attr_reader :target_sym, :options
28
-
29
- def target(target_sym, options = {})
30
- @target_sym, @options = target_sym, options
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(target_sym) { send(options[:in]).send(target_sym) }
36
+ define_method(target_name) { send(options[:in]).send(target_name) }
35
37
  else
36
- define_method(target_sym) { context.send(target_sym) }
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
@@ -1,3 +1,3 @@
1
1
  module UseCaseValidations
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
3
3
  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.3
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-03-26 00:00:00.000000000 Z
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.1.10
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