hassox-pancake 0.1.6

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.
Files changed (125) hide show
  1. data/LICENSE +20 -0
  2. data/README.textile +95 -0
  3. data/Rakefile +56 -0
  4. data/TODO +18 -0
  5. data/bin/jeweler +19 -0
  6. data/bin/pancake-gen +17 -0
  7. data/bin/rubyforge +19 -0
  8. data/lib/pancake.rb +48 -0
  9. data/lib/pancake/bootloaders.rb +180 -0
  10. data/lib/pancake/configuration.rb +140 -0
  11. data/lib/pancake/core_ext/class.rb +44 -0
  12. data/lib/pancake/core_ext/object.rb +22 -0
  13. data/lib/pancake/core_ext/symbol.rb +15 -0
  14. data/lib/pancake/errors.rb +61 -0
  15. data/lib/pancake/generators.rb +8 -0
  16. data/lib/pancake/generators/base.rb +12 -0
  17. data/lib/pancake/generators/flat_generator.rb +17 -0
  18. data/lib/pancake/generators/short_generator.rb +17 -0
  19. data/lib/pancake/generators/stack_generator.rb +17 -0
  20. data/lib/pancake/generators/templates/common/dotgitignore +22 -0
  21. data/lib/pancake/generators/templates/common/dothtaccess +17 -0
  22. data/lib/pancake/generators/templates/flat/%stack_name%/%stack_name%.rb.tt +8 -0
  23. data/lib/pancake/generators/templates/flat/%stack_name%/.gitignore +21 -0
  24. data/lib/pancake/generators/templates/flat/%stack_name%/config.ru.tt +12 -0
  25. data/lib/pancake/generators/templates/flat/%stack_name%/pancake.init.tt +1 -0
  26. data/lib/pancake/generators/templates/flat/%stack_name%/public/.empty_directory +0 -0
  27. data/lib/pancake/generators/templates/flat/%stack_name%/tmp/.empty_directory +0 -0
  28. data/lib/pancake/generators/templates/short/%stack_name%/.gitignore +21 -0
  29. data/lib/pancake/generators/templates/short/%stack_name%/LICENSE.tt +20 -0
  30. data/lib/pancake/generators/templates/short/%stack_name%/README.tt +7 -0
  31. data/lib/pancake/generators/templates/short/%stack_name%/Rakefile.tt +48 -0
  32. data/lib/pancake/generators/templates/short/%stack_name%/VERSION.tt +1 -0
  33. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%.rb.tt +5 -0
  34. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/%stack_name%.rb.tt +6 -0
  35. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/config.ru.tt +12 -0
  36. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/gems/cache/.empty_directory +0 -0
  37. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/mounts/.empty_directory +0 -0
  38. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/public/.empty_directory +0 -0
  39. data/lib/pancake/generators/templates/short/%stack_name%/lib/%stack_name%/tmp/.empty_directory +0 -0
  40. data/lib/pancake/generators/templates/short/%stack_name%/pancake.init.tt +1 -0
  41. data/lib/pancake/generators/templates/short/%stack_name%/spec/%stack_name%_spec.rb.tt +7 -0
  42. data/lib/pancake/generators/templates/short/%stack_name%/spec/spec_helper.rb.tt +9 -0
  43. data/lib/pancake/generators/templates/stack/%stack_name%/.gitignore +21 -0
  44. data/lib/pancake/generators/templates/stack/%stack_name%/LICENSE.tt +20 -0
  45. data/lib/pancake/generators/templates/stack/%stack_name%/README.tt +7 -0
  46. data/lib/pancake/generators/templates/stack/%stack_name%/Rakefile.tt +48 -0
  47. data/lib/pancake/generators/templates/stack/%stack_name%/VERSION.tt +1 -0
  48. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%.rb.tt +3 -0
  49. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/config.ru.tt +12 -0
  50. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/config/environments/development.rb.tt +18 -0
  51. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/config/environments/production.rb.tt +18 -0
  52. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/config/router.rb.tt +6 -0
  53. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/gems/cache/.empty_directory +0 -0
  54. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/mounts/.empty_directory +0 -0
  55. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/public/.empty_directory +0 -0
  56. data/lib/pancake/generators/templates/stack/%stack_name%/lib/%stack_name%/tmp/.empty_directory +0 -0
  57. data/lib/pancake/generators/templates/stack/%stack_name%/pancake.init.tt +1 -0
  58. data/lib/pancake/generators/templates/stack/%stack_name%/spec/%stack_name%_spec.rb.tt +7 -0
  59. data/lib/pancake/generators/templates/stack/%stack_name%/spec/spec_helper.rb.tt +9 -0
  60. data/lib/pancake/hooks/inheritable_inner_classes.rb +60 -0
  61. data/lib/pancake/hooks/on_inherit.rb +34 -0
  62. data/lib/pancake/master.rb +87 -0
  63. data/lib/pancake/middleware.rb +354 -0
  64. data/lib/pancake/mime_types.rb +265 -0
  65. data/lib/pancake/mixins/publish.rb +125 -0
  66. data/lib/pancake/mixins/publish/action_options.rb +104 -0
  67. data/lib/pancake/mixins/render.rb +61 -0
  68. data/lib/pancake/mixins/request_helper.rb +92 -0
  69. data/lib/pancake/mixins/stack_helper.rb +44 -0
  70. data/lib/pancake/mixins/url.rb +10 -0
  71. data/lib/pancake/more/controller.rb +4 -0
  72. data/lib/pancake/more/controller/base.rb +34 -0
  73. data/lib/pancake/paths.rb +218 -0
  74. data/lib/pancake/router.rb +99 -0
  75. data/lib/pancake/stack/app.rb +10 -0
  76. data/lib/pancake/stack/bootloader.rb +79 -0
  77. data/lib/pancake/stack/configuration.rb +44 -0
  78. data/lib/pancake/stack/middleware.rb +0 -0
  79. data/lib/pancake/stack/router.rb +18 -0
  80. data/lib/pancake/stack/stack.rb +57 -0
  81. data/lib/pancake/stacks/short.rb +2 -0
  82. data/lib/pancake/stacks/short/controller.rb +105 -0
  83. data/lib/pancake/stacks/short/stack.rb +194 -0
  84. data/spec/helpers/helpers.rb +20 -0
  85. data/spec/helpers/matchers.rb +25 -0
  86. data/spec/pancake/bootloaders_spec.rb +109 -0
  87. data/spec/pancake/configuration_spec.rb +177 -0
  88. data/spec/pancake/fixtures/foo_stack/pancake.init +0 -0
  89. data/spec/pancake/fixtures/paths/controllers/controller1.rb +0 -0
  90. data/spec/pancake/fixtures/paths/controllers/controller2.rb +0 -0
  91. data/spec/pancake/fixtures/paths/controllers/controller3.rb +0 -0
  92. data/spec/pancake/fixtures/paths/models/model1.rb +0 -0
  93. data/spec/pancake/fixtures/paths/models/model2.rb +0 -0
  94. data/spec/pancake/fixtures/paths/models/model3.rb +0 -0
  95. data/spec/pancake/fixtures/paths/stack/controllers/controller1.rb +0 -0
  96. data/spec/pancake/fixtures/paths/stack/models/model3.rb +0 -0
  97. data/spec/pancake/fixtures/paths/stack/views/view1.erb +0 -0
  98. data/spec/pancake/fixtures/paths/stack/views/view1.rb +0 -0
  99. data/spec/pancake/fixtures/paths/stack/views/view2.erb +0 -0
  100. data/spec/pancake/fixtures/paths/stack/views/view2.haml +0 -0
  101. data/spec/pancake/fixtures/render_templates/context_template.html.erb +1 -0
  102. data/spec/pancake/fixtures/render_templates/erb_template.html.erb +1 -0
  103. data/spec/pancake/fixtures/render_templates/erb_template.json.erb +1 -0
  104. data/spec/pancake/fixtures/render_templates/haml_template.html.haml +1 -0
  105. data/spec/pancake/fixtures/render_templates/haml_template.xml.haml +1 -0
  106. data/spec/pancake/hooks/on_inherit_spec.rb +65 -0
  107. data/spec/pancake/inheritance_spec.rb +100 -0
  108. data/spec/pancake/middleware_spec.rb +401 -0
  109. data/spec/pancake/mime_types_spec.rb +234 -0
  110. data/spec/pancake/mixins/publish_spec.rb +94 -0
  111. data/spec/pancake/mixins/render_spec.rb +55 -0
  112. data/spec/pancake/mixins/stack_helper_spec.rb +46 -0
  113. data/spec/pancake/pancake_spec.rb +31 -0
  114. data/spec/pancake/paths_spec.rb +210 -0
  115. data/spec/pancake/stack/app_spec.rb +28 -0
  116. data/spec/pancake/stack/bootloader_spec.rb +41 -0
  117. data/spec/pancake/stack/middleware_spec.rb +0 -0
  118. data/spec/pancake/stack/router_spec.rb +266 -0
  119. data/spec/pancake/stack/stack_configuration_spec.rb +101 -0
  120. data/spec/pancake/stack/stack_spec.rb +55 -0
  121. data/spec/pancake/stacks/short/controller_spec.rb +287 -0
  122. data/spec/pancake/stacks/short/router_spec.rb +132 -0
  123. data/spec/pancake/stacks/short/stack_spec.rb +40 -0
  124. data/spec/spec_helper.rb +21 -0
  125. metadata +238 -0
