attr_extras 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -10,8 +10,15 @@ Defines an initializer that takes two arguments and assigns `@foo` and `@bar`.
10
10
  `attr_private :foo, :bar`<br>
11
11
  Defines private readers for `@foo` and `@bar`.
12
12
 
13
+ `pattr_initialize :foo, :bar`<br>
14
+ Defines both initializer and private readers.
15
+
13
16
  `attr_id_query :foo?, :bar?`<br>
14
- Defines query methods like `foo?` which is true iff `foo_id` is truthy. Goes well with Active Record.
17
+ Defines query methods like `foo?`, which is true iff `foo_id` is truthy. Goes well with Active Record.
18
+
19
+ Findability has been a central consideration.
20
+ Hence the long name `attr_initialize`, so you see it when scanning for the initializer;
21
+ and the enforced questionmarks with `attr_id_query :foo?`, so you can search for that method.
15
22
 
16
23
 
17
24
  ## Example
@@ -1,3 +1,3 @@
1
1
  module AttrExtras
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
data/lib/attr_extras.rb CHANGED
@@ -19,6 +19,11 @@ module AttrExtras
19
19
  private *names
20
20
  end
21
21
 
22
+ def pattr_initialize(*names)
23
+ attr_initialize *names
24
+ attr_private *names
25
+ end
26
+
22
27
  def attr_id_query(*names)
23
28
  names.each do |name|
24
29
  name = name.to_s
@@ -6,12 +6,16 @@ class Example
6
6
  attr_private :foo, :bar
7
7
  end
8
8
 
9
+ class PattrExample
10
+ pattr_initialize :foo, :bar
11
+ end
12
+
9
13
  class QueryExample
10
14
  attr_id_query :baz?, :boink?
11
15
  attr_accessor :baz_id
12
16
  end
13
17
 
14
- describe Object, ".attr_init" do
18
+ describe Object, ".attr_initialize" do
15
19
  it "creates an initializer setting those instance variables" do
16
20
  example = Example.new("Foo", "Bar")
17
21
  example.instance_variable_get("@foo").must_equal "Foo"
@@ -32,6 +36,13 @@ describe Object, ".attr_private" do
32
36
  end
33
37
  end
34
38
 
39
+ describe Object, ".pattr_initialize" do
40
+ it "creates both initializer and private readers" do
41
+ example = PattrExample.new("Foo", "Bar")
42
+ example.send(:foo).must_equal "Foo"
43
+ end
44
+ end
45
+
35
46
  describe Object, ".attr_id_query" do
36
47
  it "creates id query methods" do
37
48
  example = QueryExample.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attr_extras
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-03 00:00:00.000000000 Z
12
+ date: 2013-01-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70200792462100 !ruby/object:Gem::Requirement
16
+ requirement: &70342467445180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70200792462100
24
+ version_requirements: *70342467445180
25
25
  description:
26
26
  email:
27
27
  - henrik@nyh.se
@@ -53,7 +53,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
53
53
  version: '0'
54
54
  segments:
55
55
  - 0
56
- hash: 529900991710091167
56
+ hash: -3707645124123204298
57
57
  required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  none: false
59
59
  requirements:
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  version: '0'
63
63
  segments:
64
64
  - 0
65
- hash: 529900991710091167
65
+ hash: -3707645124123204298
66
66
  requirements: []
67
67
  rubyforge_project:
68
68
  rubygems_version: 1.8.10