concerned_inheritance 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+
19
+ /.idea/workspace.xml
@@ -0,0 +1 @@
1
+ concerned_inheritance
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build concerned_inheritance-0.0.1.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Build and install concerned_inheritance-0.0.1.gem into system gems" fullCmd="install" taksId="install" /><RakeTask description="Create tag v0.0.1 and build and push concerned_inheritance-0.0.1.gem to Rubygems" fullCmd="release" taksId="release" /></RakeGroup></Settings>
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
4
+ - jruby-19mode
5
+ script: bundle exec rspec
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/jwaldrip/concerned_inheritance.png?branch=master)](https://travis-ci.org/jwaldrip/concerned_inheritance)
2
+
1
3
  # ConcernedInheritance
2
4
 
3
5
  ConcernedInheritance, allows you to place inheritance callbacks within your concerns.
@@ -26,7 +28,7 @@ class MyClass
26
28
  include ConcernedInheritance
27
29
 
28
30
  inherited do
29
- puts "#{self} was inherited from #{baseclass}
31
+ puts "#{self} was inherited from #{baseclass}"
30
32
  end
31
33
 
32
34
  end
@@ -35,7 +37,7 @@ module MyModule
35
37
  include ConcernedInheritance
36
38
 
37
39
  inherited do
38
- puts "#{self} was inherited from #{baseclass}
40
+ puts "#{self} was inherited from #{baseclass}"
39
41
  end
40
42
 
41
43
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["jason@waldrip.net"]
11
11
  gem.description = %q{Place inheritance callbacks within your concerns.}
12
12
  gem.summary = %q{ConcernedInheritance, allows you to place inheritance callbacks within your concerns.}
13
- gem.homepage = ""
13
+ gem.homepage = "https://github.com/jwaldrip/concerned_inheritance"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -0,0 +1,28 @@
1
+ module ConcernedInheritance::ClassMethods
2
+
3
+ def inherited_callbacks
4
+ (self.singleton_class.ancestors + self.ancestors).select do |ancestor|
5
+ ancestor.instance_variable_defined? :@inherited_callbacks
6
+ end.map do |ancestor|
7
+ ancestor.instance_variable_get :@inherited_callbacks
8
+ end.flatten
9
+ end
10
+
11
+ private
12
+
13
+ def inherited(subclass=nil, &block)
14
+ if subclass.nil?
15
+ define_inherited_callback(&block)
16
+ else
17
+ run_inherited_callbacks(subclass)
18
+ super(subclass)
19
+ end
20
+ end
21
+
22
+ def run_inherited_callbacks(subclass)
23
+ self.inherited_callbacks.each do |callback|
24
+ ConcernedInheritance::Delegator.new(self, subclass, callback)
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,21 @@
1
+ class ConcernedInheritance::Delegator < BasicObject
2
+
3
+ attr_reader :baseclass, :subclass
4
+
5
+ def initialize(baseclass, subclass, callback)
6
+ @baseclass = baseclass
7
+ @subclass = subclass
8
+ if !callback.is_a?(::Proc)
9
+ raise ::ArgumentError, "#{callback} must be a proc"
10
+ elsif (-1..0).cover?(callback.arity)
11
+ instance_eval(&callback)
12
+ else
13
+ raise ::ArgumentError, "#{callback} must have an arity of 0, got #{callback.arity}"
14
+ end
15
+ end
16
+
17
+ def method_missing(m, *args, &block)
18
+ subclass.send m, *args, &block
19
+ end
20
+
21
+ end
@@ -0,0 +1,11 @@
1
+ module ConcernedInheritance::ModuleMethods
2
+
3
+ def inherited_callbacks
4
+ @inherited_callbacks
5
+ end
6
+
7
+ def inherited(&block)
8
+ define_inherited_callback(&block)
9
+ end
10
+
11
+ end
@@ -1,3 +1,3 @@
1
1
  module ConcernedInheritance
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: concerned_inheritance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -115,24 +115,33 @@ extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
117
  - .gitignore
118
+ - .idea/.name
119
+ - .idea/.rakeTasks
118
120
  - .idea/concerned_inheritance.iml
119
121
  - .idea/encodings.xml
120
122
  - .idea/misc.xml
121
123
  - .idea/modules.xml
122
124
  - .idea/scopes/scope_settings.xml
123
125
  - .idea/vcs.xml
126
+ - .rspec
127
+ - .travis.yml
124
128
  - Gemfile
129
+ - Guardfile
125
130
  - LICENSE.txt
126
131
  - README.md
127
132
  - Rakefile
128
133
  - concerned_inheritance.gemspec
129
134
  - lib/concerned_inheritance.rb
135
+ - lib/concerned_inheritance/class_methods.rb
136
+ - lib/concerned_inheritance/delegator.rb
137
+ - lib/concerned_inheritance/module_methods.rb
130
138
  - lib/concerned_inheritance/version.rb
131
139
  - spec/concerned_inheritance/class_methods_spec.rb
132
140
  - spec/concerned_inheritance/delegator_spec.rb
133
141
  - spec/concerned_inheritance/module_methods_spec.rb
134
142
  - spec/concerned_inheritance_spec.rb
135
- homepage: ''
143
+ - spec/spec_helper.rb
144
+ homepage: https://github.com/jwaldrip/concerned_inheritance
136
145
  licenses: []
137
146
  post_install_message:
138
147
  rdoc_options: []
@@ -162,3 +171,4 @@ test_files:
162
171
  - spec/concerned_inheritance/delegator_spec.rb
163
172
  - spec/concerned_inheritance/module_methods_spec.rb
164
173
  - spec/concerned_inheritance_spec.rb
174
+ - spec/spec_helper.rb