class_attribute 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7f1c0e3076665cc6cc143d743caf728aaecfa9a9
4
+ data.tar.gz: 5acc71e21fae21547da2e0e31ac4bab3ab7f7e9c
5
+ SHA512:
6
+ metadata.gz: 6341c1e800d2e8a96b040572cac22c4aba188f117dbca9a108e28f9557bd23eb98e8ff64584177f1ea713e4f99b6c141b6ea027ce65b2e81994aa4e38579f6aa
7
+ data.tar.gz: b3b37e7e252b063d52cb2903c67e57ab7c761e93d3daa0d9a6e8c8f66719f1020f5cf71310ada65cedd81f3a6c6b29c066fedaf08e7bdc6577994cb587be65d0
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ script: 'bundle exec rake test:coverage --trace'
3
+ rvm:
4
+ - 2.2.0
5
+ - 2.2.2
6
+ - rbx-2
7
+ - jruby-9000
8
+
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: rbx-2
12
+ - rvm: jruby-9000
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Tobias Sandelius
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # ClassAttribute
2
+
3
+ Inheritable class level variable accessors
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'class_attribute'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install class_attribute
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/sandelius/class_attribute/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'bundler/gem_tasks'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.pattern = 'test/**/*_test.rb'
7
+ t.libs.push 'test'
8
+ end
9
+
10
+ namespace :test do
11
+ task :coverage do
12
+ ENV['COVERAGE'] = 'true'
13
+ Rake::Task['test'].invoke
14
+ end
15
+ end
16
+
17
+ task default: :test
@@ -0,0 +1,22 @@
1
+ require_relative './lib/class_attribute/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'class_attribute'
5
+ spec.version = ClassAttribute::VERSION
6
+ spec.authors = ['Tobias Sandelius']
7
+ spec.email = ['tobias@sandeli.us']
8
+ spec.summary = %q{Inheritable class level variable accessors}
9
+ spec.homepage = 'https://github.com/sandelius/class_attribute'
10
+ spec.license = 'MIT'
11
+ spec.files = `git ls-files -z`.split("\x0")
12
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
14
+ spec.require_paths = ['lib']
15
+ spec.required_ruby_version = '~> 2.2.0'
16
+
17
+ spec.add_development_dependency 'bundler', '~> 1.9'
18
+ spec.add_development_dependency 'minitest', '~> 5'
19
+ spec.add_development_dependency 'rake', '~> 10'
20
+ spec.add_development_dependency 'simplecov'
21
+ spec.add_development_dependency 'coveralls'
22
+ end
@@ -0,0 +1,85 @@
1
+ require_relative 'class_attribute/version'
2
+
3
+ # Inheritable class level variable accessors.
4
+ #
5
+ # @author Tobias Sandelius <tobias@sandeli.us>
6
+ #
7
+ # @see ClassAttribute::ClassMethods#class_attribute
8
+ module ClassAttribute
9
+ # @api private
10
+ # @see http://www.ruby-doc.org/core/Module.html#method-i-included
11
+ def self.included(base)
12
+ base.extend ClassMethods
13
+ end
14
+
15
+ module ClassMethods # :nodoc:
16
+ # Sets a class level attr_accessor(s) for the given attribute(s).
17
+ #
18
+ # @example
19
+ # require 'class_attribute'
20
+ #
21
+ # class Animal
22
+ # include ClassAttribute
23
+ #
24
+ # class_attribute :legs, :tail
25
+ #
26
+ # self.legs = 0
27
+ # self.tail = false
28
+ # end
29
+ #
30
+ # class Dog < Animal
31
+ # self.legs = 4
32
+ # self.tail = true
33
+ # end
34
+ #
35
+ # class Chicken < Animal
36
+ # self.legs = 2
37
+ # end
38
+ #
39
+ # class Snake < Animal
40
+ # end
41
+ #
42
+ # Dog.legs # => 4
43
+ # Chicken.legs # => 2
44
+ # Snake.legs # => 0
45
+ #
46
+ # Dog.tail # => true
47
+ # Chicken.tails # => false
48
+ # Snake.tail # => false
49
+ #
50
+ # @param attr [Symbol] Name of the attribute to be set.
51
+ # @param default [mixed] Attribute default value (optional).
52
+ #
53
+ # @return [void]
54
+ def class_attribute(*attrs)
55
+ singleton_class.class_eval do
56
+ attr_accessor *attrs
57
+ end
58
+
59
+ class_attributes.merge(attrs)
60
+ end
61
+
62
+ protected
63
+
64
+ # @private
65
+ # @see Class#inherited
66
+ def inherited(subclass)
67
+ class_attributes.each do |attr|
68
+ value = send(attr)
69
+ value = value.dup rescue value
70
+ subclass.class_attribute attr
71
+ subclass.send("#{attr}=", value)
72
+ end
73
+
74
+ super
75
+ end
76
+
77
+ private
78
+
79
+ # @api private
80
+ # @see http://ruby-doc.org/core-2.2.2/Class.html#method-i-inherited
81
+ def class_attributes
82
+ @class_attributes ||= ::Set.new
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,3 @@
1
+ module ClassAttribute
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,21 @@
1
+ require 'bundler/setup'
2
+
3
+ if ENV['COVERAGE'] == 'true'
4
+ require 'simplecov'
5
+ require 'coveralls'
6
+
7
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
+ SimpleCov::Formatter::HTMLFormatter,
9
+ Coveralls::SimpleCov::Formatter
10
+ ]
11
+
12
+ SimpleCov.start do
13
+ command_name 'test'
14
+ add_filter 'test'
15
+ end
16
+ end
17
+
18
+ require 'minitest/autorun'
19
+ $:.unshift 'lib'
20
+
21
+ require 'class_attribute'
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ describe ClassAttribute do
4
+ describe 'VERSION' do
5
+ it 'returns the version number' do
6
+ ClassAttribute::VERSION.must_equal '0.1.0'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,33 @@
1
+ require 'test_helper'
2
+
3
+ class Animal
4
+ include ClassAttribute
5
+ class_attribute :legs, :tail
6
+ self.legs = 0
7
+ self.tail = false
8
+ end
9
+
10
+ class Dog < Animal
11
+ self.legs = 4
12
+ self.tail = true
13
+ end
14
+
15
+ class Chicken < Animal
16
+ self.legs = 2
17
+ end
18
+
19
+ class Snake < Animal ; end
20
+
21
+ describe ClassAttribute do
22
+ describe '.class_attribute' do
23
+ it 'defines attr_accessor at class level' do
24
+ Dog.legs.must_equal(4)
25
+ Chicken.legs.must_equal(2)
26
+ Snake.legs.must_equal(0)
27
+
28
+ Dog.tail.must_equal(true)
29
+ Chicken.tail.must_equal(false)
30
+ Snake.tail.must_equal(false)
31
+ end
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: class_attribute
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tobias Sandelius
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - tobias@sandeli.us
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - class_attribute.gemspec
98
+ - lib/class_attribute.rb
99
+ - lib/class_attribute/version.rb
100
+ - test/test_helper.rb
101
+ - test/unit/class_attribute/version_test.rb
102
+ - test/unit/class_attribute_test.rb
103
+ homepage: https://github.com/sandelius/class_attribute
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: 2.2.0
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.4.7
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Inheritable class level variable accessors
127
+ test_files:
128
+ - test/test_helper.rb
129
+ - test/unit/class_attribute/version_test.rb
130
+ - test/unit/class_attribute_test.rb