@@ -0,0 +1 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__), "<%= stack_name %>"))
@@ -0,0 +1,21 @@
1
+ .DS_Store
2
+ log/*
3
+ TAGS
4
+ *~
5
+ .#*
6
+ schema/schema.rb
7
+ schema/*_structure.sql
8
+ schema/*.sqlite3
9
+ schema/*.sqlite
10
+ schema/*.db
11
+ *.sqlite
12
+ *.sqlite3
13
+ *.db
14
+ src/*
15
+ .hgignore
16
+ .hg/*
17
+ .svn/*
18
+ gems/gems/*/
19
+ gems/specifications/*
20
+ !gems/gems/thor*/
21
+ !gems/specifications/thor*
@@ -0,0 +1,20 @@
1
+ Copyright (c) <%= Date.today.year %> <YOUR NAME HERE>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,7 @@
1
+ = <%= stack_name %>
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) <%= Date.today.year %> <YOUR NAME HERE>. See LICENSE for details.
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "<%= stack_name %>"
8
+ gem.summary = %Q{TODO}
9
+ gem.email = "TODO"
10
+ gem.homepage = "TODO"
11
+ gem.authors = ["TODO"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'spec/rake/spectask'
20
+ Spec::Rake::SpecTask.new(:spec) do |spec|
21
+ spec.libs << 'lib' << 'spec'
22
+ spec.spec_files = FileList['spec/**/*_spec.rb']
23
+ end
24
+
25
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.pattern = 'spec/**/*_spec.rb'
28
+ spec.rcov = true
29
+ end
30
+
31
+
32
+ task :default => :spec
33
+
34
+ require 'rake/rdoctask'
35
+ Rake::RDocTask.new do |rdoc|
36
+ if File.exist?('VERSION.yml')
37
+ config = YAML.load(File.read('VERSION.yml'))
38
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
39
+ else
40
+ version = ""
41
+ end
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "foo #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
48
+
@@ -0,0 +1,5 @@
1
+ class <%= stack_name.camel_case %> < Pancake::Stacks::Short
2
+ roots << ::File.expand_path(::File.join(Pancake.get_root(__FILE__), "<%= stack_name %>"))
3
+ end
4
+
5
+ require ::File.join(::File.expand_path(::File.dirname(__FILE__)), "<%= stack_name %>", "<%= stack_name %>")
@@ -0,0 +1,6 @@
1
+ class <%= stack_name.camel_case %>
2
+ get "/" do
3
+ "Welcome to Pancake!"
4
+ end
5
+ end
6
+
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+
3
+ require 'pancake'
4
+ require ::File.join(::File.expand_path(::File.dirname(__FILE__)), "..", "<%= stack_name %>")
5
+
6
+ # get the application to run. The applicadtion in the Pancake.start block
7
+ # is the master application. It will have all requests directed to it through the
8
+ # pancake middleware
9
+ # This should be a very minimal file, but should be used when any stand alone code needs to be included
10
+ app = Pancake.start(:root => Pancake.get_root(__FILE__)){ <%= stack_name.camel_case %>.stackup }
11
+
12
+ run app
@@ -0,0 +1 @@
1
+ require ::File.join(::File.expand_path(::File.dirname(__FILE__)), "lib", "<%= stack_name %>")
@@ -0,0 +1,7 @@
1
+ require ::File.expand_path(::File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "<%= stack_name %>" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require '<%= stack_name -%>'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
@@ -0,0 +1,21 @@
1
+ .DS_Store
2
+ log/*
3
+ TAGS
4
+ *~
5
+ .#*
6
+ schema/schema.rb
7
+ schema/*_structure.sql
8
+ schema/*.sqlite3
9
+ schema/*.sqlite
10
+ schema/*.db
11
+ *.sqlite
12
+ *.sqlite3
13
+ *.db
14
+ src/*
15
+ .hgignore
16
+ .hg/*
17
+ .svn/*
18
+ gems/gems/*/
19
+ gems/specifications/*
20
+ !gems/gems/thor*/
21
+ !gems/specifications/thor*
@@ -0,0 +1,20 @@
1
+ Copyright (c) <%= Date.today.year %> <YOUR NAME HERE>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,7 @@
1
+ = <%= stack_name %>
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) <%= Date.today.year %> <YOUR NAME HERE>. See LICENSE for details.
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "<%= stack_name %>"
8
+ gem.summary = %Q{TODO}
9
+ gem.email = "TODO"
10
+ gem.homepage = "TODO"
11
+ gem.authors = ["TODO"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'spec/rake/spectask'
20
+ Spec::Rake::SpecTask.new(:spec) do |spec|
21
+ spec.libs << 'lib' << 'spec'
22
+ spec.spec_files = FileList['spec/**/*_spec.rb']
23
+ end
24
+
25
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.pattern = 'spec/**/*_spec.rb'
28
+ spec.rcov = true
29
+ end
30
+
31
+
32
+ task :default => :spec
33
+
34
+ require 'rake/rdoctask'
35
+ Rake::RDocTask.new do |rdoc|
36
+ if File.exist?('VERSION.yml')
37
+ config = YAML.load(File.read('VERSION.yml'))
38
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
39
+ else
40
+ version = ""
41
+ end
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "foo #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
48
+
@@ -0,0 +1,3 @@
1
+ class <%= stack_name.camel_case %> < Pancake::Stack
2
+ roots << File.join(Pancake.get_root(__FILE__), "<%= stack_name %>")
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+
3
+ require 'pancake'
4
+ require ::File.join(::File.expand_path(::File.dirname(__FILE__)), "..", "<%= stack_name %>")
5
+
6
+ # get the application to run. The applicadtion in the Pancake.start block
7
+ # is the master application. It will have all requests directed to it through the
8
+ # pancake middleware
9
+ # This should be a very minimal file, but should be used when any stand alone code needs to be included
10
+ app = Pancake.start(:root => Pancake.get_root(__FILE__)){ <%= stack_name.camel_case %>.stackup }
11
+
12
+ run app
@@ -0,0 +1,18 @@
1
+ puts "Loading Development Environment"
2
+
3
+ # Get Access
4
+ Pancake.configuration.configs(<%= stack_name.camel_case %> ) do |config|
5
+ config.foo = :foo
6
+ end
7
+
8
+ # Allows Pancake to selectively apply middlewares in the stack.
9
+ # If a middleware is not declared with a specific stack label then it will always be loaded
10
+ # You can specify Middleware to be active under particular stack labels only however.
11
+ #
12
+ # Example
13
+ # <%= stack_name.camel_case %>.stack(:my_middlware, :labels => [:demo, :development]).use(Middlware, :with => :opts)
14
+ #
15
+ # This would only include the middleware Middlware in stacks with either the :demo, or :development label
16
+ #
17
+ # Setting The Pancake.stack_labels will use any relevant stacks
18
+ Pancake.stack_labels = [:development]
@@ -0,0 +1,18 @@
1
+ puts "Loading Production Environment"
2
+
3
+ # Get Access
4
+ Pancake.configuration.configs(<%= stack_name.camel_case %> ) do |config|
5
+ # config.foo = :foo
6
+ end
7
+
8
+ # Allows Pancake to selectively apply middlewares in the stack.
9
+ # If a middleware is not declared with a specific stack label then it will always be loaded
10
+ # You can specify Middleware to be active under particular stack labels only however.
11
+ #
12
+ # Example
13
+ # <%= stack_name.camel_case %>.stack(:my_middlware, :labels => [:demo, :development]).use(Middlware, :with => :opts)
14
+ #
15
+ # This would only include the middleware Middlware in stacks with either the :demo, or :development label
16
+ #
17
+ # Setting The Pancake.stack_labels will use any relevant stacks
18
+ Pancake.stack_labels = [:production]
@@ -0,0 +1,6 @@
1
+ <%= stack_name.camel_case %>.router do |r|
2
+ # Add your routes here
3
+ r.add("/") do |e|
4
+ Rack::Response.new("Hi From <%= stack_name.camel_case %>").finish
5
+ end
6
+ end
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), "lib", "<%= stack_name %>")
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "<%= stack_name %>" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require '<%= stack_name -%>'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
@@ -0,0 +1,60 @@
1
+ module Pancake
2
+ module Hooks
3
+ module InheritableInnerClasses
4
+ def self.extended(base)
5
+ base.class_eval do
6
+ class_inheritable_reader :_inhertiable_inner_classes
7
+ @_inhertiable_inner_classes = []
8
+ end
9
+ end # extended
10
+
11
+ # Declare inner classes to be inherited when the outer class in inherited
12
+ # The best way to show this is by example:
13
+ #
14
+ # @example
15
+ # class Foo
16
+ # inheritable_inner_class :Bar
17
+ #
18
+ # class Bar
19
+ # end
20
+ # end
21
+ #
22
+ # class Baz < Foo
23
+ # # When Foo is inherited, the following occurs
24
+ # class Bar < Foo::Bar; end
25
+ # end
26
+ #
27
+ # This provides a more organic inheritance where the child gets their own
28
+ # version of the inner class which is actually inherited from the parents inner class.
29
+ # The inheritance chain remains intact.
30
+ #
31
+ # @api public
32
+ # @since 0.1.0
33
+ # @author Daniel Neighman
34
+ def inheritable_inner_classes(*classes)
35
+ _inhertiable_inner_classes
36
+ unless classes.empty?
37
+ _inhertiable_inner_classes << classes
38
+ _inhertiable_inner_classes.flatten!
39
+ end
40
+ _inhertiable_inner_classes
41
+ end
42
+
43
+ # The inherited hook that sets up inherited inner classes. Remember if you overwrite this method, you should
44
+ # call super!
45
+ #
46
+ # @api private
47
+ # @since 0.1.0
48
+ # @author Daniel Neighman
49
+ def inherited(base)
50
+ super
51
+ class_defs = inheritable_inner_classes.map do |klass|
52
+ "class #{klass} < superclass::#{klass}; end\n"
53
+ end
54
+ # puts "#{base.name} is INHERITING INNER CLASSES #{class_defs.inspect}"
55
+ base.class_eval(class_defs.join)
56
+ end
57
+
58
+ end # InheritableInnerClasses
59
+ end # Hooks
60
+ end # Pancake
@@ -0,0 +1,34 @@
1
+ module Pancake
2
+ module Hooks
3
+ module OnInherit
4
+ def self.extended(base)
5
+ base.class_eval do
6
+ class_inheritable_reader :_on_inherit
7
+ @_on_inherit = []
8
+ end
9
+ end
10
+
11
+ # Provides an inheritance hook to all extended classes
12
+ # Allows ou to hook into the inheritance
13
+ def inherited(base)
14
+ super
15
+ _on_inherit.each{|b| b.call(base,self)}
16
+ end
17
+
18
+ # A hook to add code when the stack is inherited
19
+ # The code will be executed when the class is inherited
20
+ #
21
+ # @example
22
+ # MyClass.on_inherit do |base, parent|
23
+ # # do stuff here between the child and parent
24
+ # end
25
+ #
26
+ # @api public
27
+ # @author Daniel Neighman
28
+ def on_inherit(&block)
29
+ _on_inherit << block if block
30
+ _on_inherit
31
+ end
32
+ end # OnInherit
33
+ end # Hooks
34
+ end # Pancake