kattr 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +21 -0
- data/.rbenv-version +1 -0
- data/.rspec +2 -0
- data/LICENSE +20 -0
- data/README.markdown +29 -0
- data/Rakefile +11 -0
- data/VERSION +1 -0
- data/kattr.gemspec +16 -0
- data/lib/kattr.rb +3 -0
- data/lib/kattr/accessor.rb +10 -0
- data/lib/kattr/reader.rb +11 -0
- data/lib/kattr/version.rb +0 -0
- data/lib/kattr/writer.rb +10 -0
- data/spec/kattr_spec.rb +33 -0
- data/spec/spec_helper.rb +5 -0
- metadata +63 -0
data/.gitignore
ADDED
data/.rbenv-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3-p327-perf
|
data/.rspec
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.markdown
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
kattr
|
2
|
+
=====
|
3
|
+
|
4
|
+
Works much like the version for rails (except it doesn't accept blocks and doesn't use eval).
|
5
|
+
It is prefered to use `kattr_*` instead of `cattr_*` so there are no confusion. If you are using
|
6
|
+
this gem outside of rails, it should be alright
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
class Moo
|
10
|
+
cattr_accessor :cow
|
11
|
+
end
|
12
|
+
|
13
|
+
Moo.cow = 'animal'
|
14
|
+
Moo.class_variables
|
15
|
+
#=> [:@@cow]
|
16
|
+
```
|
17
|
+
|
18
|
+
|
19
|
+
## Note on Patches/Pull Requests
|
20
|
+
|
21
|
+
1. Fork it
|
22
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
23
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
24
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
25
|
+
5. Create new Pull Request
|
26
|
+
|
27
|
+
## Copyright
|
28
|
+
|
29
|
+
Copyright (c) 2010 Daniel Bretoi. See LICENSE for details.
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.2
|
data/kattr.gemspec
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Teo Ljungberg"]
|
5
|
+
gem.email = ["teo.ljungberg@gmail.com"]
|
6
|
+
gem.description = %q{cattr like attr_* but for class methods}
|
7
|
+
gem.summary = %q{attr_* for class methods}
|
8
|
+
gem.homepage = "http://github.com/metamorfos/kattr"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "kattr"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = "0.0.1"
|
16
|
+
end
|
data/lib/kattr.rb
ADDED
data/lib/kattr/reader.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
class Class
|
2
|
+
def kattr_reader(*syms)
|
3
|
+
syms.each do |sym|
|
4
|
+
self.class.send(:define_method, sym) do
|
5
|
+
return nil unless class_variable_defined? "@@#{sym}"
|
6
|
+
return class_variable_get "@@#{sym}"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
alias_method :cattr_reader, :kattr_reader
|
11
|
+
end
|
File without changes
|
data/lib/kattr/writer.rb
ADDED
data/spec/kattr_spec.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative '../lib/kattr'
|
2
|
+
|
3
|
+
describe Class do
|
4
|
+
before do
|
5
|
+
class Dog
|
6
|
+
cattr_reader :teeth
|
7
|
+
cattr_writer :eye_color
|
8
|
+
cattr_accessor :hair_color
|
9
|
+
|
10
|
+
def self.teeth
|
11
|
+
"sharp"
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.eye_color
|
15
|
+
@@eye_color
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'cattr_reader' do
|
21
|
+
Dog.teeth.should eq("sharp")
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'cattr_writer' do
|
25
|
+
Dog.eye_color = "green"
|
26
|
+
Dog.eye_color.should eq("green")
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'cattr_accessor' do
|
30
|
+
Dog.hair_color = 'grey'
|
31
|
+
Dog.hair_color.should eq("grey")
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kattr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Teo Ljungberg
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-26 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: cattr like attr_* but for class methods
|
15
|
+
email:
|
16
|
+
- teo.ljungberg@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- .rbenv-version
|
23
|
+
- .rspec
|
24
|
+
- LICENSE
|
25
|
+
- README.markdown
|
26
|
+
- Rakefile
|
27
|
+
- VERSION
|
28
|
+
- kattr.gemspec
|
29
|
+
- lib/kattr.rb
|
30
|
+
- lib/kattr/accessor.rb
|
31
|
+
- lib/kattr/reader.rb
|
32
|
+
- lib/kattr/version.rb
|
33
|
+
- lib/kattr/writer.rb
|
34
|
+
- spec/kattr_spec.rb
|
35
|
+
- spec/spec_helper.rb
|
36
|
+
homepage: http://github.com/metamorfos/kattr
|
37
|
+
licenses: []
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
none: false
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
none: false
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.8.23
|
57
|
+
signing_key:
|
58
|
+
specification_version: 3
|
59
|
+
summary: attr_* for class methods
|
60
|
+
test_files:
|
61
|
+
- spec/kattr_spec.rb
|
62
|
+
- spec/spec_helper.rb
|
63
|
+
has_rdoc:
|