attr_extras 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +34 -3
- data/lib/attr_extras/version.rb +1 -1
- data/lib/attr_extras.rb +1 -1
- data/spec/attr_extras_spec.rb +2 -2
- metadata +1 -1
data/README.md
CHANGED
@@ -1,13 +1,19 @@
|
|
1
1
|
# attr\_extras
|
2
2
|
|
3
|
-
Takes
|
3
|
+
Takes the boilerplate out of some common Ruby patterns and complements `attr` (`attr_accessor`), `attr_reader` and `attr_writer` nicely.
|
4
4
|
|
5
|
-
|
5
|
+
Provides:
|
6
|
+
|
7
|
+
* `attr_init :foo, :bar` to define an initializer that takes two arguments and assigns `@foo` and `@bar`.
|
8
|
+
* `attr_private :foo, :bar` to define private readers for `@foo` and `@bar`.
|
9
|
+
|
10
|
+
|
11
|
+
## Example
|
6
12
|
|
7
13
|
``` ruby
|
8
14
|
class MyClass
|
9
15
|
attr_init :foo, :bar
|
10
|
-
|
16
|
+
attr_private :foo
|
11
17
|
|
12
18
|
def oof
|
13
19
|
foo.reverse # Uses the private method.
|
@@ -18,6 +24,7 @@ x = MyClass.new("Foo!", "Bar!")
|
|
18
24
|
x.oof # => "!ooF"
|
19
25
|
```
|
20
26
|
|
27
|
+
|
21
28
|
## Installation
|
22
29
|
|
23
30
|
Add this line to your application's `Gemfile`:
|
@@ -32,4 +39,28 @@ Or install it yourself as:
|
|
32
39
|
|
33
40
|
gem install attr_extras
|
34
41
|
|
42
|
+
|
35
43
|
## License
|
44
|
+
|
45
|
+
Copyright (c) 2012 Barsoom AB
|
46
|
+
|
47
|
+
MIT License
|
48
|
+
|
49
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
50
|
+
a copy of this software and associated documentation files (the
|
51
|
+
"Software"), to deal in the Software without restriction, including
|
52
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
53
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
54
|
+
permit persons to whom the Software is furnished to do so, subject to
|
55
|
+
the following conditions:
|
56
|
+
|
57
|
+
The above copyright notice and this permission notice shall be
|
58
|
+
included in all copies or substantial portions of the Software.
|
59
|
+
|
60
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
61
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
62
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
63
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
64
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
65
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
66
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/attr_extras/version.rb
CHANGED
data/lib/attr_extras.rb
CHANGED
data/spec/attr_extras_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require "attr_extras"
|
|
3
3
|
|
4
4
|
class Example
|
5
5
|
attr_init :foo, :bar
|
6
|
-
|
6
|
+
attr_private :foo, :bar
|
7
7
|
end
|
8
8
|
|
9
9
|
describe Object, ".attr_init" do
|
@@ -18,7 +18,7 @@ describe Object, ".attr_init" do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
describe Object, ".
|
21
|
+
describe Object, ".attr_private" do
|
22
22
|
it "creates private readers" do
|
23
23
|
example = Example.new("Foo", "Bar")
|
24
24
|
example.send(:foo).must_equal "Foo"
|