inheritable_accessors 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 81cf6392088186618510983ee2e096465eb347d5
4
- data.tar.gz: d617b940e149d8bf53c76abb4de9b909d9b523d2
3
+ metadata.gz: 8d2efb20dc919b54c78e3c2bec2b2d4a50c14606
4
+ data.tar.gz: ed4f8a39aee354cd65a3d3d4e2e20e7bdca79871
5
5
  SHA512:
6
- metadata.gz: e76c85097fe61adae39b8a75f3c54eb7e180c1a5cd70b7a5f524e98c5ba4937a368484bf9961ef5c4b21c188c758b2aa60d1c3d584c3de8756ab220c79476287
7
- data.tar.gz: ec4870278c994987b1a1cca2fd38d4701ebde414db8cbe1f67ec3cf6da66d8f6fa77fe29ea9ac79d0b1273b839288bd8384ee3da25d3dedaf0b93884b354a148
6
+ metadata.gz: 59e264c5d8bcdcc8e6031ef4f4fdb193517bd94baeeefef5f99102ed0d1fb15e7c2c4edb3a239e941adb91f46fb8c5e4c59c9a1c4fd6c4542bca294570ec6b73
7
+ data.tar.gz: 5e7a73237ebc94c62073b9ead680008c4edceacf00cf7eb36678d61bd2327d75e57c15d9cc14c556d98c3e816d72453c14d6378b3293a64eac2c3f2b1696f631
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # InheritableAccessors
2
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
3
  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
4
 
7
5
  ## Planned features
@@ -10,10 +8,8 @@ Easily and consistently inherit attributes and configurations. This is particul
10
8
  - [x] support addition
11
9
  - [ ] support delete/clear/reject
12
10
  - inheritable\_set
13
- - [ ] support addition
11
+ - [x] support addition
14
12
  - [ ] 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
13
 
18
14
  ## Installation
19
15
 
@@ -35,15 +31,9 @@ Or install it yourself as:
35
31
 
36
32
  see [specs](https://github.com/blakechambers/inheritable-accessors/blob/master/spec/inheritable_accessors_spec.rb).
37
33
 
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
34
  ## Contributing
45
35
 
46
- 1. Fork it ( https://github.com/[my-github-username]/inheritable-accessors/fork )
36
+ 1. Fork it ( https://github.com/blakechambers/inheritable-accessors/fork )
47
37
  2. Create your feature branch (`git checkout -b my-new-feature`)
48
38
  3. Commit your changes (`git commit -am 'Add some feature'`)
49
39
  4. Push to the branch (`git push origin my-new-feature`)
@@ -1,55 +1,20 @@
1
1
  require 'forwardable'
2
2
 
3
3
  module InheritableAccessors
4
- class InheritableHash < Hash
4
+ class InheritableHash
5
5
  attr_accessor :__local_values__
6
6
  attr_reader :__parent__
7
7
  extend Forwardable
8
8
 
9
- WRITE_METHODS = [
10
- :[]=,
11
- :initialize,
12
- :merge!,
13
- :store
14
- ]
9
+ WRITE_METHODS = %w{
10
+ []= initialize merge! store
11
+ }
15
12
 
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
- ]
13
+ READ_METHODS = %w{
14
+ == [] each each_pair each_value empty? eql? fetch flatten
15
+ has_key? has_value? hash include? index inspect invert key key? keys
16
+ length member? merge pretty_print rehash select size to_a to_h to_s
17
+ value? values }
53
18
 
54
19
  def_delegators :@__local_values__, *WRITE_METHODS
55
20
  delegate READ_METHODS => :to_hash
@@ -0,0 +1,46 @@
1
+ require 'set'
2
+
3
+ module InheritableAccessors
4
+ class InheritableSet
5
+ attr_accessor :__local_values__
6
+ attr_reader :__parent__
7
+ extend Forwardable
8
+
9
+ WRITE_METHODS = %w{
10
+ << add add? merge
11
+ }
12
+
13
+ REMOVE_METHODS = %w{
14
+ clear delete delete? delete_if keep_if reject! replace select!
15
+ }
16
+
17
+ READ_METHODS = %w{
18
+ & - < <= == > >= [] ^ classify difference disjoint? each empty? flatten
19
+ include? inspect intersect? intersection length new proper_subset?
20
+ proper_superset? size subset? subtract superset? to_a |
21
+ }
22
+
23
+ def_delegators :@__local_values__, *WRITE_METHODS
24
+ delegate READ_METHODS => :to_set
25
+
26
+ def initialize(prototype=nil)
27
+ @__local_values__ = Set.new
28
+ @__parent__ = prototype
29
+ end
30
+
31
+ def to_set
32
+ if !!__parent__
33
+ __parent__.to_set | __local_values__
34
+ else
35
+ __local_values__.clone
36
+ end
37
+ end
38
+
39
+ def inherit_copy
40
+ InheritableSet.new(self)
41
+ end
42
+
43
+ alias :initialize_clone :inherit_copy
44
+ alias :initialize_dup :inherit_copy
45
+ end
46
+ end
@@ -0,0 +1,32 @@
1
+ module InheritableAccessors
2
+ module InheritableSetAccessor
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ def inheritable_set_accessor(name)
7
+ name = name.to_s
8
+
9
+ module_eval <<-METHODS
10
+ def self.inheritable_set?
11
+ true
12
+ end
13
+
14
+ def self.#{name}
15
+ @__#{name}__ ||= begin
16
+ if superclass.respond_to?(:inheritable_set?)
17
+ superclass.#{name}.inherit_copy
18
+ else
19
+ ::InheritableAccessors::InheritableSet.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
@@ -1,3 +1,3 @@
1
1
  module InheritableAccessors
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -2,8 +2,11 @@ require "active_support/concern"
2
2
  require "inheritable_accessors/version"
3
3
  require "inheritable_accessors/inheritable_hash"
4
4
  require "inheritable_accessors/inheritable_hash_accessor"
5
+ require "inheritable_accessors/inheritable_set"
6
+ require "inheritable_accessors/inheritable_set_accessor"
5
7
 
6
8
  module InheritableAccessors
7
9
  extend ActiveSupport::Concern
8
10
  # include InheritableHashAccessor
11
+ # include InheritableSetAccessor
9
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inheritable_accessors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Chambers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-03-10 00:00:00.000000000 Z
11
+ date: 2015-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -87,6 +87,8 @@ files:
87
87
  - lib/inheritable_accessors.rb
88
88
  - lib/inheritable_accessors/inheritable_hash.rb
89
89
  - lib/inheritable_accessors/inheritable_hash_accessor.rb
90
+ - lib/inheritable_accessors/inheritable_set.rb
91
+ - lib/inheritable_accessors/inheritable_set_accessor.rb
90
92
  - lib/inheritable_accessors/version.rb
91
93
  homepage: http://github.com/blakechambers/inheritable_accessors
92
94
  licenses: