private_attrs 0.1.1 → 0.2.0
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/README.md +26 -30
- data/lib/private_attrs/attr_methods.rb +4 -4
- data/lib/private_attrs/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 951b463b4eebf168950cc603b01c5d25937e2cc0
|
4
|
+
data.tar.gz: 5e901de2a98dbdd54060f1682f09e3d3f30006b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 819fa2cb47e06bd2ef466bce3f1c324a1d350c47b5c211bd9f6753cf197137df5a52712e9b30e2be1b70e07e925fb0ad32e51dcf2f00da981e00af4c86cca420
|
7
|
+
data.tar.gz: fb07fc7a75a30058d8ef6ac9d99ef85482601108f3b1c3647b55087a8963946fc85afbfceb8845a3c98e4e11a971cb86fa93d6d922166dbd94ad080ce1c07839
|
data/README.md
CHANGED
@@ -2,52 +2,32 @@
|
|
2
2
|
|
3
3
|
[](https://codeclimate.com/github/wzcolon/private_attrs/maintainability)
|
4
4
|
|
5
|
-
|
6
|
-
readers/writers/accessors.
|
5
|
+
## Introducing Private Attrs
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
Add this line to your application's Gemfile:
|
11
|
-
|
12
|
-
```ruby
|
13
|
-
gem 'private_attrs'
|
14
|
-
```
|
15
|
-
|
16
|
-
And then execute:
|
17
|
-
|
18
|
-
$ bundle
|
19
|
-
|
20
|
-
Or install it yourself as:
|
21
|
-
|
22
|
-
$ gem install private_attrs
|
7
|
+
The private_attrs gem is a quick addition to Ruby’s Class object that allows for defining private attribute methods.
|
23
8
|
|
24
9
|
## Usage
|
25
10
|
|
26
|
-
Inside any class object you can now define private attr methods.
|
27
|
-
|
28
11
|
```
|
29
12
|
class Crocodile
|
30
|
-
|
31
13
|
private_attr_reader :temper
|
32
14
|
|
33
|
-
def
|
15
|
+
def initialize(temper)
|
34
16
|
@temper = temper
|
35
17
|
end
|
36
18
|
end
|
19
|
+
```
|
37
20
|
|
21
|
+
```
|
38
22
|
Crocodile.new('angry').temper # => NoMethodError "private method 'temper' called for ...
|
39
23
|
```
|
40
24
|
|
41
|
-
|
42
|
-
|
43
|
-
In short, because existing patterns to do this are ugly. This particular
|
44
|
-
pattern violates 'the scissor rule' of coding in that there is not a clear
|
45
|
-
separation between public and private methods.
|
25
|
+
But, why?
|
46
26
|
|
27
|
+
In short, because existing patterns to do this are ugly. This particular pattern violates the ‘Scissors Rule' of coding in that there is not a clear separation between public and private methods.
|
47
28
|
|
48
29
|
```
|
49
30
|
class Crocodile
|
50
|
-
|
51
31
|
private
|
52
32
|
|
53
33
|
attr_reader :temper
|
@@ -77,8 +57,7 @@ class Crocodile
|
|
77
57
|
end
|
78
58
|
```
|
79
59
|
|
80
|
-
This
|
81
|
-
methods definded at the top of any given class.
|
60
|
+
This example is better but still not ideal as we want all of our attribute methods defined at the top of any given class.
|
82
61
|
|
83
62
|
```
|
84
63
|
class Truck
|
@@ -106,7 +85,8 @@ class Truck
|
|
106
85
|
end
|
107
86
|
```
|
108
87
|
|
109
|
-
Other patterns are even worse
|
88
|
+
Other patterns are even worse…
|
89
|
+
|
110
90
|
```
|
111
91
|
class Pet
|
112
92
|
|
@@ -123,6 +103,22 @@ class Pet
|
|
123
103
|
end
|
124
104
|
```
|
125
105
|
|
106
|
+
## Installation
|
107
|
+
|
108
|
+
Add this line to your application's Gemfile:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
gem 'private_attrs'
|
112
|
+
```
|
113
|
+
|
114
|
+
And then execute:
|
115
|
+
|
116
|
+
$ bundle
|
117
|
+
|
118
|
+
Or install it yourself as:
|
119
|
+
|
120
|
+
$ gem install private_attrs
|
121
|
+
|
126
122
|
## License
|
127
123
|
|
128
124
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -10,19 +10,19 @@ module AttrMethods
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.private_attr_writer(*args)
|
13
|
-
private
|
14
13
|
args.each do |arg|
|
14
|
+
private
|
15
15
|
attr_writer arg.to_sym
|
16
|
+
public
|
16
17
|
end
|
17
|
-
public
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.private_attr_accessor(*args)
|
21
|
-
private
|
22
21
|
args.each do |arg|
|
22
|
+
private
|
23
23
|
attr_accessor arg.to_sym
|
24
|
+
public
|
24
25
|
end
|
25
|
-
public
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: private_attrs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Colon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
111
|
rubyforge_project:
|
112
|
-
rubygems_version: 2.
|
112
|
+
rubygems_version: 2.4.5.2
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
115
|
summary: Adds private attr methods to Class object
|