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 +4 -4
- data/Changelog +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +12 -11
- data/lib/moosex.rb +5 -1
- data/lib/moosex/version.rb +1 -1
- data/spec/hooks_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e9e5e041a9a4a5b6dbc6c7f3172983566bfd071
|
4
|
+
data.tar.gz: 3922f36665039d14f2b84dd6eb95fb83832479c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd4f9224783d8ab1f5dde9d268eb497a2502d29dc67d93e2673cf71c0b941c60754e0b3802baf30e26e2c4034d95d4cfcbcd03b59ab608dccd8582ad1ef2c500
|
7
|
+
data.tar.gz: b651e838ea0f2920847692eca70f3a2d7ab5678f59936175912cfa20866fde0d5c3481fbfb9d152511ed93f29ebdb5a379f792f7b08717c3eeb7c508b77ab1cc
|
data/Changelog
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -25,8 +25,8 @@ class Point
|
|
25
25
|
}
|
26
26
|
|
27
27
|
def clear!
|
28
|
-
self.x= 0
|
29
|
-
self.y= 0
|
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 |
|
422
|
-
|
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
|
-
|
526
|
+
### isSet(type)
|
526
527
|
|
527
|
-
similar to
|
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
|
-
|
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 =
|
616
|
-
c2 =
|
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(
|
152
|
+
block.call(code, self,*args)
|
149
153
|
|
150
154
|
end
|
151
155
|
# __meta.add_around(method, block)
|
data/lib/moosex/version.rb
CHANGED
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 |
|
38
|
+
around(:sum) do |method_lambda, object, a,b,c|
|
39
39
|
object.logger.inside_around_begin(a,b,c)
|
40
|
-
result =
|
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
|