parlement 0.3 → 0.4

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 (122) hide show
  1. data/CHANGES +16 -0
  2. data/README +36 -3
  3. data/Rakefile +8 -12
  4. data/app/controllers/account_controller.rb +2 -0
  5. data/app/controllers/elt_controller.rb +1 -5
  6. data/app/controllers/subscriber_controller.rb +1 -1
  7. data/app/helpers/elt_helper.rb +30 -10
  8. data/app/models/elt.rb +2 -1
  9. data/app/models/mail.rb +41 -41
  10. data/app/models/mail_notify.rb +27 -10
  11. data/app/views/account/_login.rhtml +9 -7
  12. data/app/views/account/_show.rhtml +4 -4
  13. data/app/views/elt/_elt.rhtml +52 -51
  14. data/app/views/elt/_list.rhtml +22 -14
  15. data/app/views/elt/new.rhtml +1 -1
  16. data/app/views/elt/show.rhtml +15 -16
  17. data/app/views/layouts/top.rhtml +13 -1
  18. data/app/views/person/show.rhtml +1 -7
  19. data/config/boot.rb +32 -7
  20. data/config/database.yml +3 -0
  21. data/config/environment.rb +3 -1
  22. data/config/environments/development.rb +1 -1
  23. data/db/ROOT/parlement/ddRing.txt +14 -0
  24. data/db/ROOT/parlement/top-politics.txt +12 -0
  25. data/db/ROOT/perso.txt +1 -1
  26. data/db/development_structure.sql +30 -16
  27. data/db/schema.rb +18 -10
  28. data/db/schema.sql +34 -34
  29. data/public/javascripts/application.js +2 -0
  30. data/public/javascripts/blank.gif +0 -0
  31. data/public/javascripts/borders.js +687 -0
  32. data/public/javascripts/controls.js +95 -30
  33. data/public/javascripts/dragdrop.js +161 -21
  34. data/public/javascripts/effects.js +310 -211
  35. data/public/javascripts/ie7-load.htc +1 -0
  36. data/public/javascripts/prototype.js +228 -28
  37. data/test/fixtures/attachments.yml +3 -0
  38. data/test/fixtures/mail/mail_ruby +1 -0
  39. data/test/fixtures/people.yml +14 -0
  40. data/test/functional/account_controller_test.rb +3 -2
  41. data/test/unit/mail_notify_test.rb +2 -0
  42. data/test/unit/mail_test.rb +59 -6
  43. data/test/unit/person_test.rb +1 -1
  44. data/vendor/plugins/engines/CHANGELOG +92 -0
  45. data/vendor/plugins/engines/MIT-LICENSE +21 -0
  46. data/vendor/plugins/engines/README +325 -39
  47. data/vendor/plugins/engines/generators/engine/USAGE +26 -0
  48. data/vendor/plugins/engines/generators/engine/engine_generator.rb +199 -0
  49. data/vendor/plugins/engines/generators/engine/templates/README +85 -0
  50. data/vendor/plugins/engines/generators/engine/templates/init_engine.erb +13 -0
  51. data/vendor/plugins/engines/generators/engine/templates/install.erb +4 -0
  52. data/vendor/plugins/engines/generators/engine/templates/lib/engine.erb +6 -0
  53. data/vendor/plugins/engines/generators/engine/templates/licenses/GPL +18 -0
  54. data/vendor/plugins/engines/generators/engine/templates/licenses/LGPL +19 -0
  55. data/vendor/plugins/engines/generators/engine/templates/licenses/MIT +22 -0
  56. data/vendor/plugins/engines/generators/engine/templates/licenses/None +1 -0
  57. data/vendor/plugins/engines/generators/engine/templates/public/javascripts/engine.js +0 -0
  58. data/vendor/plugins/engines/generators/engine/templates/public/stylesheets/engine.css +0 -0
  59. data/vendor/plugins/engines/generators/engine/templates/tasks/engine.rake +0 -0
  60. data/vendor/plugins/engines/generators/engine/templates/test/test_helper.erb +13 -0
  61. data/vendor/plugins/engines/init.rb +18 -3
  62. data/vendor/plugins/engines/lib/bundles/require_resource.rb +124 -0
  63. data/vendor/plugins/engines/lib/bundles.rb +77 -0
  64. data/vendor/plugins/engines/lib/{action_mailer_extensions.rb → engines/action_mailer_extensions.rb} +15 -36
  65. data/vendor/plugins/engines/lib/{action_view_extensions.rb → engines/action_view_extensions.rb} +40 -33
  66. data/vendor/plugins/engines/lib/engines/active_record_extensions.rb +19 -0
  67. data/vendor/plugins/engines/lib/engines/dependencies_extensions.rb +118 -0
  68. data/vendor/plugins/engines/lib/engines/migration_extensions.rb +53 -0
  69. data/vendor/plugins/engines/lib/{ruby_extensions.rb → engines/ruby_extensions.rb} +14 -28
  70. data/vendor/plugins/engines/lib/engines/testing_extensions.rb +323 -0
  71. data/vendor/plugins/engines/lib/engines.rb +258 -148
  72. data/vendor/plugins/engines/tasks/engines.rake +161 -0
  73. data/vendor/plugins/engines/test/action_view_extensions_test.rb +9 -0
  74. data/vendor/plugins/engines/test/ruby_extensions_test.rb +24 -3
  75. data/vendor/plugins/guid/README.TXT +14 -4
  76. data/vendor/plugins/guid/init.rb +9 -2
  77. data/vendor/plugins/guid/lib/uuidtools.rb +22 -15
  78. data/vendor/plugins/login_engine/CHANGELOG +14 -0
  79. data/vendor/plugins/login_engine/README +93 -7
  80. data/vendor/plugins/login_engine/app/controllers/user_controller.rb +30 -20
  81. data/vendor/plugins/login_engine/app/helpers/user_helper.rb +1 -1
  82. data/vendor/plugins/login_engine/app/views/user/forgot_password.rhtml +2 -2
  83. data/vendor/plugins/login_engine/db/migrate/001_initial_schema.rb +25 -0
  84. data/vendor/plugins/login_engine/install.rb +4 -0
  85. data/vendor/plugins/login_engine/lib/login_engine/authenticated_system.rb +11 -5
  86. data/vendor/plugins/login_engine/lib/login_engine/authenticated_user.rb +15 -9
  87. data/vendor/plugins/login_engine/lib/login_engine.rb +7 -3
  88. data/vendor/plugins/login_engine/test/functional/user_controller_test.rb +22 -19
  89. data/vendor/plugins/login_engine/test/test_helper.rb +4 -8
  90. data/vendor/plugins/login_engine/test/unit/user_test.rb +31 -11
  91. metadata +60 -57
  92. data/app/models/attachment.rb +0 -6
  93. data/public/attachment/file/architecture.png +0 -0
  94. data/public/attachment/file/architecture.svg +0 -8972
  95. data/public/attachment/file/security.svg +0 -8960
  96. data/public/engine_files/login_engine/stylesheets/login_engine.css +0 -81
  97. data/public/oldREADME +0 -190
  98. data/public/stylesheets/default.css +0 -235
  99. data/public/stylesheets/live_tree.css +0 -62
  100. data/public/stylesheets/scaffold.css +0 -74
  101. data/script/about +0 -3
  102. data/script/benchmarker +0 -19
  103. data/script/breakpointer +0 -3
  104. data/script/console +0 -3
  105. data/script/create_db +0 -7
  106. data/script/destroy +0 -3
  107. data/script/generate +0 -3
  108. data/script/performance/benchmarker +0 -3
  109. data/script/performance/profiler +0 -3
  110. data/script/plugin +0 -3
  111. data/script/process/reaper +0 -3
  112. data/script/process/spawner +0 -3
  113. data/script/process/spinner +0 -3
  114. data/script/profiler +0 -34
  115. data/script/runner +0 -3
  116. data/script/server +0 -3
  117. data/test/unit/user_test.rb +0 -94
  118. data/vendor/plugins/engines/lib/dependencies_extensions.rb +0 -56
  119. data/vendor/plugins/engines/lib/testing_extensions.rb +0 -33
  120. data/vendor/plugins/login_engine/db/schema.rb +0 -25
  121. data/vendor/plugins/login_engine/test/fixtures/templates/users.yml +0 -41
  122. /data/public/images/{eltBackground.png → eltBackground.jng} +0 -0
@@ -1,35 +1,10 @@
1
- #--
2
- # Copyright (c) 2004 David Heinemeier Hansson
3
-
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
-
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
-
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #
23
- # Engine Hacks by James Adam, 2005.
24
- #++
25
-
26
1
  # Overriding ActionMailer to teach it about Engines...
27
2
  module ActionMailer
28
3
  class Base
29
4
 
30
5
  # Initialize the mailer via the given +method_name+. The body will be
31
6
  # rendered and a new TMail::Mail object created.
32
- def create!(method_name, *parameters) #:nodoc:
7
+ def old_create!(method_name, *parameters) #:nodoc:
33
8
  initialize_defaults(method_name)
34
9
  send(method_name, *parameters)
35
10
 
@@ -54,17 +29,19 @@ module ActionMailer
54
29
  # this loop expects an array of paths to actual template files which match
55
30
  # the given action name
56
31
  templates.each do |path|
57
- type = (File.basename(path).split(".")[1..-2] || []).join("/")
58
- #RAILS_DEFAULT_LOGGER.debug "type: #{type}"
59
- next if type.empty?
60
- #RAILS_DEFAULT_LOGGER.debug "other bit: #{File.basename(path).split(".")[0..-2].join('.')}"
61
- @parts << Part.new(:content_type => type,
32
+ # TODO: don't hardcode rhtml|rxml
33
+ basename = File.basename(path)
34
+ next unless md = /^([^\.]+)\.([^\.]+\.[^\+]+)\.(rhtml|rxml)$/.match(basename)
35
+
36
+ template_name = basename
37
+ content_type = md.captures[1].gsub('.', '/')
38
+
39
+ @parts << Part.new(:content_type => content_type,
62
40
  :disposition => "inline", :charset => charset,
63
- :body => render_message(File.basename(path).split(".")[0..-2].join('.'), @body))
41
+ :body => render_message(template_name, @body))
64
42
  end
65
43
  unless @parts.empty?
66
44
  @content_type = "multipart/alternative"
67
- @charset = nil
68
45
  @parts = sort_parts(@parts, @implicit_parts_order)
69
46
  end
70
47
  end
@@ -109,7 +86,7 @@ module ActionMailer
109
86
  # Return all ActionView template paths from the app and all Engines
110
87
  def template_paths
111
88
  paths = [template_path]
112
- Engines::ActiveEngines.each { |engine|
89
+ Engines.active.each { |engine|
113
90
  # add a path for every engine if one exists.
114
91
  engine_template_path = File.join(engine.root, "app", "views", mailer_name)
115
92
  paths << engine_template_path if File.exists?(engine_template_path)
@@ -124,7 +101,7 @@ module ActionMailer
124
101
  templates = []
125
102
  seen_names = []
126
103
  template_paths.each { |path|
127
- all_templates_for_path = Dir.glob(File.join(path, "#{action}.*"))
104
+ all_templates_for_path = Dir.glob(File.join(path, "#{action}*"))
128
105
  all_templates_for_path.each { |template|
129
106
  name = File.basename(template)
130
107
  if !seen_names.include?(name)
@@ -152,7 +129,9 @@ module ActionMailer
152
129
  # template root
153
130
  def initialize_template_class(assigns, method_name)
154
131
  engine_template = find_template_root_for(method_name)
155
- ActionView::Base.new(engine_template, assigns, self)
132
+ #ActionView::Base.new(engine_template, assigns, self)
133
+ action_view_class = Class.new(ActionView::Base).send(:include, master_helper_module)
134
+ action_view_class.new(engine_template, assigns, self)
156
135
  end
157
136
 
158
137
 
@@ -1,28 +1,3 @@
1
- #--
2
- # Copyright (c) 2004 David Heinemeier Hansson
3
-
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
-
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
-
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #
23
- # Engine Hacks by James Adam, 2005.
24
- #++
25
-
26
1
  require 'fileutils'
27
2
 
28
3
  module ::ActionView
@@ -37,7 +12,7 @@ module ::ActionView
37
12
 
38
13
  # Otherwise, check in the engines to see if the template can be found there.
39
14
  # Load this in order so that more recently started Engines will take priority.
40
- Engines::ActiveEngines.each do |engine|
15
+ Engines.active.each do |engine|
41
16
  site_specific_path = File.join(engine.root, 'app', 'views', template_path.to_s + '.' + extension.to_s)
42
17
  return site_specific_path if File.exist?(site_specific_path)
43
18
  end
@@ -91,20 +66,50 @@ module ::ActionView
91
66
  def engine_javascript(engine_name, *sources)
92
67
  javascript_include_tag(*convert_public_sources(engine_name, :javascript, sources))
93
68
  end
69
+
70
+ # Returns a image tag based on the parameters passed to it
71
+ # Required option is option[:engine] in order to correctly idenfity the correct engine location
72
+ #
73
+ # engine_image 'rails-engines.png', :engine => 'my_engine', :alt => 'My Engine' =>
74
+ # <img src="/engine_files/my_engine/images/rails-engines.png" alt="My Engine />
75
+ #
76
+ # Any options supplied as a Hash as the last argument will be processed as in
77
+ # image_tag.
78
+ #
79
+ def engine_image(src, options = {})
80
+ return if !src
81
+
82
+ image_src = engine_image_src(src, options)
83
+
84
+ options.delete(:engine)
85
+
86
+ image_tag(image_src, options)
87
+ end
88
+
89
+ # Alias for engine_image
90
+ def engine_image_tag(src, options = {})
91
+ engine_image(src, options)
92
+ end
93
+
94
+ # Returns a path to the image stored within the engine_files
95
+ # Required option is option[:engine] in order to correctly idenfity the correct engine location
96
+ #
97
+ # engine_image_src 'rails-engines.png', :engine => 'my_engine' =>
98
+ # "/engine_files/my_engine/images/rails-engines.png"
99
+ #
100
+ def engine_image_src(src, options = {})
101
+ File.join(Engines.get(options[:engine].to_sym).public_dir, 'images', src)
102
+ end
94
103
 
95
104
  private
96
105
  # convert the engine public file sources into actual public paths
97
106
  # type:
98
107
  # :stylesheet
99
108
  # :javascript
100
- # if engine_name does not end in engine, "_engine" is appended automatically.
101
109
  def convert_public_sources(engine_name, type, sources)
102
110
  options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { }
103
111
  new_sources = []
104
112
 
105
- full_engine_name = engine_name
106
- full_engine_name += "_engine" if !(engine_name =~ /\_engine$/)
107
-
108
113
  case type
109
114
  when :javascript
110
115
  type_dir = "javascripts"
@@ -114,17 +119,19 @@ module ::ActionView
114
119
  ext = "css"
115
120
  end
116
121
 
117
- default = "/#{Engines.config(:public_dir)}/#{full_engine_name}/#{type_dir}/#{engine_name}"
122
+ engine = Engines.get(engine_name)
123
+
124
+ default = "#{engine.public_dir}/#{type_dir}/#{engine_name}"
118
125
  if defined?(RAILS_ROOT) && File.exists?(File.join(RAILS_ROOT, "public", "#{default}.#{ext}"))
119
126
  new_sources << default
120
127
  end
121
128
 
122
129
  sources.each { |name|
123
- new_sources << "/#{Engines.config(:public_dir)}/#{full_engine_name}/#{type_dir}/#{name}"
130
+ new_sources << "#{engine.public_dir}/#{type_dir}/#{name}"
124
131
  }
125
132
 
126
133
  new_sources << options
127
134
  end
128
135
  end
129
136
  end
130
- end
137
+ end
@@ -0,0 +1,19 @@
1
+ module ::ActiveRecord
2
+ class Base
3
+ class << self
4
+
5
+ # NOTE: Currently the Migrations system will ALWAYS wrap given table names
6
+ # in the prefix/suffix, so any table name set via config(:table_name), for instnace
7
+ # will always get wrapped in the process of migration. For this reason, whatever
8
+ # value you give to the config will be wrapped when set_table_name is used in the
9
+ # model.
10
+
11
+ def wrapped_table_name(name)
12
+ table_name_prefix + name + table_name_suffix
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ # Set ActiveRecord to ignore the engine_schema_info table by default
19
+ ::ActiveRecord::SchemaDumper.ignore_tables << 'engine_schema_info'
@@ -0,0 +1,118 @@
1
+ module ::Dependencies
2
+
3
+ # we're going to intercept the require_or_load method; lets
4
+ # make an alias for the current method so we can use it as the basis
5
+ # for loading from engines.
6
+ alias :rails_pre_engines_require_or_load :require_or_load
7
+
8
+ def require_or_load(file_name)
9
+ if Engines.config(:edge)
10
+ rails_edge_require_or_load(file_name)
11
+ elsif Rails::VERSION::STRING =~ /^1.1/
12
+ # otherwise, assume we're on trunk (1.1 at the moment)
13
+ rails_1_1_require_or_load(file_name)
14
+ elsif Rails::VERSION::STRING =~ /^1.0/
15
+ # use the old dependency load method
16
+ rails_1_0_require_or_load(file_name)
17
+ end
18
+ end
19
+
20
+ def rails_edge_require_or_load(file_name)
21
+ rails_1_1_require_or_load(file_name)
22
+ end
23
+
24
+ def rails_1_1_require_or_load(file_name)
25
+ file_name = $1 if file_name =~ /^(.*)\.rb$/
26
+
27
+ Engines.log.debug("Engines 1.1 require_or_load: #{file_name}")
28
+
29
+ # try and load the engine code first
30
+ # can't use model, as there's nothing in the name to indicate that the file is a 'model' file
31
+ # rather than a library or anything else.
32
+ ['controller', 'helper'].each do |type|
33
+ # if we recognise this type
34
+ if file_name.include?('_' + type)
35
+
36
+ # ... go through the active engines from last started to first
37
+ Engines.active.each do |engine|
38
+
39
+ engine_file_name = File.expand_path(File.join(engine.root, 'app', "#{type}s", file_name))
40
+ engine_file_name = $1 if engine_file_name =~ /^(.*)\.rb$/
41
+ Engines.log.debug("- checking engine '#{engine.name}' for '#{engine_file_name}'")
42
+ if File.exist?("#{engine_file_name}.rb")
43
+ Engines.log.debug("==> loading from engine '#{engine.name}'")
44
+ rails_pre_engines_require_or_load(engine_file_name)
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ # finally, load any application-specific controller classes using the 'proper'
51
+ # rails load mechanism
52
+ rails_pre_engines_require_or_load(file_name)
53
+ end
54
+
55
+
56
+ def rails_1_0_require_or_load(file_name)
57
+ file_name = $1 if file_name =~ /^(.*)\.rb$/
58
+
59
+ Engines.log.debug "Engines 1.0.0 require_or_load '#{file_name}'"
60
+
61
+ # if the file_name ends in "_controller" or "_controller.rb", strip all
62
+ # path information out of it except for module context, and load it. Ditto
63
+ # for helpers.
64
+ if file_name =~ /_controller(.rb)?$/
65
+ require_engine_files(file_name, 'controller')
66
+ elsif file_name =~ /_helper(.rb)?$/ # any other files we can do this with?
67
+ require_engine_files(file_name, 'helper')
68
+ end
69
+
70
+ # finally, load any application-specific controller classes using the 'proper'
71
+ # rails load mechanism
72
+ Engines.log.debug("--> loading from application: '#{file_name}'")
73
+ rails_pre_engines_require_or_load(file_name)
74
+ Engines.log.debug("--> Done loading.")
75
+ end
76
+
77
+ # Load the given file (which should be a path to be matched from the root of each
78
+ # engine) from all active engines which have that file.
79
+ # NOTE! this method automagically strips file_name up to and including the first
80
+ # instance of '/app/controller'. This should correspond to the app/controller folder
81
+ # under RAILS_ROOT. However, if you have your Rails application residing under a
82
+ # path which includes /app/controller anyway, such as:
83
+ #
84
+ # /home/username/app/controller/my_web_application # == RAILS_ROOT
85
+ #
86
+ # then you might have trouble. Sorry, just please don't have your web application
87
+ # running under a path like that.
88
+ def require_engine_files(file_name, type='')
89
+ Engines.log.debug "requiring #{type} file '#{file_name}'"
90
+ processed_file_name = file_name.gsub(/[\w\W\/\.]*app\/#{type}s\//, '')
91
+ Engines.log.debug "--> rewrote to '#{processed_file_name}'"
92
+ Engines.active.reverse.each do |engine|
93
+ engine_file_name = File.join(engine.root, 'app', "#{type}s", processed_file_name)
94
+ engine_file_name += '.rb' unless ! load? || engine_file_name[-3..-1] == '.rb'
95
+ Engines.log.debug "--> checking '#{engine.name}' for #{engine_file_name}"
96
+ if File.exist?(engine_file_name) ||
97
+ (engine_file_name[-3..-1] != '.rb' && File.exist?(engine_file_name + '.rb'))
98
+ Engines.log.debug "--> found, loading from engine '#{engine.name}'"
99
+ rails_pre_engines_require_or_load(engine_file_name)
100
+ end
101
+ end
102
+ end
103
+ end
104
+
105
+
106
+ # We only need to deal with LoadingModules in Rails 1.0.0
107
+ if Rails::VERSION::STRING =~ /^1.0/ && !Engines.config(:edge)
108
+ module ::Dependencies
109
+ class RootLoadingModule < LoadingModule
110
+ # hack to allow adding to the load paths within the Rails Dependencies mechanism.
111
+ # this allows Engine classes to be unloaded and loaded along with standard
112
+ # Rails application classes.
113
+ def add_path(path)
114
+ @load_paths << (path.kind_of?(ConstantLoadPath) ? path : ConstantLoadPath.new(path))
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,53 @@
1
+ #require 'active_record/connection_adapters/abstract/schema_statements'
2
+
3
+ module ::ActiveRecord::ConnectionAdapters::SchemaStatements
4
+ alias :old_initialize_schema_information :initialize_schema_information
5
+ def initialize_schema_information
6
+ # create the normal schema stuff
7
+ old_initialize_schema_information
8
+
9
+ # create the engines schema stuff.
10
+ begin
11
+ execute "CREATE TABLE #{engine_schema_info_table_name} (engine_name #{type_to_sql(:string)}, version #{type_to_sql(:integer)})"
12
+ rescue ActiveRecord::StatementInvalid
13
+ # Schema has been initialized
14
+ end
15
+ end
16
+
17
+ def engine_schema_info_table_name
18
+ ActiveRecord::Base.wrapped_table_name "engine_schema_info"
19
+ end
20
+ end
21
+
22
+
23
+ require 'breakpoint'
24
+ module ::Engines
25
+ class EngineMigrator < ActiveRecord::Migrator
26
+
27
+ # We need to be able to set the 'current' engine being migrated.
28
+ cattr_accessor :current_engine
29
+
30
+ class << self
31
+
32
+ def schema_info_table_name
33
+ ActiveRecord::Base.wrapped_table_name "engine_schema_info"
34
+ end
35
+
36
+ def current_version
37
+ result = ActiveRecord::Base.connection.select_one("SELECT version FROM #{schema_info_table_name} WHERE engine_name = '#{current_engine.name}'")
38
+ if result
39
+ result["version"].to_i
40
+ else
41
+ # There probably isn't an entry for this engine in the migration info table.
42
+ # We need to create that entry, and set the version to 0
43
+ ActiveRecord::Base.connection.execute("INSERT INTO #{schema_info_table_name} (version, engine_name) VALUES (0,'#{current_engine.name}')")
44
+ 0
45
+ end
46
+ end
47
+ end
48
+
49
+ def set_schema_version(version)
50
+ ActiveRecord::Base.connection.update("UPDATE #{self.class.schema_info_table_name} SET version = #{down? ? version.to_i - 1 : version.to_i} WHERE engine_name = '#{self.current_engine.name}'")
51
+ end
52
+ end
53
+ end
@@ -1,26 +1,3 @@
1
- #--
2
- # Copyright (c) 2005 James Adam
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
23
-
24
1
  #--
25
2
  # Add these methods to the top-level module so that they are available in all
26
3
  # modules, etc
@@ -88,16 +65,25 @@ class ::Module
88
65
  # MyModule.config :param_two
89
66
  # => 98765
90
67
  #
68
+ # Configuration values can also be given as a Hash:
69
+ #
70
+ # MyModule.config :param1 => 'value1', :param2 => 'value2'
71
+ #
72
+ # Setting of these values can also be forced:
73
+ #
74
+ # MyModule.config :param1 => 'value3', :param2 => 'value4', :force => true
75
+ #
76
+ # A value of anything other than false or nil given for the :force key will
77
+ # result in the new values *always* being set.
91
78
  def config(*args)
92
79
 
93
80
  raise "config expects at least one argument" if args.empty?
94
81
 
95
82
  # extract the arguments
96
83
  if args[0].is_a?(Hash)
97
- # we can't override when using hash'd arguments since
98
- # if > 1 hash keys are given, it's impossible to tell which
99
- # one is the name of the option, and which is the override flag.
100
- args[0].each { |key, value| _handle_config(key, value)}
84
+ override = args[0][:force]
85
+ args[0].delete(:force)
86
+ args[0].each { |key, value| _handle_config(key, value, override)}
101
87
  else
102
88
  _handle_config(*args)
103
89
  end
@@ -124,4 +110,4 @@ class ::Module
124
110
  end
125
111
  end
126
112
  end
127
- end
113
+ end