moosex 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 145aae5f2007ffa2f565296a4a256b27c32d5baa
4
- data.tar.gz: e454cd3f240e2b47c53446bf14b44fd94aaab26e
3
+ metadata.gz: 6e9e5e041a9a4a5b6dbc6c7f3172983566bfd071
4
+ data.tar.gz: 3922f36665039d14f2b84dd6eb95fb83832479c1
5
5
  SHA512:
6
- metadata.gz: 0f8761c2e4f9fbb9458f4bc7b4dc5db5f5dc1e1efa08b3d51d58da8595ec232178630afeb8909fb6b6252dabb287772e367dbc7eb2bad4c14ac38b1dc64e6094
7
- data.tar.gz: b613aa258cc7a06e7f0f44ea7f00bfdcb8aff52bd122c512f330e4f025dcf83d61a875395158e9162dd4a88355e14d9861106c904e0bb86b42f741e1fa6a1af8
6
+ metadata.gz: fd4f9224783d8ab1f5dde9d268eb497a2502d29dc67d93e2673cf71c0b941c60754e0b3802baf30e26e2c4034d95d4cfcbcd03b59ab608dccd8582ad1ef2c500
7
+ data.tar.gz: b651e838ea0f2920847692eca70f3a2d7ab5678f59936175912cfa20866fde0d5c3481fbfb9d152511ed93f29ebdb5a379f792f7b08717c3eeb7c508b77ab1cc
data/Changelog CHANGED
@@ -1,3 +1,6 @@
1
+ 0.0.13 - 2013-02-05
2
+ - change around to receive a lambda #42
3
+
1
4
  0.0.12 - 2013-02-05
2
5
  - basic support override attributes #19
3
6
  - basic support to roles #17
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- moosex (0.0.12)
4
+ moosex (0.0.13)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -25,8 +25,8 @@ class Point
25
25
  }
26
26
 
27
27
  def clear!
28
- self.x= 0 # to run with type-check you must
29
- self.y= 0 # use the setter instad @x=
28
+ self.x= 0 # to run with type-check you must
29
+ self.y= 0 # use the setter instad @x=
30
30
  end
31
31
 
32
32
  def to_s
@@ -415,16 +415,17 @@ end
415
415
 
416
416
  ### around
417
417
 
418
- The around hook is agressive: it will substitute the original method for a lambda. This lambda will receive the original method, a reference for the object and the argument list
418
+ The around hook is agressive: it will substitute the original method for a lambda. This lambda will receive the original method as a lambda, a reference for the object and the argument list, you shuld call the method_lambda using object + arguments
419
419
 
420
420
  ```ruby
421
- around(:sum) do |original_method, object, a,b,c|
422
- result = original_method.bind(object).call(a,b,c)
421
+ around(:sum) do |method_lambda, object, a,b,c|
422
+ c = 0
423
+ result = method_lambda.call(object,a,b,c)
423
424
  result + 1
424
425
  end
425
426
  ```
426
427
 
427
- it is useful to manipulate the return value if you need.
428
+ it is useful to manipulate the return value or argument list, add a begin/rescue block, aditional validations, etc, if you need.
428
429
 
429
430
  ## MooseX::Types
430
431
 
@@ -522,9 +523,9 @@ similar to isArray. if you do not specify a pair of types, it will check only if
522
523
  }
523
524
  ```
524
525
 
525
- ## isSet(type)
526
+ ### isSet(type)
526
527
 
527
- similar to isSet. the difference is: it will raise one exception if there are non unique elements in this array.
528
+ similar to isArray. the difference is: it will raise one exception if there are non unique elements in this array.
528
529
 
529
530
  ```ruby
530
531
  has x: {
@@ -533,7 +534,7 @@ similar to isSet. the difference is: it will raise one exception if there are no
533
534
  }
534
535
  ```
535
536
 
536
- ## isTuple(types)
537
+ ### isTuple(types)
537
538
 
538
539
  similar to isArray, Tuples are Arrays with fixed size. We will verify the type of each element.
539
540
 
@@ -612,8 +613,8 @@ class Currency
612
613
  # include Eq # warning 'safe' include, after equal declaration
613
614
  end
614
615
 
615
- c1 = ComplexRole::Currency.new( value: 12 )
616
- c2 = ComplexRole::Currency.new( value: 12 )
616
+ c1 = Currency.new( value: 12 )
617
+ c2 = Currency.new( value: 12 )
617
618
 
618
619
  c1.equal(c2) # true, they have the same value
619
620
  c1.no_equal(c2) # will return false
data/lib/moosex.rb CHANGED
@@ -143,9 +143,13 @@ module MooseX
143
143
  def around(method_name, &block)
144
144
  method = instance_method method_name
145
145
 
146
+ code = Proc.new do | o, *a|
147
+ method.bind(o).call(*a)
148
+ end
149
+
146
150
  define_method method_name do |*args|
147
151
 
148
- block.call(method, self,*args)
152
+ block.call(code, self,*args)
149
153
 
150
154
  end
151
155
  # __meta.add_around(method, block)
@@ -1,3 +1,3 @@
1
1
  module MooseX
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
data/spec/hooks_spec.rb CHANGED
@@ -35,9 +35,9 @@ describe "Hooks" do
35
35
  end
36
36
 
37
37
  class Hooks2 < Hooks
38
- around(:sum) do |original_method, object, a,b,c|
38
+ around(:sum) do |method_lambda, object, a,b,c|
39
39
  object.logger.inside_around_begin(a,b,c)
40
- result = original_method.bind(object).call(a,b,c)
40
+ result = method_lambda.call(object,a,b,c)
41
41
  object.logger.inside_around_end(a,b,c)
42
42
  result + 1
43
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moosex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Peczenyj