oasis 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,8 @@
1
1
  module Oasis
2
2
  class Debug
3
3
  def self.log(msg)
4
- if defined? RAILS_DEFAULT_LOGGER
4
+ if defined? RAILS_DEFAULT_LOGGER && RAILS_ENV == "development"
5
5
  RAILS_DEFAULT_LOGGER.debug "** [OASIS] : #{msg}"
6
- else
7
- puts "** [OASIS] : #{msg}"
8
6
  end
9
7
  end
10
8
  end
@@ -5,64 +5,69 @@
5
5
  module Oasis
6
6
  module Dependencies
7
7
 
8
- def require_or_load(file_name, const_path=nil)
9
- super(file_name, const_path) unless defined? RAILS_ROOT
8
+ def require_or_load(file, const_path=nil)
9
+ super(file, const_path) unless defined? RAILS_ROOT
10
10
  file_loaded = false
11
- # only look for controller and helper files.
12
- %w(controller helper).each do |file_type|
13
- if file_name =~ /^(.*app\/#{file_type}s\/)?(.*_#{file_type})(\.rb)?$/
14
- base_name = $2
15
-
16
- # jump through the loaded/registered oasis apps, looking for
17
- # similar files that you may want to try to reference.
18
- Oasis.apps.each do |app|
19
- plugin_file_name = File.expand_path(File.join(app.directory, 'app', "#{file_type}s", base_name))
20
- Oasis::Debug.log "checking engine '#{app.name}' for '#{base_name}'"
21
- if File.file? "#{plugin_file_name}.rb"
22
- Oasis::Debug.log "loading from engine '#{app.name}'"
23
- file_loaded = true if super(plugin_file_name, const_path)
24
- end
25
- end
26
-
27
- # Ensure we are only loading from the /app directory at this point.
28
- app_file_name = File.join(RAILS_ROOT, 'app', "#{file_type}s", "#{base_name}")
29
-
30
- if File.file? "#{app_file_name}.rb"
31
- Oasis::Debug.log "loading from application: #{base_name}"
32
- file_loaded = true if super(app_file_name, const_path)
33
- else
34
- Oasis::Debug.log "file not found in application"
35
- end
11
+
12
+ plugin_file_name, app_file_name = "", ""
13
+ # get out the peices we want for them requirement.
14
+ file_name, base_name = extract_file_name(file), extract_base_name(file)
15
+
16
+ # start, by looking for the files as helpers or controllers
17
+ # if they are suffixed with helper or controller.
18
+ if file_name =~ /_(helper|controller)?$/
19
+ type = file_name.split("_").last
20
+ Oasis::Debug.log "searching for #{type} named '#{file_name}'"
21
+ Oasis.apps.each do |app|
22
+ plugin_file_name = File.expand_path(File.join(app.directory, "app", "#{type}s", base_name))
23
+ Oasis::Debug.log "checking engine '#{app.name}' for '#{file_name}' (#{plugin_file_name})"
24
+ break if File.file? "#{plugin_file_name}.rb"
36
25
  end
26
+
27
+ else
28
+
29
+ # if we didn't find it in helpers or controllers, lets try looking in models.
30
+ Oasis::Debug.log "searching for models named '#{file_name}'"
31
+ Oasis.apps.each do |app|
32
+ plugin_file_name = File.expand_path(File.join(app.directory, "app", "models", base_name))
33
+ Oasis::Debug.log "checking engine '#{app.name}' for '#{file_name}' (#{plugin_file_name})"
34
+ break if File.file? "#{plugin_file_name}.rb"
35
+ end
36
+
37
+ end
38
+
39
+ # success! we've found code in the engine, lets load it.
40
+ if File.file?("#{plugin_file_name}.rb")
41
+ Oasis::Debug.log "loading '#{file_name}' from an engine."
42
+ file_loaded = true if super(plugin_file_name, const_path)
43
+ end
44
+
45
+ app_file_name = File.join(RAILS_ROOT, "app", "#{type||"model"}s", base_name)
46
+ if File.file? "#{app_file_name}.rb"
47
+ Oasis::Debug.log "loading from application: #{file_name}"
48
+ file_loaded = true if super(app_file_name, const_path)
49
+ else
50
+ Oasis::Debug.log "file '#{file_name}' not found in application"
37
51
  end
38
52
 
39
53
  # if we managed to load a file, return true. If not, default to the original method.
40
54
  # Note that this relies on the RHS of a boolean || not to be evaluated if the LHS is true.
41
- file_loaded || super(file_name, const_path)
55
+ file_loaded || super(file, const_path)
56
+ end
57
+
58
+ private
59
+
60
+ def extract_base_name(file_name)
61
+ (file_name.split("/app/").last.split("/") - ["models", "controllers", "helpers"]).join("/").gsub(".rb","")
62
+ end
63
+
64
+ def extract_file_name(file_name)
65
+ file_name.split("/").last.gsub(".rb","")
42
66
  end
43
67
  end
44
-
45
68
  end
46
69
 
47
70
 
48
71
  module ::ActiveSupport::Dependencies #:nodoc:
49
72
  extend Oasis::Dependencies
50
- end
51
-
52
- class Object
53
- # shortcut for requiring models from rails engines.
54
- def require_model_from(app_name, constant_name)
55
- require_from(app_name,"app/models/#{constant_name}")
56
- end
57
-
58
- # this can be used to require something deep within a rails engine so that it
59
- # can be reopened properly. for instance, model files could now define
60
- # require_from :plugin_name, "app/models/foobar"
61
- # class Foobar
62
- #
63
- # def some_added_method ...
64
- def require_from(app_name, path)
65
- raise "#{app_name} has not been registered with Oasis." unless Oasis.apps[app_name]
66
- eval(%Q{require "#{Oasis.apps[app_name].directory}/#{path}"})
67
- end
68
73
  end
@@ -1,3 +1,3 @@
1
1
  module Oasis
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{oasis}
8
- s.version = "0.4.2"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Derek Perez", "Chris Eppstein"]
12
- s.date = %q{2010-01-08}
12
+ s.date = %q{2010-01-11}
13
13
  s.description = %q{a collection of enhancements for rails engines. Designed to work with Rails 2.3.}
14
14
  s.email = %q{derek@derekperez.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oasis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Perez
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-01-08 00:00:00 -08:00
13
+ date: 2010-01-11 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency