Module: TaintedLove::Utils
- Included in:
- TaintedLove
- Defined in:
- lib/tainted_love/utils.rb,
lib/tainted_love/utils/proxy.rb
Defined Under Namespace
Classes: Proxy
Instance Method Summary collapse
-
#hash(str) ⇒ String
Create a hex encoded MD5 hash.
-
#proxy_method(klass, method, replace_return_value = false) {|*args, &block| ... } ⇒ Object
Replaces a method defined in klass.
-
#tag(object, payload = {}) ⇒ Object
Adds information about the object.
Instance Method Details
#hash(str) ⇒ String
Create a hex encoded MD5 hash
59 60 61 62 63 |
# File 'lib/tainted_love/utils.rb', line 59 def hash(str) h = Digest::MD5.new h.update(str) h.hexdigest end |
#proxy_method(klass, method, replace_return_value = false) {|*args, &block| ... } ⇒ Object
Replaces a method defined in klass.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tainted_love/utils.rb', line 15 def proxy_method(klass, method, replace_return_value = false, &block) if klass.is_a?(String) if Object.const_defined?(klass) klass = Object.const_get(klass) else return end end original_method = "_tainted_love_original_#{method}" klass.class_eval do alias_method original_method, method define_method method do |*args, &given_block| return_value = send(original_method, *args, &given_block) block_return = block.call(return_value, *args, self, &block) if replace_return_value block_return else return_value end end end end |
#tag(object, payload = {}) ⇒ Object
Adds information about the object. The information can be about where the object is coming from, validation that has been done on the object, etc.
49 50 51 52 53 |
# File 'lib/tainted_love/utils.rb', line 49 def tag(object, payload = {}) object. << payload object end |