kattr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/.rbenv-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3-p327-perf
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
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
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ task :default => :spec
7
+
8
+ task :console do
9
+ sh "pry -I lib -r kattr"
10
+ end
11
+ task c: :console
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
@@ -0,0 +1,3 @@
1
+ Dir[File.dirname(__FILE__) + '/kattr/**/*.rb'].each do |file|
2
+ require file
3
+ end
@@ -0,0 +1,10 @@
1
+ require_relative './writer'
2
+ require_relative './reader'
3
+
4
+ class Class
5
+ def kattr_accessor(*syms)
6
+ kattr_writer(*syms)
7
+ kattr_reader(*syms)
8
+ end
9
+ alias_method :cattr_accessor, :kattr_accessor
10
+ end
@@ -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
@@ -0,0 +1,10 @@
1
+ class Class
2
+ def kattr_writer(*syms)
3
+ syms.each do |sym|
4
+ self.class.send(:define_method, :"#{sym}=") do |opt|
5
+ class_variable_set("@@#{sym}", opt)
6
+ end
7
+ end
8
+ end
9
+ alias_method :cattr_writer, :kattr_writer
10
+ end
@@ -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
@@ -0,0 +1,5 @@
1
+ RSpec.configure do |config|
2
+ config.treat_symbols_as_metadata_keys_with_true_values = true
3
+ config.run_all_when_everything_filtered = true
4
+ config.filter_run :focus
5
+ end
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: