hairy_dangerzone 0.0.1 → 0.0.2
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.
- data/README.md +17 -18
- data/lib/hairy_dangerzone.rb +8 -10
- data/lib/hairy_dangerzone/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -17,28 +17,27 @@ Or install it yourself as:
|
|
17
17
|
$ gem install hairy_dangerzone
|
18
18
|
|
19
19
|
## Usage
|
20
|
+
|
20
21
|
```ruby
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
# spec 2
|
36
|
-
i.hairy_dangerzone_x?(1) #=> false
|
37
|
-
i.hairy_dangerzone_x?("Hello") #=> true
|
22
|
+
class MyClass
|
23
|
+
include HairyDangerzone::Awesome
|
24
|
+
|
25
|
+
danger_danger :x, "Not a string" do |attr|
|
26
|
+
attr.is_a?(String)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
i = MyClass.new
|
31
|
+
i.x = "ok"
|
32
|
+
i.x = 1 #=> should raise "Invalid String"
|
33
|
+
|
34
|
+
i.hairy_dangerzone_x?(1) #=> false
|
35
|
+
i.hairy_dangerzone_x?("Hello") #=> true
|
38
36
|
```
|
37
|
+
|
39
38
|
## Contributing
|
40
39
|
|
41
|
-
1. Fork it ( http://github.com
|
40
|
+
1. Fork it ( http://github.com/iamteem/hairy_dangerzone/fork )
|
42
41
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
42
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
43
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/hairy_dangerzone.rb
CHANGED
@@ -8,18 +8,16 @@ module HairyDangerzone
|
|
8
8
|
|
9
9
|
module ClassMethods
|
10
10
|
def danger_danger(attribute, fail_message, &block)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
fail fail_message
|
17
|
-
end
|
11
|
+
define_method :"#{attribute}_with_danger_danger=" do |new_value|
|
12
|
+
if block.call(new_value)
|
13
|
+
send(:"#{attribute}_without_danger_danger=", new_value)
|
14
|
+
else
|
15
|
+
fail fail_message
|
18
16
|
end
|
19
|
-
|
20
|
-
alias_method :"#{attribute}_without_danger_danger=", :"#{attribute}="
|
21
|
-
alias_method :"#{attribute}=", :"#{attribute}_with_danger_danger="
|
22
17
|
end
|
18
|
+
|
19
|
+
alias_method :"#{attribute}_without_danger_danger=", :"#{attribute}="
|
20
|
+
alias_method :"#{attribute}=", :"#{attribute}_with_danger_danger="
|
23
21
|
end
|
24
22
|
end
|
25
23
|
end
|