cauta-desert 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +46 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +316 -0
- data/Rakefile +77 -0
- data/VERSION.yml +2 -0
- data/generators/desert_plugin/USAGE +14 -0
- data/generators/desert_plugin/desert_plugin_generator.rb +73 -0
- data/generators/desert_plugin/templates/desert_routes.rb +4 -0
- data/generators/desert_plugin/templates/empty_file +0 -0
- data/generators/desert_plugin/templates/plugin_migration.rb +11 -0
- data/generators/desert_plugin/templates/spec_helper.rb +8 -0
- data/init.rb +0 -0
- data/lib/desert/manager.rb +129 -0
- data/lib/desert/plugin.rb +74 -0
- data/lib/desert/plugin_migrations/1.2/extensions/schema_statements.rb +34 -0
- data/lib/desert/plugin_migrations/1.2/migrator.rb +33 -0
- data/lib/desert/plugin_migrations/2.1/extensions/schema_statements.rb +33 -0
- data/lib/desert/plugin_migrations/2.1/migrator.rb +35 -0
- data/lib/desert/plugin_migrations/migrator.rb +29 -0
- data/lib/desert/plugin_migrations.rb +11 -0
- data/lib/desert/plugin_templates/1.2.0/action_mailer.rb +21 -0
- data/lib/desert/plugin_templates/1.2.0/action_view.rb +53 -0
- data/lib/desert/plugin_templates/1.99.0/action_mailer.rb +25 -0
- data/lib/desert/plugin_templates/1.99.0/action_view.rb +38 -0
- data/lib/desert/plugin_templates/2.0.0/action_mailer.rb +23 -0
- data/lib/desert/plugin_templates/2.0.2/action_view.rb +26 -0
- data/lib/desert/plugin_templates/2.1.0/action_view.rb +12 -0
- data/lib/desert/plugin_templates/action_controller.rb +12 -0
- data/lib/desert/plugin_templates/action_view.rb +17 -0
- data/lib/desert/plugin_templates.rb +10 -0
- data/lib/desert/rails/1.2.0/initializer.rb +20 -0
- data/lib/desert/rails/2.0.0/plugin.rb +22 -0
- data/lib/desert/rails/dependencies.rb +87 -0
- data/lib/desert/rails/migration.rb +36 -0
- data/lib/desert/rails/route_set.rb +23 -0
- data/lib/desert/rails.rb +10 -0
- data/lib/desert/ruby/object.rb +34 -0
- data/lib/desert/ruby.rb +2 -0
- data/lib/desert/supported_rails_versions.rb +12 -0
- data/lib/desert/tasks.rb +4 -0
- data/lib/desert/version_checker.rb +26 -0
- data/lib/desert.rb +14 -0
- metadata +102 -0
@@ -0,0 +1,87 @@
|
|
1
|
+
dependencies = ActiveSupport.const_defined?(:Dependencies) ? ActiveSupport::Dependencies : Dependencies
|
2
|
+
dependencies.module_eval do
|
3
|
+
def load_missing_constant_with_desert(from_mod, const_name)
|
4
|
+
from_mod = guard_against_anonymous_module(from_mod)
|
5
|
+
qualified_name = qualified_name_for from_mod, const_name
|
6
|
+
path_suffix = qualified_name.underscore
|
7
|
+
|
8
|
+
if define_constant_with_desert_loading(from_mod, const_name, qualified_name, path_suffix)
|
9
|
+
return from_mod.const_get(const_name)
|
10
|
+
end
|
11
|
+
|
12
|
+
if has_parent_module?(from_mod)
|
13
|
+
look_for_constant_in_parent_module(from_mod, const_name, qualified_name, path_suffix)
|
14
|
+
else
|
15
|
+
raise NameError, "Constant #{qualified_name} from #{path_suffix}.rb not found"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
alias_method_chain :load_missing_constant, :desert
|
19
|
+
|
20
|
+
def load_once_path?(path)
|
21
|
+
load_once_paths.any? { |base| File.expand_path(path).starts_with? File.expand_path(base) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def depend_on_with_desert(file_name, swallow_load_errors = false)
|
25
|
+
successfully_loaded_in_plugin = false
|
26
|
+
Desert::Manager.files_on_load_path(file_name).each do |file|
|
27
|
+
require_or_load(file)
|
28
|
+
successfully_loaded_in_plugin = true
|
29
|
+
end
|
30
|
+
begin
|
31
|
+
unless successfully_loaded_in_plugin
|
32
|
+
require_or_load file_name
|
33
|
+
loaded << File.expand_path(file_name)
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
if !swallow_load_errors && !successfully_loaded_in_plugin
|
37
|
+
raise
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
alias_method_chain :depend_on, :desert
|
42
|
+
|
43
|
+
protected
|
44
|
+
def define_constant_with_desert_loading(from_mod, const_name, qualified_name, path_suffix)
|
45
|
+
define_constant_from_file(from_mod, const_name, qualified_name, path_suffix) ||
|
46
|
+
define_constant_from_directory(from_mod, const_name, qualified_name, path_suffix)
|
47
|
+
end
|
48
|
+
|
49
|
+
def has_parent_module?(mod)
|
50
|
+
mod != Object
|
51
|
+
end
|
52
|
+
|
53
|
+
def look_for_constant_in_parent_module(from_mod, const_name, qualified_name, path_suffix)
|
54
|
+
return from_mod.parent.const_missing(const_name)
|
55
|
+
rescue NameError => e
|
56
|
+
raise NameError, "Constant #{qualified_name} from #{path_suffix}.rb not found\n#{e.message}"
|
57
|
+
end
|
58
|
+
|
59
|
+
def guard_against_anonymous_module(from_mod)
|
60
|
+
return Object if from_mod.name.blank?
|
61
|
+
return from_mod
|
62
|
+
end
|
63
|
+
|
64
|
+
def define_constant_from_file(from_mod, const_name, qualified_name, path_suffix)
|
65
|
+
files = Desert::Manager.files_on_load_path(path_suffix)
|
66
|
+
files.each do |file|
|
67
|
+
require_or_load file
|
68
|
+
loaded << file.gsub(/\.rb$/, '')
|
69
|
+
next if autoloaded_constants.include?(qualified_name)
|
70
|
+
next if load_once_path?(file)
|
71
|
+
autoloaded_constants << qualified_name
|
72
|
+
end
|
73
|
+
loaded << File.expand_path(path_suffix)
|
74
|
+
from_mod.const_defined?(const_name)
|
75
|
+
end
|
76
|
+
|
77
|
+
def define_constant_from_directory(from_mod, const_name, qualified_name, path_suffix)
|
78
|
+
return false unless Desert::Manager.directory_on_load_path?(path_suffix)
|
79
|
+
|
80
|
+
if autoloaded_constants.include?(qualified_name)
|
81
|
+
raise "Constant #{qualified_name} is already autoloaded but is not defined as a constant"
|
82
|
+
end
|
83
|
+
from_mod.const_set(const_name, Module.new)
|
84
|
+
autoloaded_constants << qualified_name
|
85
|
+
return true
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class ActiveRecord::Migration
|
2
|
+
module DesertMigration
|
3
|
+
def migrate_plugin(plugin_name, version)
|
4
|
+
plugin = find_plugin(plugin_name)
|
5
|
+
Desert::PluginMigrations::Migrator.migrate_plugin(
|
6
|
+
plugin,
|
7
|
+
version
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
def find_plugin(plugin_name)
|
13
|
+
plugin = Desert::Manager.find_plugin(plugin_name.to_s)
|
14
|
+
return plugin if plugin
|
15
|
+
raise ArgumentError, "No plugin found named #{plugin_name}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def table_exists?(table_name)
|
19
|
+
vals = select_all("DESC #{table_name}")
|
20
|
+
return true
|
21
|
+
rescue ActiveRecord::StatementInvalid
|
22
|
+
return false
|
23
|
+
end
|
24
|
+
|
25
|
+
def column_exists?(table_name, column_name)
|
26
|
+
val = select_one("select #{column_name} from #{table_name}")
|
27
|
+
return true
|
28
|
+
rescue ActiveRecord::StatementInvalid
|
29
|
+
return false
|
30
|
+
end
|
31
|
+
def table_exists?(table_name)
|
32
|
+
ActiveRecord::Base.connection.tables.include? table_name
|
33
|
+
end
|
34
|
+
end
|
35
|
+
extend DesertMigration
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Desert
|
2
|
+
module Rails
|
3
|
+
module RouteSet
|
4
|
+
# Loads the set of routes from within a plugin and evaluates them at this
|
5
|
+
# point within an application's main <tt>routes.rb</tt> file.
|
6
|
+
#
|
7
|
+
# Plugin routes are loaded from <tt><plugin_root>/routes.rb</tt>.
|
8
|
+
def routes_from_plugin(name)
|
9
|
+
name = name.to_s
|
10
|
+
routes_path = File.join(
|
11
|
+
Desert::Manager.plugin_path(name),
|
12
|
+
"config/desert_routes.rb"
|
13
|
+
)
|
14
|
+
RAILS_DEFAULT_LOGGER.debug "Loading routes from #{routes_path}."
|
15
|
+
eval(IO.read(routes_path), binding, routes_path) if File.file?(routes_path)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class ActionController::Routing::RouteSet::Mapper
|
22
|
+
include Desert::Rails::RouteSet
|
23
|
+
end
|
data/lib/desert/rails.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
dir = File.dirname(__FILE__)
|
2
|
+
if Desert::VersionChecker.rails_version_is_below_1990?
|
3
|
+
require "#{dir}/rails/1.2.0/initializer"
|
4
|
+
else
|
5
|
+
require "#{dir}/rails/2.0.0/plugin"
|
6
|
+
end
|
7
|
+
require "#{dir}/rails/dependencies"
|
8
|
+
require "#{dir}/rails/migration"
|
9
|
+
|
10
|
+
require "#{dir}/rails/route_set"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Object
|
2
|
+
def require_with_desert(path)
|
3
|
+
relative_include_path = (path =~ /\.rb$/) ? path : "#{path}.rb"
|
4
|
+
if $".include?(relative_include_path)
|
5
|
+
return false
|
6
|
+
else
|
7
|
+
__each_matching_file(path) do |expanded_path|
|
8
|
+
require_without_desert expanded_path
|
9
|
+
end
|
10
|
+
$" << relative_include_path
|
11
|
+
return true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
alias_method_chain :require, :desert
|
15
|
+
|
16
|
+
def load_with_desert(file)
|
17
|
+
__each_matching_file(file) do |file|
|
18
|
+
load_without_desert file
|
19
|
+
end
|
20
|
+
end
|
21
|
+
alias_method_chain :load, :desert
|
22
|
+
|
23
|
+
private
|
24
|
+
def __each_matching_file(file)
|
25
|
+
files = Desert::Manager.instance.files_on_load_path(file)
|
26
|
+
desert_file_exists = files.empty? ? false : true
|
27
|
+
files.each do |component_file|
|
28
|
+
yield(component_file)
|
29
|
+
end
|
30
|
+
|
31
|
+
return true if desert_file_exists
|
32
|
+
yield(file)
|
33
|
+
end
|
34
|
+
end
|
data/lib/desert/ruby.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module Desert
|
2
|
+
SUPPORTED_RAILS_VERSIONS = {
|
3
|
+
"1.2.5" => {'version' => '1.2.5', 'git_tag' => 'v1.2.5'},
|
4
|
+
"1.99.0" => {'version' => '1.99.0', 'git_tag' => 'v2.0.0_RC1'},
|
5
|
+
"2.0.2" => {'version' => '2.0.2', 'git_tag' => 'v2.0.2'},
|
6
|
+
"2.1.0" => {'version' => '2.1.0', 'git_tag' => 'v2.1.0'},
|
7
|
+
"2.2.0" => {'version' => '2.2.0', 'git_tag' => 'v2.2.0'},
|
8
|
+
"2.2.2" => {'version' => '2.2.2', 'git_tag' => 'v2.2.2'},
|
9
|
+
"2.3.2" => {'version' => '2.3.2', 'git_tag' => 'v2.3.2'},
|
10
|
+
# "edge" => {'version' => 'edge', 'git_tag' => 'master'},
|
11
|
+
}
|
12
|
+
end
|
data/lib/desert/tasks.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Desert
|
2
|
+
class VersionChecker
|
3
|
+
class << self
|
4
|
+
def current_rails_version_matches?(version_requirement)
|
5
|
+
version_matches?(::Rails::VERSION::STRING, version_requirement)
|
6
|
+
end
|
7
|
+
|
8
|
+
def version_matches?(version, version_requirement)
|
9
|
+
Gem::Version::Requirement.new([version_requirement]).satisfied_by?(Gem::Version.new(version))
|
10
|
+
end
|
11
|
+
|
12
|
+
def rails_version_is_below_1990?
|
13
|
+
result = current_rails_version_matches?('<1.99.0')
|
14
|
+
result
|
15
|
+
end
|
16
|
+
|
17
|
+
def rails_version_is_below_rc2?
|
18
|
+
current_rails_version_matches?('<1.99.1')
|
19
|
+
end
|
20
|
+
|
21
|
+
def rails_version_is_1991?
|
22
|
+
current_rails_version_matches?('=1.99.1')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/desert.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "active_support"
|
2
|
+
require "active_record"
|
3
|
+
require "action_controller"
|
4
|
+
require "action_mailer"
|
5
|
+
|
6
|
+
dir = File.dirname(__FILE__)
|
7
|
+
require "#{dir}/desert/supported_rails_versions"
|
8
|
+
require "#{dir}/desert/plugin"
|
9
|
+
require "#{dir}/desert/manager"
|
10
|
+
require "#{dir}/desert/version_checker"
|
11
|
+
require "#{dir}/desert/rails"
|
12
|
+
require "#{dir}/desert/ruby"
|
13
|
+
require "#{dir}/desert/plugin_migrations"
|
14
|
+
require "#{dir}/desert/plugin_templates"
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cauta-desert
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pivotal Labs
|
8
|
+
- Brian Takita Mockingbird
|
9
|
+
- Parker I'm-not-a-hippie! Thompson
|
10
|
+
- Adam 'That's Crap' Milligan
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
|
15
|
+
date: 2009-04-08 00:00:00 -07:00
|
16
|
+
default_executable:
|
17
|
+
dependencies: []
|
18
|
+
|
19
|
+
description: Desert is a component framework for Rails that allows your plugins to be packaged as mini Rails apps.
|
20
|
+
email: opensource@pivotallabs.com
|
21
|
+
executables: []
|
22
|
+
|
23
|
+
extensions: []
|
24
|
+
|
25
|
+
extra_rdoc_files:
|
26
|
+
- CHANGES
|
27
|
+
- README.rdoc
|
28
|
+
files:
|
29
|
+
- CHANGES
|
30
|
+
- MIT-LICENSE
|
31
|
+
- README.rdoc
|
32
|
+
- Rakefile
|
33
|
+
- VERSION.yml
|
34
|
+
- generators/desert_plugin/USAGE
|
35
|
+
- generators/desert_plugin/desert_plugin_generator.rb
|
36
|
+
- generators/desert_plugin/templates/desert_routes.rb
|
37
|
+
- generators/desert_plugin/templates/empty_file
|
38
|
+
- generators/desert_plugin/templates/plugin_migration.rb
|
39
|
+
- generators/desert_plugin/templates/spec_helper.rb
|
40
|
+
- init.rb
|
41
|
+
- lib/desert.rb
|
42
|
+
- lib/desert/manager.rb
|
43
|
+
- lib/desert/plugin.rb
|
44
|
+
- lib/desert/plugin_migrations.rb
|
45
|
+
- lib/desert/plugin_migrations/1.2/extensions/schema_statements.rb
|
46
|
+
- lib/desert/plugin_migrations/1.2/migrator.rb
|
47
|
+
- lib/desert/plugin_migrations/2.1/extensions/schema_statements.rb
|
48
|
+
- lib/desert/plugin_migrations/2.1/migrator.rb
|
49
|
+
- lib/desert/plugin_migrations/migrator.rb
|
50
|
+
- lib/desert/plugin_templates.rb
|
51
|
+
- lib/desert/plugin_templates/1.2.0/action_mailer.rb
|
52
|
+
- lib/desert/plugin_templates/1.2.0/action_view.rb
|
53
|
+
- lib/desert/plugin_templates/1.99.0/action_mailer.rb
|
54
|
+
- lib/desert/plugin_templates/1.99.0/action_view.rb
|
55
|
+
- lib/desert/plugin_templates/2.0.0/action_mailer.rb
|
56
|
+
- lib/desert/plugin_templates/2.0.2/action_view.rb
|
57
|
+
- lib/desert/plugin_templates/2.1.0/action_view.rb
|
58
|
+
- lib/desert/plugin_templates/action_controller.rb
|
59
|
+
- lib/desert/plugin_templates/action_view.rb
|
60
|
+
- lib/desert/rails.rb
|
61
|
+
- lib/desert/rails/1.2.0/initializer.rb
|
62
|
+
- lib/desert/rails/2.0.0/plugin.rb
|
63
|
+
- lib/desert/rails/dependencies.rb
|
64
|
+
- lib/desert/rails/migration.rb
|
65
|
+
- lib/desert/rails/route_set.rb
|
66
|
+
- lib/desert/ruby.rb
|
67
|
+
- lib/desert/ruby/object.rb
|
68
|
+
- lib/desert/supported_rails_versions.rb
|
69
|
+
- lib/desert/tasks.rb
|
70
|
+
- lib/desert/version_checker.rb
|
71
|
+
has_rdoc: true
|
72
|
+
homepage: http://pivotallabs.com
|
73
|
+
licenses:
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options:
|
76
|
+
- --main
|
77
|
+
- README.rdoc
|
78
|
+
- --inline-source
|
79
|
+
- --line-numbers
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: "0"
|
87
|
+
version:
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: "0"
|
93
|
+
version:
|
94
|
+
requirements: []
|
95
|
+
|
96
|
+
rubyforge_project: desert
|
97
|
+
rubygems_version: 1.3.5
|
98
|
+
signing_key:
|
99
|
+
specification_version: 2
|
100
|
+
summary: Desert is a component framework for Rails that allows your plugins to be packaged as mini Rails apps.
|
101
|
+
test_files: []
|
102
|
+
|