oasis 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  require 'active_support/core_ext/module'
2
2
  require "oasis/version"
3
- require "oasis/debug"
3
+ require "oasis/logger"
4
4
  require "oasis/app/list"
5
5
  require "oasis/app/loader"
6
6
  require "oasis/dependencies"
@@ -7,7 +7,7 @@ module Oasis
7
7
  def register_plugin_as_loaded_with_oasis(plugin)
8
8
  register_plugin_as_loaded_without_oasis(plugin)
9
9
  Oasis.apps << plugin if plugin.engine?
10
- Oasis::Debug.log "Loading Rails App: #{plugin.name}"
10
+ Oasis::Logger.trace "Loading Rails App: #{plugin.name}"
11
11
  end
12
12
 
13
13
  def self.included(base)
@@ -17,20 +17,20 @@ module Oasis
17
17
  # if they are suffixed with helper or controller.
18
18
  if file_name =~ /_(helper|controller)?$/
19
19
  type = file_name.split("_").last
20
- Oasis::Debug.log "searching for #{type} named '#{file_name}'"
20
+ Oasis::Logger.trace "searching for #{type} named '#{file_name}'"
21
21
  Oasis.apps.each do |app|
22
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})"
23
+ Oasis::Logger.trace "checking engine '#{app.name}' for '#{file_name}' (#{plugin_file_name})"
24
24
  break if File.file? "#{plugin_file_name}.rb"
25
25
  end
26
26
 
27
27
  else
28
28
 
29
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}'"
30
+ Oasis::Logger.trace "searching for models named '#{file_name}'"
31
31
  Oasis.apps.each do |app|
32
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})"
33
+ Oasis::Logger.trace "checking engine '#{app.name}' for '#{file_name}' (#{plugin_file_name})"
34
34
  break if File.file? "#{plugin_file_name}.rb"
35
35
  end
36
36
 
@@ -38,16 +38,16 @@ module Oasis
38
38
 
39
39
  # success! we've found code in the engine, lets load it.
40
40
  if File.file?("#{plugin_file_name}.rb")
41
- Oasis::Debug.log "loading '#{file_name}' from an engine."
41
+ Oasis::Logger.debug "loading '#{file_name}' from an engine."
42
42
  file_loaded = true if super(plugin_file_name, const_path)
43
43
  end
44
44
 
45
45
  app_file_name = File.join(RAILS_ROOT, "app", "#{type||"model"}s", base_name)
46
46
  if File.file? "#{app_file_name}.rb"
47
- Oasis::Debug.log "loading from application: #{file_name}"
47
+ Oasis::Logger.trace "loading from application: #{file_name}"
48
48
  file_loaded = true if super(app_file_name, const_path)
49
49
  else
50
- Oasis::Debug.log "file '#{file_name}' not found in application"
50
+ Oasis::Logger.trace "file '#{file_name}' not found in application"
51
51
  end
52
52
 
53
53
  # if we managed to load a file, return true. If not, default to the original method.
@@ -0,0 +1,40 @@
1
+ module Oasis
2
+ class Logger
3
+ LOG_LEVELS = {
4
+ :trace => 1,
5
+ :debug => 2,
6
+ :warn => 3
7
+ }.freeze
8
+ RAILS_LOG_METHOD = {
9
+ :trace => :debug,
10
+ :debug => :debug,
11
+ :warn => :warn
12
+ }.freeze
13
+ class << self
14
+ def level
15
+ @level || :warn
16
+ end
17
+ def level=(v)
18
+ unless LOG_LEVELS.has_key?(v)
19
+ errmsg = "#{v.inspect} is not a log level. Please use one of #{LOG_LEVELS.keys.map(&:inspect).join(", ")}"
20
+ raise ArgumentError, errmsg
21
+ end
22
+ @level = v
23
+ end
24
+ def trace(msg); log(msg, :trace); end
25
+ def debug(msg); log(msg, :debug); end
26
+ def warn(msg); log(msg, :warn); end
27
+ def log(msg, level)
28
+ return unless LOG_LEVELS[level] >= LOG_LEVELS[self.level]
29
+ msg = "** [OASIS] : #{msg}"
30
+ if defined?(Rails)
31
+ Rails.logger.send(RAILS_LOG_METHOD[level], msg)
32
+ elsif defined?(RAILS_DEFAULT_LOGGER)
33
+ RAILS_DEFAULT_LOGGER.send(RAILS_LOG_METHOD[level], msg)
34
+ else
35
+ $stderr.puts msg
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -6,7 +6,7 @@ module Oasis
6
6
  cattr_accessor :apps
7
7
  def self.routing_for(name, &blk)
8
8
  self.apps[name] = blk
9
- Debug.log "loaded routes for app: #{name}"
9
+ Oasis::Logger.debug "loaded routes for app: #{name}"
10
10
  end
11
11
 
12
12
  def self.reset!
@@ -1,3 +1,3 @@
1
1
  module Oasis
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
3
3
  end
@@ -24,7 +24,7 @@ require 'oasis'
24
24
 
25
25
  # silence the logger, or define a new path for logging.
26
26
  module Oasis
27
- class Debug
27
+ class Logger
28
28
  def self.log(*args)
29
29
  nil
30
30
  end
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.5.2
4
+ version: 0.5.3
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-27 00:00:00 -08:00
13
+ date: 2010-02-08 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -42,11 +42,11 @@ files:
42
42
  - lib/oasis/app/list.rb
43
43
  - lib/oasis/app/loader.rb
44
44
  - lib/oasis/configure.rb
45
- - lib/oasis/debug.rb
46
45
  - lib/oasis/dependencies.rb
47
46
  - lib/oasis/development.rb
48
47
  - lib/oasis/layout.rb
49
48
  - lib/oasis/loader.rb
49
+ - lib/oasis/logger.rb
50
50
  - lib/oasis/routes.rb
51
51
  - lib/oasis/version.rb
52
52
  - oasis.gemspec
@@ -1,9 +0,0 @@
1
- module Oasis
2
- class Debug
3
- def self.log(msg)
4
- if defined? RAILS_DEFAULT_LOGGER && RAILS_ENV == "development"
5
- RAILS_DEFAULT_LOGGER.debug "** [OASIS] : #{msg}"
6
- end
7
- end
8
- end
9
- end