joshnabbott-desert 0.3.5.2

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 (41) hide show
  1. data/CHANGES +36 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +316 -0
  4. data/Rakefile +106 -0
  5. data/generators/desert_plugin/USAGE +14 -0
  6. data/generators/desert_plugin/desert_plugin_generator.rb +73 -0
  7. data/generators/desert_plugin/templates/empty_file +0 -0
  8. data/generators/desert_plugin/templates/plugin_migration.rb +11 -0
  9. data/generators/desert_plugin/templates/routes.rb +4 -0
  10. data/generators/desert_plugin/templates/spec_helper.rb +8 -0
  11. data/init.rb +0 -0
  12. data/lib/desert/manager.rb +116 -0
  13. data/lib/desert/plugin.rb +74 -0
  14. data/lib/desert/plugin_migrations/1.2/extensions/schema_statements.rb +34 -0
  15. data/lib/desert/plugin_migrations/2.1/extensions/schema_statements.rb +30 -0
  16. data/lib/desert/plugin_migrations/migrator.rb +29 -0
  17. data/lib/desert/plugin_migrations.rb +11 -0
  18. data/lib/desert/plugin_templates/1.2.0/action_mailer.rb +21 -0
  19. data/lib/desert/plugin_templates/1.2.0/action_view.rb +53 -0
  20. data/lib/desert/plugin_templates/1.99.0/action_mailer.rb +25 -0
  21. data/lib/desert/plugin_templates/1.99.0/action_view.rb +38 -0
  22. data/lib/desert/plugin_templates/2.0.0/action_mailer.rb +23 -0
  23. data/lib/desert/plugin_templates/2.0.2/action_view.rb +26 -0
  24. data/lib/desert/plugin_templates/2.1.0/action_view.rb +13 -0
  25. data/lib/desert/plugin_templates/action_controller.rb +14 -0
  26. data/lib/desert/plugin_templates/action_view.rb +17 -0
  27. data/lib/desert/plugin_templates/edge/action_view.rb +10 -0
  28. data/lib/desert/plugin_templates.rb +10 -0
  29. data/lib/desert/rails/1.2.0/initializer.rb +20 -0
  30. data/lib/desert/rails/2.0.0/plugin.rb +22 -0
  31. data/lib/desert/rails/dependencies.rb +87 -0
  32. data/lib/desert/rails/migration.rb +36 -0
  33. data/lib/desert/rails/observer.rb +22 -0
  34. data/lib/desert/rails/route_set.rb +23 -0
  35. data/lib/desert/rails.rb +11 -0
  36. data/lib/desert/ruby/object.rb +34 -0
  37. data/lib/desert/ruby.rb +2 -0
  38. data/lib/desert/supported_rails_versions.rb +11 -0
  39. data/lib/desert/version_checker.rb +26 -0
  40. data/lib/desert.rb +14 -0
  41. metadata +95 -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,22 @@
1
+ module Desert
2
+ module Rails
3
+ module Observer
4
+ def self.observers=(*observers)
5
+ @observers = observers.flatten
6
+ end
7
+ def self.observers
8
+ @observers ||= []
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ class Rails::Initializer
15
+ def load_observers_with_desert
16
+ # todo verify if this should be logged
17
+ puts "Adding #{Desert::Rails::Observer.observers.inspect} to #{ActiveRecord::Base.observers.inspect}"
18
+ ActiveRecord::Base.observers += Desert::Rails::Observer.observers.uniq
19
+ load_observers_without_desert
20
+ end
21
+ alias_method_chain :load_observers, :desert
22
+ 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>/desert_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
@@ -0,0 +1,11 @@
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"
11
+ require "#{dir}/rails/observer"
@@ -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
@@ -0,0 +1,2 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/ruby/object"
@@ -0,0 +1,11 @@
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
+ # "edge" => {'version' => 'edge', 'git_tag' => 'master'},
10
+ }
11
+ end
@@ -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,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: joshnabbott-desert
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.5.2
5
+ platform: ruby
6
+ authors:
7
+ - Pivotal Labs
8
+ - Josh N. Abbott
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2008-09-08 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Desert is a component framework for Rails that allows your plugins to be packaged as mini Rails apps.
18
+ email: joshnabbott@gmail.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - CHANGES
27
+ - MIT-LICENSE
28
+ - Rakefile
29
+ - README.rdoc
30
+ - init.rb
31
+ - lib/desert/manager.rb
32
+ - lib/desert/plugin.rb
33
+ - lib/desert/plugin_migrations/2.1/extensions/schema_statements.rb
34
+ - lib/desert/plugin_migrations/1.2/extensions/schema_statements.rb
35
+ - lib/desert/plugin_migrations/migrator.rb
36
+ - lib/desert/plugin_migrations.rb
37
+ - lib/desert/plugin_templates/1.2.0/action_mailer.rb
38
+ - lib/desert/plugin_templates/1.2.0/action_view.rb
39
+ - lib/desert/plugin_templates/1.99.0/action_mailer.rb
40
+ - lib/desert/plugin_templates/1.99.0/action_view.rb
41
+ - lib/desert/plugin_templates/2.0.0/action_mailer.rb
42
+ - lib/desert/plugin_templates/2.0.2/action_view.rb
43
+ - lib/desert/plugin_templates/2.1.0/action_view.rb
44
+ - lib/desert/plugin_templates/action_controller.rb
45
+ - lib/desert/plugin_templates/action_view.rb
46
+ - lib/desert/plugin_templates/edge/action_view.rb
47
+ - lib/desert/plugin_templates.rb
48
+ - lib/desert/rails/1.2.0/initializer.rb
49
+ - lib/desert/rails/2.0.0/plugin.rb
50
+ - lib/desert/rails/dependencies.rb
51
+ - lib/desert/rails/migration.rb
52
+ - lib/desert/rails/observer.rb
53
+ - lib/desert/rails/route_set.rb
54
+ - lib/desert/rails.rb
55
+ - lib/desert/ruby/object.rb
56
+ - lib/desert/ruby.rb
57
+ - lib/desert/supported_rails_versions.rb
58
+ - lib/desert/version_checker.rb
59
+ - lib/desert.rb
60
+ - generators/desert_plugin
61
+ - generators/desert_plugin/desert_plugin_generator.rb
62
+ - generators/desert_plugin/templates
63
+ - generators/desert_plugin/templates/empty_file
64
+ - generators/desert_plugin/templates/plugin_migration.rb
65
+ - generators/desert_plugin/templates/routes.rb
66
+ - generators/desert_plugin/templates/spec_helper.rb
67
+ - generators/desert_plugin/USAGE
68
+ has_rdoc: true
69
+ homepage: http://pivotallabs.com
70
+ post_install_message:
71
+ rdoc_options: []
72
+
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ version:
87
+ requirements: []
88
+
89
+ rubyforge_project: desert
90
+ rubygems_version: 1.2.0
91
+ signing_key:
92
+ specification_version: 2
93
+ summary: Desert is a component framework for Rails that allows your plugins to be packaged as mini Rails apps.
94
+ test_files: []
95
+