sharp 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/sharp CHANGED
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  if ARGV[0] == "console"
4
- $:.unshift(File.expand_path("lib", Dir.pwd))
5
- require 'boot'
4
+ require File.expand_path('app/boot', Dir.pwd)
6
5
  require 'irb'
7
6
  ARGV.clear
8
7
  IRB.start(Sharp.root)
@@ -22,13 +22,14 @@ module Sharp
22
22
  class Application
23
23
  attr_reader :root, :router
24
24
 
25
- def initialize(root)
26
- @root = Pathname.new(root)
25
+ def self.boot(root)
26
+ app = new(root)
27
+ app.boot
28
+ app
27
29
  end
28
30
 
29
- # TODO: Log to a file, command-line option for STDOUT
30
- def logger
31
- @logger ||= Logger.new(STDOUT)
31
+ def initialize(root)
32
+ @root = Pathname.new(root)
32
33
  end
33
34
 
34
35
  def boot
@@ -36,6 +37,7 @@ module Sharp
36
37
  false
37
38
  else
38
39
  pre_boot
40
+ load_lib
39
41
  load_models
40
42
  load_actions
41
43
  load_routes
@@ -52,6 +54,27 @@ module Sharp
52
54
  @env ||= ENV['RACK_ENV'].present? ? ENV['RACK_ENV'].to_sym : :development
53
55
  end
54
56
 
57
+ # TODO: Log to a file, command-line option for STDOUT
58
+ def logger
59
+ @logger ||= begin
60
+ logger = Logger.new(STDOUT)
61
+ logger.formatter = logger_formatter
62
+ logger
63
+ end
64
+ end
65
+
66
+ def logger_formatter
67
+ @logger_formatter ||= proc do |severity, datetime, progname, msg|
68
+ color = case severity
69
+ when "ERROR" then '0;31'
70
+ when "WARN" then '1;33'
71
+ when "DEBUG" then '0;32'
72
+ else '1;37'
73
+ end
74
+ "\e[#{ color }m#{datetime} #{msg}\e[0;0m\n"
75
+ end
76
+ end
77
+
55
78
  #TODO: Pull out Sequel-specific code
56
79
  def db
57
80
  @db ||= begin
@@ -74,19 +97,24 @@ module Sharp
74
97
  end
75
98
 
76
99
  # TODO: Make an Array of load paths that you can add to that these are just part of
100
+ def load_lib
101
+ $:.unshift(root.join("app/lib"))
102
+ Dir.glob(root.join("app/lib/*.rb")) {|file| require file }
103
+ end
104
+
77
105
  def load_models
78
- $:.unshift(root.join("lib/models"))
79
- Dir.glob(root.join("lib/models/*.rb")) {|file| require file }
106
+ $:.unshift(root.join("app/models"))
107
+ Dir.glob(root.join("app/models/*.rb")) {|file| require file }
80
108
  end
81
109
 
82
110
  def load_actions
83
111
  Rack::Action.logger = logger
84
- $:.unshift(root.join("lib/actions"))
85
- Dir.glob(root.join("lib/actions/*.rb")) {|file| require file }
112
+ $:.unshift(root.join("app/actions"))
113
+ Dir.glob(root.join("app/actions/*.rb")) {|file| require file }
86
114
  end
87
115
 
88
116
  def load_routes
89
- require "routes"
117
+ require File.expand_path "app/routes", root
90
118
  end
91
119
 
92
120
  def post_boot
@@ -1,3 +1,3 @@
1
1
  module Sharp
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "sharp"
5
- gem.version = "0.0.2"
5
+ gem.version = "0.0.3"
6
6
  gem.authors = ["Paul Barry"]
7
7
  gem.email = ["mail@paulbarry.com"]
8
8
  gem.description = %q{A web framework}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sharp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: