espresso-framework 0.3.0
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 +15 -0
- data/.gitignore +6 -0
- data/LICENSE +20 -0
- data/README.rdoc +32 -0
- data/Rakefile +88 -0
- data/VERSION +1 -0
- data/espresso-framework.gemspec +110 -0
- data/init.rb +1 -0
- data/lib/espresso.rb +49 -0
- data/lib/espresso/collection.rb +44 -0
- data/lib/espresso/collection/searchlogic.rb +17 -0
- data/lib/espresso/collection/will_paginate.rb +19 -0
- data/lib/espresso/concern.rb +37 -0
- data/lib/espresso/controller.rb +17 -0
- data/lib/espresso/controller/inherited_resources.rb +110 -0
- data/lib/espresso/deprecated.rb +19 -0
- data/lib/espresso/deprecated/resources.rb +11 -0
- data/lib/espresso/extensions/action_controller.rb +6 -0
- data/lib/espresso/extensions/action_view.rb +6 -0
- data/lib/espresso/extensions/active_record.rb +6 -0
- data/lib/espresso/extensions/all.rb +6 -0
- data/lib/espresso/extensions/haml.rb +28 -0
- data/lib/espresso/extensions/has_scope.rb +13 -0
- data/lib/espresso/extensions/inherited_resources.rb +15 -0
- data/lib/espresso/extensions/searchlogic.rb +14 -0
- data/lib/espresso/extensions/will_paginate.rb +14 -0
- data/lib/espresso/model.rb +36 -0
- data/lib/espresso/model/inherited_resources.rb +20 -0
- data/lib/espresso/view.rb +261 -0
- data/lib/espresso/view/form_builder.rb +60 -0
- data/lib/espresso/view/has_scope.rb +23 -0
- data/lib/espresso/view/inherited_resources.rb +72 -0
- data/lib/espresso/view/searchlogic.rb +33 -0
- data/lib/espresso/view/will_paginate.rb +35 -0
- data/test/espresso_collection_test.rb +6 -0
- data/test/espresso_controller_test.rb +1 -0
- data/test/espresso_extensions_haml_test.rb +19 -0
- data/test/espresso_model_test.rb +26 -0
- data/test/espresso_test.rb +5 -0
- data/test/espresso_view_has_scope_test.rb +11 -0
- data/test/espresso_view_test.rb +46 -0
- data/test/espresso_view_will_paginate_test.rb +9 -0
- data/test/example_model.rb +23 -0
- data/test/test_helper.rb +51 -0
- metadata +182 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YjJmMmFkNGNhMmJmZTU3MzlhOGU3MGRmMmNiYzYwMzNlMzEzOWFjOA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZjhmMTY5MGZiMjdlNjdmMDA4ZTUwOTZmNjk4ZWMxNjIyOTVjNWZjMw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZWQ4NTYxYjBkODU2Y2UyNGU3Y2JiN2U4YzBjMjg3OTllMzFlM2I1MzM3N2Nk
|
10
|
+
NDcxYjEwZjNhZmNkNWQzMTVjYmI5NGI5Yjc5ZTJkYTYyNmMwNGJkZmY5OWM5
|
11
|
+
ZWZmYjNkZGM2ZGRmYmE5N2RlMmYwODllOWYxMmYxNjMyODA1ZWU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NjZhNjAxNGM2OTBkMjk1OWFmYTgxODMxMTgwNzBkYWIxYjIzODk1NzI0YzY1
|
14
|
+
NDFiNWE3NzViMGNkOTRhNzE0Njk2NTIzMzk5ZGQzNjUwYWIzMzc1Y2IyZDlm
|
15
|
+
N2NhYWFhOTVlZDc4NWY0N2M2MmUxYTU4NTNhMGIwNzNhNWJhNzA=
|
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Alexander Semyonov
|
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.
|
data/README.rdoc
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
= Espresso
|
2
|
+
|
3
|
+
Some useful extensions to default Rails environment.
|
4
|
+
|
5
|
+
Can be more extended if using with InheritedResources, WillPaginate, Searchlogic and Formtastic.
|
6
|
+
|
7
|
+
== Espresso::Model
|
8
|
+
|
9
|
+
Enhances ActiveRecord::Base classes with #name_field and #make_slug methods.
|
10
|
+
|
11
|
+
== Espresso::View
|
12
|
+
|
13
|
+
Enhances ActionView with some useful helpers
|
14
|
+
|
15
|
+
== Espresso::Controller
|
16
|
+
|
17
|
+
Uses InheritedResources, WillPaginate and Searchlogic to provide enhanced RESTful resources controllers.
|
18
|
+
|
19
|
+
== Note on Patches/Pull Requests
|
20
|
+
|
21
|
+
* Fork the project.
|
22
|
+
* Make your feature addition or bug fix.
|
23
|
+
* Add tests for it. This is important so I don't break it in a
|
24
|
+
future version unintentionally.
|
25
|
+
* Commit, do not mess with rakefile, version, or history.
|
26
|
+
(if you want to have your own version, that is fine but
|
27
|
+
bump version in a commit by itself I can ignore when I pull)
|
28
|
+
* Send me a pull request. Bonus points for topic branches.
|
29
|
+
|
30
|
+
== Copyright
|
31
|
+
|
32
|
+
© 2009 Alexander Semyonov. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = 'espresso'
|
8
|
+
gem.summary = %Q{Rails extender to simplify rails development}
|
9
|
+
gem.description = %Q{Useful templates for controller and model functions}
|
10
|
+
gem.email = 'rotuka@tokak.ru'
|
11
|
+
gem.homepage = 'http://github.com/krasivotokak/espresso'
|
12
|
+
gem.authors = ['Alexander Semyonov']
|
13
|
+
gem.add_dependency('activesupport', '~> 2.3.5')
|
14
|
+
gem.add_dependency('activerecord', '~> 2.3.5')
|
15
|
+
gem.add_dependency('actionpack', '~> 2.3.5')
|
16
|
+
gem.add_dependency('inherited_resources', '~> 1.0.5')
|
17
|
+
gem.add_development_dependency('shoulda')
|
18
|
+
gem.add_development_dependency('redgreen')
|
19
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
20
|
+
end
|
21
|
+
Jeweler::GemcutterTasks.new
|
22
|
+
rescue LoadError
|
23
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'rake/testtask'
|
27
|
+
Rake::TestTask.new(:test) do |test|
|
28
|
+
test.libs << 'lib' << 'test'
|
29
|
+
test.pattern = 'test/**/*_test.rb'
|
30
|
+
test.verbose = true
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
require 'rcov/rcovtask'
|
35
|
+
Rcov::RcovTask.new do |test|
|
36
|
+
test.libs << 'lib' << 'test'
|
37
|
+
test.pattern = 'test/**/*_test.rb'
|
38
|
+
test.verbose = true
|
39
|
+
end
|
40
|
+
rescue LoadError
|
41
|
+
task :rcov do
|
42
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install rcov"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
begin
|
47
|
+
require 'reek/rake/task'
|
48
|
+
Reek::Rake::Task.new do |test|
|
49
|
+
test.ruby_opts << '-rubygems'
|
50
|
+
end
|
51
|
+
rescue LoadError
|
52
|
+
task :reek do
|
53
|
+
abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
begin
|
58
|
+
require 'roodi'
|
59
|
+
require 'roodi_task'
|
60
|
+
RoodiTask.new do |t|
|
61
|
+
t.patterns << 'lib/*.rb' << 'lib/**/*.rb'
|
62
|
+
end
|
63
|
+
rescue LoadError
|
64
|
+
task :roodi do
|
65
|
+
abort "Roodi is not available. In order to run reek, you must: sudo gem install roodi"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
task :test => :check_dependencies
|
70
|
+
|
71
|
+
task :default => :test
|
72
|
+
|
73
|
+
begin
|
74
|
+
require 'yard'
|
75
|
+
YARD::Rake::YardocTask.new do |yard|
|
76
|
+
yard.options << '--no-private'
|
77
|
+
end
|
78
|
+
rescue LoadError
|
79
|
+
task :yardoc do
|
80
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
desc 'Generate documentation'
|
85
|
+
task :doc => :yard
|
86
|
+
|
87
|
+
desc "Bump patch version and release to github and gemcutter"
|
88
|
+
task :bump => %w(version:bump:patch release gemcutter:release install)
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.1
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{espresso-framework}
|
8
|
+
s.version = "0.3.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Alexander Semyonov"]
|
12
|
+
s.date = %q{2010-03-29}
|
13
|
+
s.description = %q{Useful templates for controller and model functions}
|
14
|
+
s.email = %q{rotuka@tokak.ru}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"espresso-framework.gemspec",
|
26
|
+
"init.rb",
|
27
|
+
"lib/espresso.rb",
|
28
|
+
"lib/espresso/collection.rb",
|
29
|
+
"lib/espresso/collection/searchlogic.rb",
|
30
|
+
"lib/espresso/collection/will_paginate.rb",
|
31
|
+
"lib/espresso/concern.rb",
|
32
|
+
"lib/espresso/controller.rb",
|
33
|
+
"lib/espresso/controller/inherited_resources.rb",
|
34
|
+
"lib/espresso/deprecated.rb",
|
35
|
+
"lib/espresso/deprecated/resources.rb",
|
36
|
+
"lib/espresso/extensions/action_controller.rb",
|
37
|
+
"lib/espresso/extensions/action_view.rb",
|
38
|
+
"lib/espresso/extensions/active_record.rb",
|
39
|
+
"lib/espresso/extensions/all.rb",
|
40
|
+
"lib/espresso/extensions/haml.rb",
|
41
|
+
"lib/espresso/extensions/has_scope.rb",
|
42
|
+
"lib/espresso/extensions/inherited_resources.rb",
|
43
|
+
"lib/espresso/extensions/searchlogic.rb",
|
44
|
+
"lib/espresso/extensions/will_paginate.rb",
|
45
|
+
"lib/espresso/model.rb",
|
46
|
+
"lib/espresso/model/inherited_resources.rb",
|
47
|
+
"lib/espresso/view.rb",
|
48
|
+
"lib/espresso/view/form_builder.rb",
|
49
|
+
"lib/espresso/view/has_scope.rb",
|
50
|
+
"lib/espresso/view/inherited_resources.rb",
|
51
|
+
"lib/espresso/view/searchlogic.rb",
|
52
|
+
"lib/espresso/view/will_paginate.rb",
|
53
|
+
"test/espresso_collection_test.rb",
|
54
|
+
"test/espresso_controller_test.rb",
|
55
|
+
"test/espresso_extensions_haml_test.rb",
|
56
|
+
"test/espresso_model_test.rb",
|
57
|
+
"test/espresso_test.rb",
|
58
|
+
"test/espresso_view_has_scope_test.rb",
|
59
|
+
"test/espresso_view_test.rb",
|
60
|
+
"test/espresso_view_will_paginate_test.rb",
|
61
|
+
"test/example_model.rb",
|
62
|
+
"test/test_helper.rb"
|
63
|
+
]
|
64
|
+
s.homepage = %q{http://github.com/krasivotokak/espresso}
|
65
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
66
|
+
s.require_paths = ["lib"]
|
67
|
+
s.rubygems_version = %q{1.3.6}
|
68
|
+
s.summary = %q{Rails extender to simplify rails development}
|
69
|
+
s.test_files = [
|
70
|
+
"test/espresso_extensions_haml_test.rb",
|
71
|
+
"test/example_model.rb",
|
72
|
+
"test/espresso_collection_test.rb",
|
73
|
+
"test/espresso_model_test.rb",
|
74
|
+
"test/espresso_view_test.rb",
|
75
|
+
"test/espresso_test.rb",
|
76
|
+
"test/test_helper.rb",
|
77
|
+
"test/espresso_controller_test.rb",
|
78
|
+
"test/espresso_view_has_scope_test.rb",
|
79
|
+
"test/espresso_view_will_paginate_test.rb"
|
80
|
+
]
|
81
|
+
|
82
|
+
if s.respond_to? :specification_version then
|
83
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
84
|
+
s.specification_version = 3
|
85
|
+
|
86
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
87
|
+
s.add_runtime_dependency(%q<activesupport>, ["~> 2.3.5"])
|
88
|
+
s.add_runtime_dependency(%q<activerecord>, ["~> 2.3.5"])
|
89
|
+
s.add_runtime_dependency(%q<actionpack>, ["~> 2.3.5"])
|
90
|
+
s.add_runtime_dependency(%q<inherited_resources>, ["~> 1.0.5"])
|
91
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
92
|
+
s.add_development_dependency(%q<redgreen>, [">= 0"])
|
93
|
+
else
|
94
|
+
s.add_dependency(%q<activesupport>, ["~> 2.3.5"])
|
95
|
+
s.add_dependency(%q<activerecord>, ["~> 2.3.5"])
|
96
|
+
s.add_dependency(%q<actionpack>, ["~> 2.3.5"])
|
97
|
+
s.add_dependency(%q<inherited_resources>, ["~> 1.0.5"])
|
98
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
99
|
+
s.add_dependency(%q<redgreen>, [">= 0"])
|
100
|
+
end
|
101
|
+
else
|
102
|
+
s.add_dependency(%q<activesupport>, ["~> 2.3.5"])
|
103
|
+
s.add_dependency(%q<activerecord>, ["~> 2.3.5"])
|
104
|
+
s.add_dependency(%q<actionpack>, ["~> 2.3.5"])
|
105
|
+
s.add_dependency(%q<inherited_resources>, ["~> 1.0.5"])
|
106
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
107
|
+
s.add_dependency(%q<redgreen>, [">= 0"])
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'espresso'
|
data/lib/espresso.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
$KCODE = 'u'
|
2
|
+
require 'active_support/core_ext/module'
|
3
|
+
|
4
|
+
module Espresso
|
5
|
+
autoload :Model, 'espresso/model'
|
6
|
+
autoload :View, 'espresso/view'
|
7
|
+
autoload :Controller, 'espresso/controller'
|
8
|
+
autoload :Collection, 'espresso/collection'
|
9
|
+
autoload :Concern, 'espresso/concern'
|
10
|
+
|
11
|
+
BASE_MODULES = %w(model view controller)
|
12
|
+
|
13
|
+
mattr_accessor :extensions
|
14
|
+
self.extensions = []
|
15
|
+
|
16
|
+
# Configures Espresso.
|
17
|
+
# By default, loads all extensions
|
18
|
+
def self.configure
|
19
|
+
if block_given?
|
20
|
+
yield
|
21
|
+
else
|
22
|
+
uses :all
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Loads Espresso extensions
|
27
|
+
# @param [String, Symbol] extension name of the Espresso extension
|
28
|
+
def self.uses(extension)
|
29
|
+
require("espresso/extensions/#{extension}")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
if defined?(ActiveRecord)
|
34
|
+
Espresso.uses :active_record
|
35
|
+
end
|
36
|
+
|
37
|
+
if defined?(ActionView)
|
38
|
+
Espresso.uses :action_view
|
39
|
+
end
|
40
|
+
|
41
|
+
if defined?(ActionController)
|
42
|
+
Espresso.uses :action_controller
|
43
|
+
end
|
44
|
+
|
45
|
+
if defined?(Haml)
|
46
|
+
Espresso.uses :haml
|
47
|
+
end
|
48
|
+
|
49
|
+
require 'espresso/deprecated'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'active_support/core_ext/class'
|
2
|
+
|
3
|
+
module Espresso
|
4
|
+
self.extensions << :collection
|
5
|
+
# Represents collection of resources.
|
6
|
+
# Used in Espresso::Controller InheritedResources extension
|
7
|
+
class Collection < Array
|
8
|
+
cattr_accessor :per_page
|
9
|
+
self.per_page = 30
|
10
|
+
|
11
|
+
attr_accessor :base, :options, :collection, :search
|
12
|
+
protected :base, :options, :collection
|
13
|
+
|
14
|
+
# Initiates a collection of resources
|
15
|
+
# @param [AtiveRecord::Base] base Base class having {Espresso::Model} included
|
16
|
+
# @param [Hash] options options for building the collection
|
17
|
+
# @option options [Number] :page current page number
|
18
|
+
# @option options [Number] :per_page per-page limit
|
19
|
+
# @option options [Hash] :search conditions for searching
|
20
|
+
def initialize(base, options = {})
|
21
|
+
@base, @options = base, options
|
22
|
+
replace(collection)
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
# All resources in {#base}
|
27
|
+
def collection
|
28
|
+
@collection ||= base.all(@options)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Proxy to {#collection} methods
|
32
|
+
def method_missing(method_name, *args)
|
33
|
+
collection.send(method_name, *args)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
if defined? Searchlogic
|
39
|
+
require 'espresso/collection/searchlogic'
|
40
|
+
end
|
41
|
+
|
42
|
+
if defined? WillPaginate
|
43
|
+
require 'espresso/collection/will_paginate'
|
44
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'espresso/collection'
|
2
|
+
require 'searchlogic'
|
3
|
+
|
4
|
+
module Espresso
|
5
|
+
class Collection
|
6
|
+
# Use ActiveRecord::Base#searchlogic method to generate
|
7
|
+
# base for finding the collection
|
8
|
+
# @return [ActiveRecord::Base] ActiveRecord model scoped with searchlogic
|
9
|
+
def base
|
10
|
+
unless @search
|
11
|
+
search_options = options.delete(:search) { {} }
|
12
|
+
@search = @base.searchlogic(search_options)
|
13
|
+
end
|
14
|
+
@search
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'espresso/collection'
|
2
|
+
require 'will_paginate/collection'
|
3
|
+
|
4
|
+
module Espresso
|
5
|
+
class Collection
|
6
|
+
# Finds collection by ActiveRecord::Base.paginate method
|
7
|
+
# and options provided in {Espresso::Collection#initialize} method
|
8
|
+
# @return [WillPaginate::Collection] single page of resources
|
9
|
+
def collection
|
10
|
+
unless @collection
|
11
|
+
page = options.delete(:page) { 1 }
|
12
|
+
per_page = options.delete(:per_page) { Espresso::Collection.per_page }
|
13
|
+
@collection ||= base.paginate(:page => page,
|
14
|
+
:per_page => per_page)
|
15
|
+
end
|
16
|
+
@collection
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'espresso'
|
2
|
+
|
3
|
+
module Espresso
|
4
|
+
# Code extracted from ActiveSupport 3.0.0beta
|
5
|
+
module Concern
|
6
|
+
def self.extended(base)
|
7
|
+
base.instance_variable_set('@_dependencies', [])
|
8
|
+
end
|
9
|
+
|
10
|
+
def append_features(base)
|
11
|
+
if base.instance_variable_defined?('@_dependencies')
|
12
|
+
base.instance_variable_get('@_dependencies') << self
|
13
|
+
return false
|
14
|
+
else
|
15
|
+
return false if base < self
|
16
|
+
@_dependencies.each { |dep| base.send(:include, dep) }
|
17
|
+
super
|
18
|
+
base.extend const_get('ClassMethods') if const_defined?('ClassMethods')
|
19
|
+
base.send :include, const_get('InstanceMethods') if const_defined?('InstanceMethods')
|
20
|
+
if instance_variable_defined?('@_included_blocks')
|
21
|
+
@_included_blocks.each do |included_block|
|
22
|
+
base.class_eval(&included_block)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def included(base = nil, &block)
|
29
|
+
if base.nil?
|
30
|
+
@_included_blocks ||= []
|
31
|
+
@_included_blocks << block
|
32
|
+
else
|
33
|
+
super
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|