sharp 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/sharp CHANGED
@@ -3,7 +3,6 @@
3
3
  if ARGV[0] == "console"
4
4
  $:.unshift(File.expand_path("lib", Dir.pwd))
5
5
  require 'boot'
6
- Sharp.boot
7
6
  require 'irb'
8
7
  ARGV.clear
9
8
  IRB.start(Sharp.root)
data/lib/sharp.rb CHANGED
@@ -8,25 +8,25 @@ require "yaml"
8
8
  module Sharp
9
9
 
10
10
  class << self
11
+ attr_reader :app
11
12
  delegate :logger, :boot, :root, :router, :env, :db, :to => :app
13
+ delegate :routes, :to => :router
12
14
  end
13
15
 
14
- def self.app(*args, &init_routes)
15
- if args.length == 0
16
- @app
17
- else
18
- @app = Application.new(*args, &init_routes)
19
- end
16
+ def self.boot(root)
17
+ @app = Application.new(root)
18
+ @app.boot
19
+ @app
20
20
  end
21
21
 
22
22
  class Application
23
23
  attr_reader :root, :router
24
24
 
25
- def initialize(root, &init_routes)
25
+ def initialize(root)
26
26
  @root = Pathname.new(root)
27
- @init_routes = init_routes
28
27
  end
29
28
 
29
+ # TODO: Log to a file, command-line option for STDOUT
30
30
  def logger
31
31
  @logger ||= Logger.new(STDOUT)
32
32
  end
@@ -35,25 +35,17 @@ module Sharp
35
35
  if @booted
36
36
  false
37
37
  else
38
- preboot
39
- $:.unshift(root.join("lib/models"))
40
- Dir.glob(root.join("lib/models/*.rb")) {|file| require file }
41
- $:.unshift(root.join("lib/actions"))
42
- Dir.glob(root.join("lib/actions/*.rb")) {|file| require file }
43
- @booted = true
38
+ pre_boot
39
+ load_models
40
+ load_actions
41
+ load_routes
42
+ post_boot
43
+ finish_boot
44
44
  end
45
45
  end
46
46
 
47
- def preboot
48
- # A hook for plugins to add boot logic
49
- db # TODO: Pull out Sequel-specific code
50
- end
51
-
52
47
  def router
53
- @router ||= begin
54
- boot
55
- Rack::Router.new(&@init_routes)
56
- end
48
+ @router ||= Rack::Router.new
57
49
  end
58
50
 
59
51
  def env
@@ -74,5 +66,36 @@ module Sharp
74
66
  def db_config
75
67
  @db_config ||= YAML.load_file(root.join("config/database.yml")).symbolize_keys[env].symbolize_keys
76
68
  end
69
+
70
+ protected
71
+ def pre_boot
72
+ # A hook for plugins to add boot logic
73
+ db # TODO: Pull out Sequel-specific code
74
+ end
75
+
76
+ # TODO: Make an Array of load paths that you can add to that these are just part of
77
+ def load_models
78
+ $:.unshift(root.join("lib/models"))
79
+ Dir.glob(root.join("lib/models/*.rb")) {|file| require file }
80
+ end
81
+
82
+ def load_actions
83
+ Rack::Action.logger = logger
84
+ $:.unshift(root.join("lib/actions"))
85
+ Dir.glob(root.join("lib/actions/*.rb")) {|file| require file }
86
+ end
87
+
88
+ def load_routes
89
+ require "routes"
90
+ end
91
+
92
+ def post_boot
93
+ # A hook for plugins to add boot logic
94
+ end
95
+
96
+ def finish_boot
97
+ @booted = true
98
+ end
99
+
77
100
  end
78
101
  end
data/lib/sharp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sharp
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/sharp.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "sharp"
5
- gem.version = "0.0.1"
5
+ gem.version = "0.0.2"
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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: