active_stripper 0.3.0 → 1.0.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: a277eb0491e8dcc6b84db07c1268a910167b82f2
4
- data.tar.gz: f7a1f7e001594d9d02551a6630b51dc7dfcebb09
3
+ metadata.gz: 1d39d3a9cc0d5806ad23edbe74c7eaa97caefe3d
4
+ data.tar.gz: 8f8fe1a5a8f5e776c8f3edcfefffa49f0fc1195e
5
5
  SHA512:
6
- metadata.gz: efb4007419b663ecb2a2540ebdbc6c6d03f53789c24b7692c36360de5796fd6057ffcc6cf21c38e9935326501b5ea675e7f6c82433abca33d58cadf9bab5bda3
7
- data.tar.gz: ef8d95f1eb7d029364297ff1d37455f5e9eab8f69f35c6493151e0d1af46c3b2bf106a2cd1c0d213779b22add9cf0c78fadb4a16fb492fd1d5a560234763c639
6
+ metadata.gz: d5335aebed86f6d18daa880f2178cbd714124dd200666fb1cff855c30b9518e532578d10ab4507d631169fc7380d0e8d13f8e58186b5c6a17515aea27a5f3d16
7
+ data.tar.gz: 15bdb138efc4d1b1fcf449c0209f2defb63b86cbefaa08028d9cca58a570bf86442c7cc43f28d294339470a87df2f11288d7adb7ba858ae4e5fd0cee4a78d783
@@ -21,36 +21,50 @@ module ActiveStripper # Pun intended
21
21
  def self.iterable_apply(val, iterable_operators, base)
22
22
  iterable_operators.each do | operator_name, operator_args |
23
23
 
24
- val = case
25
- when !operator_args
26
- ActiveStripper.method_apply(val, operator_name, base)
27
- when operator_args[:module]
28
- Module.const_get(operator_args[:module])
29
- .send(operator_name, val)
30
- end
24
+ additionnal_args = nil
25
+ lookup_module_name = "ActiveStripper::Helpers"
26
+
27
+ if operator_args
28
+ additionnal_args = operator_args[:additionnal_args]
29
+ lookup_module_name = operator_args[:module] if operator_args[:module]
30
+ end
31
+
32
+ val = ActiveStripper.method_apply(val,
33
+ operator_name,
34
+ base,
35
+ lookup_module_name,
36
+ additionnal_args)
31
37
  end
32
38
 
33
39
  return val
34
40
  end
35
41
 
36
42
  #
37
- # Look up for method `operator` in ActiveStripper::Helpers and current
38
- # class and call it
43
+ # Look up for method `operator` in ActiveStripper::Helpers THEN in current
44
+ # class if not found and call it
39
45
  #
40
- # @param [String] val Value to modify
41
- # @param [String/Symbol] operator Method name to execute
42
- # @param [Object] base Instance including the current module
46
+ # @param [String] val Value to modify
47
+ # @param [Symbol] operator Method name to execute
48
+ # @param [Object] base Instance including the current module
49
+ # @param [String] module_name Name of the module where we are going to lookup
50
+ # a method which name is contained in `operator`
51
+ # if equal to EMPTY STRING the lookup context will
52
+ # be the object passed through `base`
53
+ # @param [Array] args (Optional)
54
+ # Additionnal args to pass to the processor method
43
55
  #
44
- # @return [String] Modifies value
56
+ # @return [String] Processed val if possible otherwise return val is it was
45
57
  #
46
- def self.method_apply(val, operator, base)
58
+ def self.method_apply(val, operator, base, module_name, args = nil)
59
+ lookup_module = (module_name == "") ? base : Module.const_get(module_name)
60
+
47
61
  case
48
62
  when operator.class.name === "Proc"
49
- operator.call(val)
50
- when ActiveStripper::Helpers.respond_to?(operator)
51
- ActiveStripper::Helpers.send(operator, val)
52
- when base.respond_to?(operator)
53
- base.send(operator, val)
63
+ operator.call(val, *args)
64
+ when lookup_module.respond_to?(operator)
65
+ lookup_module.send(operator, val, *args)
66
+ when lookup_module != base && base.respond_to?(operator)
67
+ base.send(operator, val, *args)
54
68
  else
55
69
  val
56
70
  end
@@ -72,9 +86,9 @@ module ActiveStripper # Pun intended
72
86
  args = args.reject { | field | self.respond_to?(field) }
73
87
 
74
88
  # Dynamically generate an anonymous module to be prepended
89
+ # self is equal to the object where the current method is called
75
90
  mod = Module.new do
76
91
  args.each do | field |
77
-
78
92
  define_method :"#{field}=" do | val |
79
93
  val = case operator.class.name
80
94
  when "Proc"
@@ -82,7 +96,10 @@ module ActiveStripper # Pun intended
82
96
  when "Hash", "Array"
83
97
  ActiveStripper.iterable_apply(val, operator, self)
84
98
  when "String", "Symbol"
85
- ActiveStripper.method_apply(val, operator, self)
99
+ ActiveStripper.method_apply(val,
100
+ operator,
101
+ self,
102
+ "ActiveStripper::Helpers")
86
103
  end
87
104
 
88
105
  super(val)
@@ -1,5 +1,5 @@
1
1
  #coding: utf-8
2
2
 
3
3
  module ActiveStripper
4
- VERSION = "0.3.0"
4
+ VERSION = "1.0.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_stripper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - François TCHENG
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-24 00:00:00.000000000 Z
11
+ date: 2017-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '3.0'
55
55
  description: |2-
56
56
 
57
- Strip or preprocess Active Record / Object attributes by creating custom setter through module prepending.
57
+ Strip / preprocess selected Active Record / Object attributes by creating custom setter through module prepending.
58
58
  Work with any Object in ruby and still allow custom setter to be defined inside the class.
59
59
  For exemple, can lowercase an email field during attribute setting for ActiveRecord instances
60
60
  instead of having to hook on validation hook on ActiveRecord.