concerned_inheritance 0.0.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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,40 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="FacetManager">
4
+ <facet type="gem" name="Gem">
5
+ <configuration>
6
+ <option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
7
+ <option name="GEM_APP_TEST_PATH" value="" />
8
+ <option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/lib" />
9
+ </configuration>
10
+ </facet>
11
+ </component>
12
+ <component name="NewModuleRootManager">
13
+ <content url="file://$MODULE_DIR$" />
14
+ <orderEntry type="inheritedJdk" />
15
+ <orderEntry type="sourceFolder" forTests="false" />
16
+ <orderEntry type="library" scope="PROVIDED" name="activesupport (v@6581d7, rbenv: 1.9.3-p362) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v1.2.3, rbenv: 1.9.3-p362) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="coderay (v1.0.8, rbenv: 1.9.3-p362) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.1.3, rbenv: 1.9.3-p362) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="guard (v1.6.1, rbenv: 1.9.3-p362) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="guard-rspec (v2.3.3, rbenv: 1.9.3-p362) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="i18n (v0.6.1, rbenv: 1.9.3-p362) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="listen (v0.7.2, rbenv: 1.9.3-p362) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="lumberjack (v1.0.2, rbenv: 1.9.3-p362) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="method_source (v0.8.1, rbenv: 1.9.3-p362) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="multi_json (v1.5.0, rbenv: 1.9.3-p362) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="pry (v0.9.10, rbenv: 1.9.3-p362) [gem]" level="application" />
28
+ <orderEntry type="library" scope="PROVIDED" name="rb-fsevent (v0.9.3, rbenv: 1.9.3-p362) [gem]" level="application" />
29
+ <orderEntry type="library" scope="PROVIDED" name="rspec (v2.12.0, rbenv: 1.9.3-p362) [gem]" level="application" />
30
+ <orderEntry type="library" scope="PROVIDED" name="rspec-core (v2.12.2, rbenv: 1.9.3-p362) [gem]" level="application" />
31
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v2.12.1, rbenv: 1.9.3-p362) [gem]" level="application" />
32
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v2.12.1, rbenv: 1.9.3-p362) [gem]" level="application" />
33
+ <orderEntry type="library" scope="PROVIDED" name="simplecov (v0.7.1, rbenv: 1.9.3-p362) [gem]" level="application" />
34
+ <orderEntry type="library" scope="PROVIDED" name="simplecov-html (v0.7.1, rbenv: 1.9.3-p362) [gem]" level="application" />
35
+ <orderEntry type="library" scope="PROVIDED" name="slop (v3.3.3, rbenv: 1.9.3-p362) [gem]" level="application" />
36
+ <orderEntry type="library" scope="PROVIDED" name="terminal-notifier-guard (v1.5.3, rbenv: 1.9.3-p362) [gem]" level="application" />
37
+ <orderEntry type="library" scope="PROVIDED" name="thor (v0.16.0, rbenv: 1.9.3-p362) [gem]" level="application" />
38
+ </component>
39
+ </module>
40
+
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
4
+ </project>
5
+
data/.idea/misc.xml ADDED
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="rbenv: 1.9.3-p362" project-jdk-type="RUBY_SDK" />
4
+ </project>
5
+
data/.idea/modules.xml ADDED
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/concerned_inheritance.iml" filepath="$PROJECT_DIR$/.idea/concerned_inheritance.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
9
+
@@ -0,0 +1,5 @@
1
+ <component name="DependencyValidationManager">
2
+ <state>
3
+ <option name="SKIP_IMPORT_STATEMENTS" value="false" />
4
+ </state>
5
+ </component>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
7
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in concerned_inheritance.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # ConcernedInheritance
2
+
3
+ ConcernedInheritance, allows you to place inheritance callbacks within your concerns.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'concerned_inheritance'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install concerned_inheritance
18
+
19
+ ## Usage
20
+
21
+ To use concerned inheritance, just include it in your class or module. Any callbacks defined in modules will only get run if the parent class is also extended.
22
+
23
+ ```ruby
24
+
25
+ class MyClass
26
+ include ConcernedInheritance
27
+
28
+ inherited do
29
+ puts "#{self} was inherited from #{baseclass}
30
+ end
31
+
32
+ end
33
+
34
+ module MyModule
35
+ include ConcernedInheritance
36
+
37
+ inherited do
38
+ puts "#{self} was inherited from #{baseclass}
39
+ end
40
+
41
+ end
42
+
43
+ ```
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'concerned_inheritance/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "concerned_inheritance"
8
+ gem.version = ConcernedInheritance::VERSION
9
+ gem.authors = ["Jason Waldrip"]
10
+ gem.email = ["jason@waldrip.net"]
11
+ gem.description = %q{Place inheritance callbacks within your concerns.}
12
+ gem.summary = %q{ConcernedInheritance, allows you to place inheritance callbacks within your concerns.}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'activesupport'
21
+
22
+ gem.add_development_dependency 'guard-rspec'
23
+ gem.add_development_dependency 'rb-fsevent'
24
+ gem.add_development_dependency 'rspec'
25
+ gem.add_development_dependency 'simplecov'
26
+ gem.add_development_dependency 'terminal-notifier-guard'
27
+
28
+ end
@@ -0,0 +1,3 @@
1
+ module ConcernedInheritance
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ require 'active_support/concern'
2
+ require 'active_support/core_ext/class/attribute'
3
+ require 'active_support/dependencies/autoload'
4
+
5
+ module ConcernedInheritance
6
+ extend ActiveSupport::Autoload
7
+
8
+ autoload :Delegator
9
+ autoload :ClassMethods
10
+ autoload :ModuleMethods
11
+
12
+ def self.extended(base)
13
+ case base
14
+ when Class
15
+ base.extend ClassMethods
16
+ when Module
17
+ base.extend ModuleMethods
18
+ end
19
+ base.instance_variable_set :@inherited_callbacks, [] unless base.instance_variable_defined? :@inherited_callbacks
20
+ end
21
+
22
+ def define_inherited_callback(&block)
23
+ raise ArgumentError, 'missing required block' unless block_given?
24
+ @inherited_callbacks += [block]
25
+ end
26
+
27
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+ require 'concerned_inheritance'
3
+
4
+ describe ConcernedInheritance::ClassMethods do
5
+
6
+ let(:klass) do
7
+ Class.new do
8
+ extend ConcernedInheritance
9
+ end
10
+ end
11
+
12
+ describe '.inherited' do
13
+
14
+ context 'with a subclass' do
15
+ it 'should call run inherited callbacks' do
16
+ mock_subclass = mock
17
+ klass.should_receive(:run_inherited_callbacks).with(mock_subclass)
18
+ klass.send :inherited, mock_subclass
19
+ end
20
+ end
21
+
22
+ context 'with a block' do
23
+ it 'should call define_inherited_callback' do
24
+ block = Proc.new { }
25
+ klass.should_receive(:define_inherited_callback).with(&block)
26
+ klass.send :inherited, &block
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ describe '.inherited_callbacks' do
33
+ it 'should call off to its ancestors' do
34
+ mock_ancestor = mock
35
+ mock_callback = proc { "Bar" }
36
+ mock_ancestor.instance_variable_set :@inherited_callbacks, [mock_callback]
37
+ klass.singleton_class.stub(:ancestors).and_return([mock_ancestor])
38
+ klass.stub(:ancestors).and_return([mock_ancestor])
39
+ klass.inherited_callbacks.size.should > 0
40
+ klass.inherited_callbacks.each do |callback|
41
+ callback.should == mock_callback
42
+ end
43
+ end
44
+ end
45
+
46
+ describe '.run_inherited_callbacks' do
47
+ it 'should initialize an InheritanceDelegator' do
48
+ mock_subclass = mock
49
+ mock_callback = proc { }
50
+ ConcernedInheritance::Delegator.should_receive(:new).with(klass, mock_subclass, mock_callback)
51
+ klass.send :define_inherited_callback, &mock_callback
52
+ klass.send :run_inherited_callbacks, mock_subclass
53
+ end
54
+ end
55
+
56
+ end
57
+
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+ require 'concerned_inheritance'
3
+
4
+ describe ConcernedInheritance::Delegator do
5
+
6
+ let(:baseclass) { Class.new }
7
+ let(:subclass) { Class.new }
8
+
9
+ describe '.new' do
10
+ context 'given a proc with no arity' do
11
+ let(:callback) do
12
+ proc { 'foo' }
13
+ end
14
+ it "should should call a subclass' instance method" do
15
+ expect { ConcernedInheritance::Delegator.new(baseclass, subclass, callback) }.to_not raise_error ArgumentError
16
+ end
17
+
18
+ it 'should instance_eval the callback' do
19
+ callback = proc { foo }
20
+ subclass.should_receive(:foo)
21
+ ConcernedInheritance::Delegator.new(baseclass, subclass, callback)
22
+ end
23
+ end
24
+
25
+ context 'given a proc with arity' do
26
+ let(:callback) do
27
+ proc { |foo| foo }
28
+ end
29
+ it 'should raise an error' do
30
+ expect { ConcernedInheritance::Delegator.new(baseclass, subclass, callback) }.to raise_error ArgumentError
31
+ end
32
+ end
33
+
34
+ context 'when not given a proc' do
35
+ it 'should raise an error' do
36
+ expect { ConcernedInheritance::Delegator.new(baseclass, subclass, Object.new) }.to raise_error ArgumentError
37
+ end
38
+ end
39
+ end
40
+
41
+ describe '#method_missing' do
42
+ let(:callback) { proc { } }
43
+ it 'should call a method on the subclass' do
44
+ block = proc { }
45
+ subclass.should_receive(:foo).with('bar', 'baz', &block)
46
+ delegator = ConcernedInheritance::Delegator.new(baseclass, subclass, callback)
47
+ delegator.foo 'bar', 'baz', &block
48
+ end
49
+ end
50
+
51
+ end
52
+
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'concerned_inheritance'
3
+
4
+ describe ConcernedInheritance::ModuleMethods do
5
+ let(:the_module) do
6
+ Module.new do
7
+ extend ConcernedInheritance
8
+ end
9
+ end
10
+
11
+ describe '.define_inherited_callback' do
12
+ it 'should include the callback' do
13
+ block = Proc.new { }
14
+ the_module.send :define_inherited_callback, &block
15
+ the_module.inherited_callbacks.should include block
16
+ end
17
+ end
18
+
19
+ describe '.inherited' do
20
+ it 'should call define_inherited_callback' do
21
+ block = Proc.new { }
22
+ the_module.should_receive(:define_inherited_callback).with(&block)
23
+ the_module.send :inherited, &block
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+ require 'concerned_inheritance'
3
+
4
+ describe ConcernedInheritance do
5
+
6
+ let(:klass) do
7
+ Class.new do
8
+ extend ConcernedInheritance
9
+ end
10
+ end
11
+
12
+ describe '.extended' do
13
+ context 'on a module' do
14
+ it 'should extend ModuleMethods' do
15
+ Module.new.extend(ConcernedInheritance).singleton_class.ancestors.should include ConcernedInheritance::ModuleMethods
16
+ end
17
+ end
18
+
19
+ context 'on a class' do
20
+ it 'should extend ClassMethods' do
21
+ Class.new.extend(ConcernedInheritance).singleton_class.ancestors.should include ConcernedInheritance::ClassMethods
22
+ end
23
+ end
24
+ end
25
+
26
+ describe '.define_inherited_callback' do
27
+ it 'should include the callback' do
28
+ block = Proc.new { }
29
+ klass.send :define_inherited_callback, &block
30
+ klass.instance_variable_get(:@inherited_callbacks).should include block
31
+ end
32
+ end
33
+
34
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: concerned_inheritance
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jason Waldrip
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: guard-rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rb-fsevent
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: terminal-notifier-guard
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Place inheritance callbacks within your concerns.
111
+ email:
112
+ - jason@waldrip.net
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - .idea/concerned_inheritance.iml
119
+ - .idea/encodings.xml
120
+ - .idea/misc.xml
121
+ - .idea/modules.xml
122
+ - .idea/scopes/scope_settings.xml
123
+ - .idea/vcs.xml
124
+ - Gemfile
125
+ - LICENSE.txt
126
+ - README.md
127
+ - Rakefile
128
+ - concerned_inheritance.gemspec
129
+ - lib/concerned_inheritance.rb
130
+ - lib/concerned_inheritance/version.rb
131
+ - spec/concerned_inheritance/class_methods_spec.rb
132
+ - spec/concerned_inheritance/delegator_spec.rb
133
+ - spec/concerned_inheritance/module_methods_spec.rb
134
+ - spec/concerned_inheritance_spec.rb
135
+ homepage: ''
136
+ licenses: []
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ! '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 1.8.23
156
+ signing_key:
157
+ specification_version: 3
158
+ summary: ConcernedInheritance, allows you to place inheritance callbacks within your
159
+ concerns.
160
+ test_files:
161
+ - spec/concerned_inheritance/class_methods_spec.rb
162
+ - spec/concerned_inheritance/delegator_spec.rb
163
+ - spec/concerned_inheritance/module_methods_spec.rb
164
+ - spec/concerned_inheritance_spec.rb