inheritable_accessors 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +50 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/inheritable_accessors.gemspec +31 -0
- data/lib/inheritable_accessors/inheritable_hash.rb +76 -0
- data/lib/inheritable_accessors/inheritable_hash_accessor.rb +32 -0
- data/lib/inheritable_accessors/version.rb +3 -0
- data/lib/inheritable_accessors.rb +9 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 81cf6392088186618510983ee2e096465eb347d5
|
4
|
+
data.tar.gz: d617b940e149d8bf53c76abb4de9b909d9b523d2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e76c85097fe61adae39b8a75f3c54eb7e180c1a5cd70b7a5f524e98c5ba4937a368484bf9961ef5c4b21c188c758b2aa60d1c3d584c3de8756ab220c79476287
|
7
|
+
data.tar.gz: ec4870278c994987b1a1cca2fd38d4701ebde414db8cbe1f67ec3cf6da66d8f6fa77fe29ea9ac79d0b1273b839288bd8384ee3da25d3dedaf0b93884b354a148
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Blake Chambers
|
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,50 @@
|
|
1
|
+
# InheritableAccessors
|
2
|
+
|
3
|
+
**Development status: Currently this is under active development, and should not be used until this section is removed from the readme.**
|
4
|
+
|
5
|
+
Easily and consistently inherit attributes and configurations. This is particularly designed to work well with Rspec, which creates new inherited classes during each context. More examples of usage coming soon.
|
6
|
+
|
7
|
+
## Planned features
|
8
|
+
|
9
|
+
- inheritable\_hash
|
10
|
+
- [x] support addition
|
11
|
+
- [ ] support delete/clear/reject
|
12
|
+
- inheritable\_set
|
13
|
+
- [ ] support addition
|
14
|
+
- [ ] support deletion
|
15
|
+
- [x] concerns that create an inheritable\_hash\_accessor will setup inheritance from class to class automatically
|
16
|
+
- [x] instance inherits from class hash
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem 'inheritable_accessors'
|
24
|
+
```
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
|
28
|
+
$ bundle
|
29
|
+
|
30
|
+
Or install it yourself as:
|
31
|
+
|
32
|
+
$ gem install inheritable_accessors
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
see [specs](https://github.com/blakechambers/inheritable-accessors/blob/master/spec/inheritable_accessors_spec.rb).
|
37
|
+
|
38
|
+
## Development
|
39
|
+
|
40
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
41
|
+
|
42
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
1. Fork it ( https://github.com/[my-github-username]/inheritable-accessors/fork )
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "inheritable/accessors"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'inheritable_accessors/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "inheritable_accessors"
|
8
|
+
spec.version = InheritableAccessors::VERSION
|
9
|
+
spec.authors = ["Blake Chambers"]
|
10
|
+
spec.email = ["chambb1@gmail.com"]
|
11
|
+
|
12
|
+
# if spec.respond_to?(:metadata)
|
13
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
|
14
|
+
# end
|
15
|
+
|
16
|
+
spec.summary = %q{inheritable accessors}
|
17
|
+
spec.description = %q{inheritable accessors}
|
18
|
+
spec.homepage = "http://github.com/blakechambers/inheritable_accessors"
|
19
|
+
spec.license = "MIT"
|
20
|
+
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "activesupport", ">= 3.2.0"
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module InheritableAccessors
|
4
|
+
class InheritableHash < Hash
|
5
|
+
attr_accessor :__local_values__
|
6
|
+
attr_reader :__parent__
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
WRITE_METHODS = [
|
10
|
+
:[]=,
|
11
|
+
:initialize,
|
12
|
+
:merge!,
|
13
|
+
:store
|
14
|
+
]
|
15
|
+
|
16
|
+
READ_METHODS = [
|
17
|
+
:==,
|
18
|
+
:[],
|
19
|
+
:[],
|
20
|
+
:each,
|
21
|
+
:each,
|
22
|
+
:each_pair,
|
23
|
+
:each_pair,
|
24
|
+
:each_value,
|
25
|
+
:empty?,
|
26
|
+
:eql?,
|
27
|
+
:fetch,
|
28
|
+
:flatten,
|
29
|
+
:has_key?,
|
30
|
+
:has_value?,
|
31
|
+
:hash,
|
32
|
+
:include?,
|
33
|
+
:index,
|
34
|
+
:inspect,
|
35
|
+
:inspect,
|
36
|
+
:invert,
|
37
|
+
:key,
|
38
|
+
:key?,
|
39
|
+
:keys,
|
40
|
+
:length,
|
41
|
+
:member?,
|
42
|
+
:merge,
|
43
|
+
:pretty_print,
|
44
|
+
:rehash,
|
45
|
+
:select,
|
46
|
+
:size,
|
47
|
+
:to_a,
|
48
|
+
:to_h,
|
49
|
+
:to_s,
|
50
|
+
:value?,
|
51
|
+
:values
|
52
|
+
]
|
53
|
+
|
54
|
+
def_delegators :@__local_values__, *WRITE_METHODS
|
55
|
+
delegate READ_METHODS => :to_hash
|
56
|
+
|
57
|
+
def initialize(prototype=nil)
|
58
|
+
@__local_values__ = Hash.new
|
59
|
+
@__parent__ = prototype
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_hash
|
63
|
+
if !!__parent__
|
64
|
+
__parent__.to_hash.merge(__local_values__)
|
65
|
+
else
|
66
|
+
__local_values__.clone
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def inherit_copy
|
71
|
+
InheritableHash.new(self)
|
72
|
+
end
|
73
|
+
|
74
|
+
alias :initialize_copy :inherit_copy
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module InheritableAccessors
|
2
|
+
module InheritableHashAccessor
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def inheritable_hash_accessor(name)
|
7
|
+
name = name.to_s
|
8
|
+
|
9
|
+
module_eval <<-METHODS
|
10
|
+
def self.inheritable_hash?
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.#{name}
|
15
|
+
@__#{name}__ ||= begin
|
16
|
+
if superclass.respond_to?(:inheritable_hash?)
|
17
|
+
superclass.#{name}.inherit_copy
|
18
|
+
else
|
19
|
+
::InheritableAccessors::InheritableHash.new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def #{name}
|
25
|
+
@__#{name}__ ||= self.class.#{name}.inherit_copy
|
26
|
+
end
|
27
|
+
METHODS
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require "active_support/concern"
|
2
|
+
require "inheritable_accessors/version"
|
3
|
+
require "inheritable_accessors/inheritable_hash"
|
4
|
+
require "inheritable_accessors/inheritable_hash_accessor"
|
5
|
+
|
6
|
+
module InheritableAccessors
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
# include InheritableHashAccessor
|
9
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inheritable_accessors
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Blake Chambers
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.8'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
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.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: inheritable accessors
|
70
|
+
email:
|
71
|
+
- chambb1@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- inheritable_accessors.gemspec
|
87
|
+
- lib/inheritable_accessors.rb
|
88
|
+
- lib/inheritable_accessors/inheritable_hash.rb
|
89
|
+
- lib/inheritable_accessors/inheritable_hash_accessor.rb
|
90
|
+
- lib/inheritable_accessors/version.rb
|
91
|
+
homepage: http://github.com/blakechambers/inheritable_accessors
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.4.6
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: inheritable accessors
|
115
|
+
test_files: []
|