accessor 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.travis.yml +2 -0
- data/CHANGELOG.mdown +50 -0
- data/Gemfile +4 -0
- data/Guardfile +26 -0
- data/LICENSE +22 -0
- data/README.md +136 -0
- data/Rakefile +2 -0
- data/accessor.gemspec +26 -0
- data/benchmarks/vs_attr.rb +42 -0
- data/example/example_1.rb +20 -0
- data/lib/accessor.rb +131 -0
- data/lib/accessor/version.rb +3 -0
- data/test/helper.rb +14 -0
- data/test/test_accessor.rb +89 -0
- metadata +150 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.mdown
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
1.0.2 / 2012-01-17
|
3
|
+
==================
|
4
|
+
|
5
|
+
* Fixing the listed version
|
6
|
+
* Detailing the gemspec
|
7
|
+
* Updating the readme with real details
|
8
|
+
* Merge branch 'release/1.0.0' into develop
|
9
|
+
|
10
|
+
1.0.0 / 2012-01-16
|
11
|
+
==================
|
12
|
+
|
13
|
+
* Delgating to attribute for writer and accessor
|
14
|
+
* Delegating for writer and accessor
|
15
|
+
* Raising on no names given, for accessor and writer
|
16
|
+
* Returning self for chaining
|
17
|
+
* Delegating to the class method
|
18
|
+
* Raising if no names given
|
19
|
+
* Going over each name given and creating an attribute
|
20
|
+
* Defining the method for the property and proc
|
21
|
+
* Raising if it doesnt match reader, writer, or accessor
|
22
|
+
* Returning the ivar value if no arg given
|
23
|
+
* Determining how to treat arg given
|
24
|
+
* Writing accessor proc generator
|
25
|
+
* Writing writer proc generator
|
26
|
+
* Writing logic on proc generation
|
27
|
+
* Checking if types are correct
|
28
|
+
* Dropping scaffold comment
|
29
|
+
* Extending the Object class with Accessor
|
30
|
+
* Defining the core attributes method and documentation
|
31
|
+
* Defining the instance accessor method and documentation
|
32
|
+
* Defining the accessor metamethod and documentation
|
33
|
+
* Defining the instance writer method and docs
|
34
|
+
* Defining the writer metamethod and docs
|
35
|
+
* Defining the instance reader method and docs
|
36
|
+
* Defining the reader metamethod and documentation
|
37
|
+
* Adding documentation on the possible API
|
38
|
+
* Creating a test for features in Accessor
|
39
|
+
* Comparing attr to Accessor via benchmark
|
40
|
+
* Adding a simple example of the API
|
41
|
+
* Adding in a Guardfile for continous testing
|
42
|
+
* Adding a dummy class for my tests
|
43
|
+
* Adding pride to my tests
|
44
|
+
* Fixing rocco problem with redcarpet version
|
45
|
+
* Adding the initial changelog
|
46
|
+
|
47
|
+
0.0.1 / 2012-01-16
|
48
|
+
==================
|
49
|
+
|
50
|
+
* Initial bundler scaffold
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'bundler' do
|
5
|
+
watch('Gemfile')
|
6
|
+
# Uncomment next line if Gemfile contain `gemspec' command
|
7
|
+
watch(/^.+\.gemspec/)
|
8
|
+
end
|
9
|
+
|
10
|
+
guard 'minitest' do
|
11
|
+
# with Minitest::Unit
|
12
|
+
watch(%r|^test/test_(.*)\.rb|)
|
13
|
+
watch(%r|^lib/(.*)\.rb|) { |m| "test/test_#{m[1]}.rb" }
|
14
|
+
watch(%r|^test/helper\.rb|) { "test" }
|
15
|
+
|
16
|
+
# with Minitest::Spec
|
17
|
+
# watch(%r|^spec/(.*)_spec\.rb|)
|
18
|
+
# watch(%r|^lib/(.*)\.rb|) { |m| "spec/#{m[1]}_spec.rb" }
|
19
|
+
# watch(%r|^spec/spec_helper\.rb|) { "spec" }
|
20
|
+
end
|
21
|
+
|
22
|
+
guard 'rocco' do
|
23
|
+
watch(%r{^lib/.*\.rb$})
|
24
|
+
end
|
25
|
+
|
26
|
+
watch(%r|^benchmarks/(.*)\.rb$|) { |m| eval File.read "benchmarks/#{m[1]}.rb" }
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Kurtis Rainbolt-Greene
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
accessor
|
2
|
+
========
|
3
|
+
|
4
|
+
The accessor gem is for giving you easy syntax sugar for getters, setters, and accessors.
|
5
|
+
|
6
|
+
|
7
|
+
usage
|
8
|
+
-----
|
9
|
+
|
10
|
+
Sure, you can use `attr_accessor`, `attr_reader`, and `attr_writer` but the `attr` gang can't do this!:
|
11
|
+
|
12
|
+
- Chain together setters: `person.name("Kurtis").email("me+accessor@kurtisrainboltgreene.name").age(24)`
|
13
|
+
- Define new accessors, getters, and setters on instances: `person.accessor!(:secret_token)`
|
14
|
+
- Do both: `person.accessor(:api_token, :dashboard_token).api_token(generated_token).dashboard_token`
|
15
|
+
|
16
|
+
Here's an example:
|
17
|
+
|
18
|
+
``` ruby
|
19
|
+
require 'accessor'
|
20
|
+
|
21
|
+
class Person
|
22
|
+
accessor :name, :email
|
23
|
+
writer :password
|
24
|
+
reader :encrypted_password
|
25
|
+
|
26
|
+
def encrypt_password!
|
27
|
+
@encrypted_password = Base64::strict_encode64(@password)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
contact = Person.new
|
33
|
+
contact.name "Kurtis Rainbolt-Greene"
|
34
|
+
contact.email "me+accessor@kurtisrainboltgreene.name"
|
35
|
+
contact.email
|
36
|
+
|
37
|
+
contact.accessor!(:age).age 24
|
38
|
+
```
|
39
|
+
|
40
|
+
|
41
|
+
installing
|
42
|
+
----------
|
43
|
+
|
44
|
+
**Requirements**
|
45
|
+
|
46
|
+
1. Ruby MRI 1.9+
|
47
|
+
2. RubyGems 1.6+
|
48
|
+
|
49
|
+
Like any other gem, all you have to do is either use:
|
50
|
+
|
51
|
+
``` bash
|
52
|
+
$ gem install accessor
|
53
|
+
```
|
54
|
+
|
55
|
+
Or add it to your `Gemfile`:
|
56
|
+
|
57
|
+
``` ruby
|
58
|
+
source :rubygems
|
59
|
+
|
60
|
+
gem "accessor", "1.0.2"
|
61
|
+
```
|
62
|
+
|
63
|
+
That's all you have to do.
|
64
|
+
|
65
|
+
**Testing**
|
66
|
+
|
67
|
+
To make sure you did everything right do the following:
|
68
|
+
|
69
|
+
``` ruby
|
70
|
+
ruby -e "p require 'accessor'"
|
71
|
+
true
|
72
|
+
```
|
73
|
+
|
74
|
+
|
75
|
+
issues & documentation
|
76
|
+
----------------------
|
77
|
+
|
78
|
+
* [Documentation](http://krainboltgreene.github.com/accessor/documentation)
|
79
|
+
* [Issues](https://github.com/krainboltgreene/accessor/issues)
|
80
|
+
|
81
|
+
We welcome any pull requests or commits that improve `accessor`.
|
82
|
+
|
83
|
+
|
84
|
+
changelog
|
85
|
+
---------
|
86
|
+
|
87
|
+
- 1.0.2: Adding helpful README and gemspec details
|
88
|
+
- 1.0.0: Initial release
|
89
|
+
|
90
|
+
|
91
|
+
contributing
|
92
|
+
------------
|
93
|
+
|
94
|
+
* **Fork** the repository
|
95
|
+
* **Clone the repository** locally, or **edit via Github**
|
96
|
+
* Create a **new branch** using the [Git Flow Standard](http://yakiloo.com/getting-started-git-flow/) conventions
|
97
|
+
* Commit **often** and **when important**
|
98
|
+
* **DO NOT CHANGE** ANY OF THESE (without making a new branch for *that* change):
|
99
|
+
* `*.gemspec`
|
100
|
+
* `Rakefile`
|
101
|
+
* `.rvmrc`
|
102
|
+
* `.gitignore`
|
103
|
+
* Any part of the git history
|
104
|
+
* **Write tests** specifically for the changes you've made, if no test exist
|
105
|
+
* **Push** your feature or hotfix branch to Github.
|
106
|
+
* Make a **Pull Request**
|
107
|
+
|
108
|
+
|
109
|
+
Credits
|
110
|
+
-------
|
111
|
+
|
112
|
+
- Myself!...So far.
|
113
|
+
|
114
|
+
License
|
115
|
+
-------
|
116
|
+
|
117
|
+
Copyright (c) 2012 Kurtis Rainbolt-Greene
|
118
|
+
|
119
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
120
|
+
a copy of this software and associated documentation files (the
|
121
|
+
"Software"), to deal in the Software without restriction, including
|
122
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
123
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
124
|
+
permit persons to whom the Software is furnished to do so, subject to
|
125
|
+
the following conditions:
|
126
|
+
|
127
|
+
The above copyright notice and this permission notice shall be
|
128
|
+
included in all copies or substantial portions of the Software.
|
129
|
+
|
130
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
131
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
132
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
133
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
134
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
135
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
136
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/accessor.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/accessor/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Kurtis Rainbolt-Greene"]
|
6
|
+
gem.email = ["kurtisrainboltgreene@gmail.com"]
|
7
|
+
gem.description = "A syntactically better accessor, setter, and getter metamethod generator"
|
8
|
+
gem.summary = %q{A syntactically better accessor, setter, and getter metamethod generator}
|
9
|
+
gem.homepage = "http://krainboltgreene.github.com/accessor"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "accessor"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Accessor::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency 'rake', '~> 0.9'
|
19
|
+
gem.add_development_dependency 'rocco', '~> 0.8'
|
20
|
+
gem.add_development_dependency 'redcarpet', '~> 1.7'
|
21
|
+
gem.add_development_dependency 'awesome_print', '~> 1.0'
|
22
|
+
gem.add_development_dependency 'guard', '~> 0.10'
|
23
|
+
gem.add_development_dependency 'guard-minitest', '~> 0.4'
|
24
|
+
gem.add_development_dependency 'guard-rocco', '~> 0.0.3'
|
25
|
+
gem.add_development_dependency 'guard-bundler', '~> 0.1'
|
26
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
|
3
|
+
accessor_time = Benchmark.realtime do
|
4
|
+
require 'accessor'
|
5
|
+
class Person
|
6
|
+
accessor :name, :email
|
7
|
+
writer :password
|
8
|
+
reader :encrypted_password
|
9
|
+
|
10
|
+
def encrypt_password!
|
11
|
+
@encrypted_password = Base64::strict_encode64(@password)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
contact = Person.new
|
17
|
+
contact.name "Kurtis Rainbolt-Greene"
|
18
|
+
contact.email "me+accessor@kurtisrainboltgreene.name"
|
19
|
+
contact.email
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_time = Benchmark.realtime do
|
23
|
+
class Person
|
24
|
+
attr_accessor :name, :email
|
25
|
+
attr_reader :password
|
26
|
+
attr_writer :encrypted_password
|
27
|
+
|
28
|
+
def encrypt_password!
|
29
|
+
@encrypted_password = Base64::strict_encode64(@password)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
contact = Person.new
|
35
|
+
contact.name = "Kurtis Rainbolt-Greene"
|
36
|
+
contact.email = "me+accessor@kurtisrainboltgreene.name"
|
37
|
+
contact.email
|
38
|
+
end
|
39
|
+
|
40
|
+
puts "Benchmarks Accessor vs attr:"
|
41
|
+
puts " - Accessor: Time elapsed #{accessor_time * 1000}ms"
|
42
|
+
puts " - attr: Time elapsed #{attr_time * 1000}ms"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'accessor'
|
2
|
+
|
3
|
+
class Person
|
4
|
+
accessor :name, :email
|
5
|
+
writer :password
|
6
|
+
reader :encrypted_password
|
7
|
+
|
8
|
+
def encrypt_password!
|
9
|
+
@encrypted_password = Base64::strict_encode64(@password)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
contact = Person.new
|
15
|
+
contact.name "Kurtis Rainbolt-Greene"
|
16
|
+
contact.email "me+accessor@kurtisrainboltgreene.name"
|
17
|
+
contact.email
|
18
|
+
|
19
|
+
contact.accessor!(:age).age 24
|
20
|
+
p contact
|
data/lib/accessor.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
require "accessor/version"
|
2
|
+
|
3
|
+
# The Accessor library is for giving your setters, getters, and accessors
|
4
|
+
# a more suggary syntax:
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# class Person
|
8
|
+
# accessor :name, :email
|
9
|
+
# writer :password
|
10
|
+
# reader :encrypted_password
|
11
|
+
#
|
12
|
+
# def encrypt_password!
|
13
|
+
# @encrypted_password = Base64::strict_encode64(@password)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# contact = Person.new
|
19
|
+
# contact.name "Kurtis Rainbolt-Greene"
|
20
|
+
# contact.email "me+accessor@kurtisrainboltgreene.name"
|
21
|
+
# contact.email
|
22
|
+
# # => "me+accessor@kurtisrainboltgreene.name"
|
23
|
+
# contact.password "ilovehorsesthateatglue"
|
24
|
+
# contact.password
|
25
|
+
# # => 0 for 1 arguments
|
26
|
+
# contact.encrypted_password "Test!"
|
27
|
+
# # => 1 for 0 arguments
|
28
|
+
# contact.encrypt_password!
|
29
|
+
# contact.encrypted_password
|
30
|
+
# # => "MTIzNDEyMzQ="
|
31
|
+
# contact.name("James Earl Jones").email("jejones@gmail.com")
|
32
|
+
# # => #<Person:0x3E034 @name="James Earl Jones" @email="jejones@gmail.com">
|
33
|
+
#
|
34
|
+
module Accessor
|
35
|
+
# The `reader` method is a metamethod, and it takes an `Array` of `Symbols`.
|
36
|
+
# It goes over each `Symbol` and calls the `attribute` method with the
|
37
|
+
# `Symbol` as an argument, creating a getter method.
|
38
|
+
def reader(*names)
|
39
|
+
names.each { |name| attribute name, :reader }
|
40
|
+
end
|
41
|
+
|
42
|
+
# The `reader!` method is a metamethod, and it takes the same arguments as `reader`.
|
43
|
+
# The difference between the two are that `reader!` is used to define getter methods
|
44
|
+
# for the class of an instance object.
|
45
|
+
def reader!(*names)
|
46
|
+
raise ArgumentError unless names.any?
|
47
|
+
self.class.reader(*names)
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
# The `writer` method is a metamethod, and it takes an `Array` of `Symbols`.
|
53
|
+
# It goes over each `Symbol` and calls the `attribute` method with the
|
54
|
+
# `Symbol` as an argument, creating a setter method.
|
55
|
+
def writer(*names)
|
56
|
+
names.each { |name| attribute name, :writer }
|
57
|
+
end
|
58
|
+
|
59
|
+
# The `writer!` method is a metamethod, and it takes the same arguments as `writer`.
|
60
|
+
# The difference between the two are that `writer!` is used to define setter methods
|
61
|
+
# for the class of an instance object.
|
62
|
+
def writer!(*names)
|
63
|
+
raise ArgumentError unless names.any?
|
64
|
+
self.class.writer(*names)
|
65
|
+
self
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
# The `accessor` method is a metamethod, and it takes an `Array` of `Symbols`.
|
70
|
+
# It goes over each `Symbol` and calls the `attribute` method with the
|
71
|
+
# `Symbol` as an argument, creating both a getter and setter method.
|
72
|
+
def accessor(*names)
|
73
|
+
names.each { |name| attribute name }
|
74
|
+
end
|
75
|
+
|
76
|
+
# The `accessor!` method is a metamethod, and it takes the same arguments as `accessor`.
|
77
|
+
# The difference between the two are that `accessor!` is used to define setter/getter methods
|
78
|
+
# for the class of an instance object.
|
79
|
+
def accessor!(*names)
|
80
|
+
raise ArgumentError unless names.any?
|
81
|
+
self.class.accessor(*names)
|
82
|
+
self
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
# The `attribute` method is the metamethod behind `accessor`, `writer`, and `reader`.
|
87
|
+
# It takes two `Symbols`, but has a default for the last.
|
88
|
+
def attribute(name, type = :accessor)
|
89
|
+
# If the `name` or `type` parameters are anything but `Symbol` classes
|
90
|
+
# then it should raise a TypeError.
|
91
|
+
raise TypeError unless name.is_a?(Symbol) && type.is_a?(Symbol)
|
92
|
+
|
93
|
+
# Based on the `Symbol` passed in as `type` determine what kind of `Proc` to create.
|
94
|
+
block = case type
|
95
|
+
|
96
|
+
# For getter metamethods, pass along a block that accesses the instance variable
|
97
|
+
when :reader then -> { instance_variable_get "@#{name}".to_sym }
|
98
|
+
|
99
|
+
# For setter metamethods, pass along a block that takes a single argument and
|
100
|
+
# sets the instance variable to that value, finally returning `self`. The `self`
|
101
|
+
# return allows for cool chaining like `person.age(24).name("Katie")`
|
102
|
+
when :writer then ->(arg) { instance_variable_set "@#{name}".to_sym, arg; self }
|
103
|
+
|
104
|
+
# Finally for both functionalities the accessor metamethod does both the setter and
|
105
|
+
# reader based on if an argument was passed or not (default not).
|
106
|
+
when :accessor
|
107
|
+
->(arg = nil) {
|
108
|
+
if arg
|
109
|
+
instance_variable_set "@#{name}".to_sym, arg
|
110
|
+
self
|
111
|
+
else
|
112
|
+
instance_variable_get "@#{name}".to_sym
|
113
|
+
end
|
114
|
+
}
|
115
|
+
# If for some reason the `type` parameter was a Symbol, but not those listed above
|
116
|
+
# then raise an `ArgumentError`
|
117
|
+
else raise ArgumentError
|
118
|
+
end
|
119
|
+
|
120
|
+
# Finally define an instance method on the class with the `name` parameter and
|
121
|
+
# `Proc` created.
|
122
|
+
define_method name, block
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Extend the main object with the `Accessor` module to populate it with the correct
|
127
|
+
# method singleton methods.
|
128
|
+
class Object
|
129
|
+
extend Accessor
|
130
|
+
include Accessor
|
131
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "minitest/pride"
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'accessor'
|
4
|
+
|
5
|
+
class Person
|
6
|
+
accessor :name, :email
|
7
|
+
writer :password
|
8
|
+
reader :encrypted_password
|
9
|
+
|
10
|
+
def encrypt_password!
|
11
|
+
@encrypted_password = Base64::strict_encode64(@password)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require_relative 'helper'
|
3
|
+
|
4
|
+
class TestAccessor < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@iperson = Person.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_person_class_has_accessor_method
|
11
|
+
assert_respond_to Person, :accessor
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_person_class_has_writer_method
|
15
|
+
assert_respond_to Person, :writer
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_person_class_has_reader_method
|
19
|
+
assert_respond_to Person, :reader
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_person_has_name_accessor
|
23
|
+
assert_respond_to @iperson, :name
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_person_has_email_accessor
|
27
|
+
assert_respond_to @iperson, :email
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_person_has_password_writer
|
31
|
+
assert_respond_to @iperson, :password
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_person_has_encrypted_password_reader
|
35
|
+
assert_respond_to @iperson, :encrypted_password
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_cant_read_password_ivariable
|
39
|
+
assert_raises(ArgumentError) { @iperson.password }
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_cant_write_encrypted_password_ivariable
|
43
|
+
assert_raises(ArgumentError) { @iperson.encrypted_password("test") }
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_person_has_accessor_method
|
47
|
+
assert_respond_to @iperson, :accessor!
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_person_has_writer_method
|
51
|
+
assert_respond_to @iperson, :writer!
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_person_has_reader_method
|
55
|
+
assert_respond_to @iperson, :reader!
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_iaccessor_defines_getter_method
|
59
|
+
@iperson.accessor! :age
|
60
|
+
assert_respond_to @iperson, :age
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_iaccessor_defines_setter_method
|
64
|
+
@iperson.accessor! :age
|
65
|
+
assert_send [@iperson, :age, 23]
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_ireader_defines_getter_method
|
69
|
+
@iperson.reader! :age
|
70
|
+
assert_respond_to @iperson, :age
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_iwritter_defines_setter_method
|
74
|
+
@iperson.writer! :age
|
75
|
+
assert_send [@iperson, :age, 23]
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_iaccessor_requires_names
|
79
|
+
assert_raises(ArgumentError) { @iperson.accessor! }
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_ireader_requires_names
|
83
|
+
assert_raises(ArgumentError) { @iperson.reader! }
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_iwriter_requires_names
|
87
|
+
assert_raises(ArgumentError) { @iperson.writer! }
|
88
|
+
end
|
89
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: accessor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kurtis Rainbolt-Greene
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &2156430340 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.9'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2156430340
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rocco
|
27
|
+
requirement: &2156429780 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.8'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2156429780
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: redcarpet
|
38
|
+
requirement: &2156429280 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.7'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2156429280
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: awesome_print
|
49
|
+
requirement: &2156428780 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2156428780
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: guard
|
60
|
+
requirement: &2156428260 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0.10'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2156428260
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-minitest
|
71
|
+
requirement: &2156427760 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0.4'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2156427760
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: guard-rocco
|
82
|
+
requirement: &2156427120 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 0.0.3
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *2156427120
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: guard-bundler
|
93
|
+
requirement: &2156426540 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ~>
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0.1'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *2156426540
|
102
|
+
description: A syntactically better accessor, setter, and getter metamethod generator
|
103
|
+
email:
|
104
|
+
- kurtisrainboltgreene@gmail.com
|
105
|
+
executables: []
|
106
|
+
extensions: []
|
107
|
+
extra_rdoc_files: []
|
108
|
+
files:
|
109
|
+
- .gitignore
|
110
|
+
- .travis.yml
|
111
|
+
- CHANGELOG.mdown
|
112
|
+
- Gemfile
|
113
|
+
- Guardfile
|
114
|
+
- LICENSE
|
115
|
+
- README.md
|
116
|
+
- Rakefile
|
117
|
+
- accessor.gemspec
|
118
|
+
- benchmarks/vs_attr.rb
|
119
|
+
- example/example_1.rb
|
120
|
+
- lib/accessor.rb
|
121
|
+
- lib/accessor/version.rb
|
122
|
+
- test/helper.rb
|
123
|
+
- test/test_accessor.rb
|
124
|
+
homepage: http://krainboltgreene.github.com/accessor
|
125
|
+
licenses: []
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ! '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 1.8.10
|
145
|
+
signing_key:
|
146
|
+
specification_version: 3
|
147
|
+
summary: A syntactically better accessor, setter, and getter metamethod generator
|
148
|
+
test_files:
|
149
|
+
- test/helper.rb
|
150
|
+
- test/test_accessor.rb
|