cattr 0.1.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.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +28 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/cattr.rb +25 -0
- data/test/helper.rb +10 -0
- data/test/test_cattr.rb +33 -0
- metadata +86 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Daniel Bretoi
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
= cattr
|
2
|
+
|
3
|
+
Like attr_accessor for instance methods, but creates class methods/variables instead.
|
4
|
+
Works just like the version for rails (except it doesn't accept blocks and doesn't use eval).
|
5
|
+
|
6
|
+
class Moo
|
7
|
+
cattr_accessor :cow
|
8
|
+
end
|
9
|
+
Moo.cow = 'animal'
|
10
|
+
ap Moo.class_variables
|
11
|
+
[
|
12
|
+
[0] :@@cow
|
13
|
+
]
|
14
|
+
|
15
|
+
|
16
|
+
== Note on Patches/Pull Requests
|
17
|
+
|
18
|
+
* Fork the project.
|
19
|
+
* Make your feature addition or bug fix.
|
20
|
+
* Add tests for it. This is important so I don't break it in a
|
21
|
+
future version unintentionally.
|
22
|
+
* Commit, do not mess with rakefile, version, or history.
|
23
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
24
|
+
* Send me a pull request. Bonus points for topic branches.
|
25
|
+
|
26
|
+
== Copyright
|
27
|
+
|
28
|
+
Copyright (c) 2010 Daniel Bretoi. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "cattr"
|
8
|
+
gem.summary = %Q{cattr like attr_* but for class methods}
|
9
|
+
gem.description = %Q{cattr like attr_* but for class methods. we know rails has it, but it's useful eleswhere too.}
|
10
|
+
gem.email = "daniel@netwalk.org"
|
11
|
+
gem.homepage = "http://github.com/danielb2/cattr"
|
12
|
+
gem.authors = ["Daniel Bretoi"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "cattr #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/cattr.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
class Class
|
2
|
+
def cattr_accessor(*meths)
|
3
|
+
cattr_writer(*meths)
|
4
|
+
cattr_reader(*meths)
|
5
|
+
end
|
6
|
+
def cattr_reader(*meths)
|
7
|
+
meths.each do |meth|
|
8
|
+
self.class.send(:define_method, meth) { class_variable_get("@@#{meth}") }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
def cattr_writer(*meths)
|
12
|
+
meths.each do |meth|
|
13
|
+
self.class.send(:define_method, :"#{meth}=") do |arg|
|
14
|
+
# if we can get the class variable it means it exists so
|
15
|
+
# we don't want to overwrite it.
|
16
|
+
begin
|
17
|
+
class_variable_get("@@#{meth}")
|
18
|
+
rescue NameError
|
19
|
+
# if we get a nameerror, then it didn't exist so let's set it
|
20
|
+
class_variable_set("@@#{meth}", arg)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/test/helper.rb
ADDED
data/test/test_cattr.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestCattr < Test::Unit::TestCase
|
4
|
+
should "set and get class attributes" do
|
5
|
+
class Moo
|
6
|
+
cattr_accessor :cow
|
7
|
+
end
|
8
|
+
Moo.cow = 'test'
|
9
|
+
assert('test',Moo.cow)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "create class setter" do
|
13
|
+
class Moo
|
14
|
+
cattr_writer :cow
|
15
|
+
def self.get
|
16
|
+
@@cow
|
17
|
+
end
|
18
|
+
end
|
19
|
+
Moo.cow = 'test'
|
20
|
+
assert('test',Moo.get)
|
21
|
+
end
|
22
|
+
|
23
|
+
should "create class reder" do
|
24
|
+
class Moo
|
25
|
+
cattr_reader :cow
|
26
|
+
def self.get=(arg)
|
27
|
+
@@cow = arg
|
28
|
+
end
|
29
|
+
end
|
30
|
+
Moo.get = 'test'
|
31
|
+
assert('test',Moo.cow)
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cattr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Daniel Bretoi
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-07-20 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: thoughtbot-shoulda
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :development
|
32
|
+
version_requirements: *id001
|
33
|
+
description: cattr like attr_* but for class methods. we know rails has it, but it's useful eleswhere too.
|
34
|
+
email: daniel@netwalk.org
|
35
|
+
executables: []
|
36
|
+
|
37
|
+
extensions: []
|
38
|
+
|
39
|
+
extra_rdoc_files:
|
40
|
+
- LICENSE
|
41
|
+
- README.rdoc
|
42
|
+
files:
|
43
|
+
- .document
|
44
|
+
- .gitignore
|
45
|
+
- LICENSE
|
46
|
+
- README.rdoc
|
47
|
+
- Rakefile
|
48
|
+
- VERSION
|
49
|
+
- lib/cattr.rb
|
50
|
+
- test/helper.rb
|
51
|
+
- test/test_cattr.rb
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://github.com/danielb2/cattr
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options:
|
58
|
+
- --charset=UTF-8
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
requirements: []
|
78
|
+
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 1.3.7
|
81
|
+
signing_key:
|
82
|
+
specification_version: 3
|
83
|
+
summary: cattr like attr_* but for class methods
|
84
|
+
test_files:
|
85
|
+
- test/helper.rb
|
86
|
+
- test/test_cattr.rb
|