corrupt 0.3.6 → 0.3.7
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.
- data/Rakefile +4 -3
- data/app/models/page.rb +1 -1
- data/config.ru +9 -3
- data/lib/corrupt.rb +9 -1
- data/lib/corrupt/framework/controller.rb +2 -1
- data/lib/corrupt/generators/app.rb +4 -2
- data/lib/corrupt/router.rb +10 -11
- data/lib/corrupt/system.rb +7 -1
- data/spec/lib/corrupt/router_spec.rb +8 -1
- data/spec/spec_helper.rb +7 -3
- data/tasks/corrupt.rake +21 -0
- data/tasks/doc.rake +48 -0
- metadata +4 -2
data/Rakefile
CHANGED
@@ -3,10 +3,11 @@ task :default => 'spec'
|
|
3
3
|
task :environment do
|
4
4
|
ENV['CORRUPT_ENV'] ||= 'development'
|
5
5
|
begin
|
6
|
-
|
6
|
+
# Try to load from ./vendor first.
|
7
|
+
require File.dirname(__FILE__) + '/vendor/corrupt'
|
7
8
|
rescue LoadError
|
8
|
-
#
|
9
|
-
require
|
9
|
+
# Now try the gem.
|
10
|
+
require 'corrupt'
|
10
11
|
end
|
11
12
|
Corrupt.boot!
|
12
13
|
end
|
data/app/models/page.rb
CHANGED
data/config.ru
CHANGED
@@ -13,10 +13,16 @@ use Rack::Static, :urls => static_paths, :root => 'public'
|
|
13
13
|
ENV['CORRUPT_ENV'] ||= 'production'
|
14
14
|
|
15
15
|
begin
|
16
|
-
|
16
|
+
# Try to load from ./vendor first.
|
17
|
+
require File.join(Dir.pwd, 'vendor', 'corrupt')
|
17
18
|
rescue LoadError
|
18
|
-
#
|
19
|
-
|
19
|
+
# Now try the gem.
|
20
|
+
begin
|
21
|
+
require 'corrupt'
|
22
|
+
rescue LoadError
|
23
|
+
require 'rubygems'
|
24
|
+
require 'corrupt'
|
25
|
+
end
|
20
26
|
end
|
21
27
|
|
22
28
|
Corrupt.boot!
|
data/lib/corrupt.rb
CHANGED
@@ -26,7 +26,7 @@ require 'corrupt/generators'
|
|
26
26
|
require 'corrupt/framework/controller'
|
27
27
|
|
28
28
|
module Corrupt
|
29
|
-
VERSION = '0.3.
|
29
|
+
VERSION = '0.3.7'
|
30
30
|
|
31
31
|
# Setup the Corrupt environment. This just calls Corrupt::System.boot!
|
32
32
|
def self.boot!
|
@@ -40,28 +40,36 @@ module Corrupt
|
|
40
40
|
|
41
41
|
private
|
42
42
|
|
43
|
+
# Points to the root of the current Corrupt application.
|
43
44
|
def self.app_root
|
45
|
+
# FIXME: This is most certainly wrong. Dir.pwd should probably not be used here.
|
44
46
|
ENV['CORRUPT_APP'] || File.join(Dir.pwd, 'app')
|
45
47
|
end
|
46
48
|
|
49
|
+
# Returns the Corrupt::Config instance.
|
47
50
|
def self.config
|
48
51
|
Corrupt::Config
|
49
52
|
end
|
50
53
|
|
54
|
+
# Path to the application configuration file.
|
51
55
|
def self.config_file
|
52
56
|
ENV['CORRUPT_CONFIG'] || Corrupt.app_root + '/../config/app_config.yml'
|
53
57
|
end
|
54
58
|
|
59
|
+
# The current Corrupt environment (development, production, etc.)
|
60
|
+
# Defaults to 'development'.
|
55
61
|
def self.env
|
56
62
|
ENV['CORRUPT_ENV'] || 'development'
|
57
63
|
end
|
58
64
|
|
65
|
+
# Returns the logger instance.
|
59
66
|
def self.log
|
60
67
|
@log ||= Logger.new("#{Corrupt.app_root}/../log/#{Corrupt.env}.log")
|
61
68
|
@log.level = (Corrupt.env == 'production' ? Logger::WARN : Logger::DEBUG)
|
62
69
|
@log
|
63
70
|
end
|
64
71
|
|
72
|
+
# Returns the root path of the Corrupt library.
|
65
73
|
def self.root
|
66
74
|
ENV['CORRUPT_ROOT'] || File.expand_path(File.dirname(__FILE__) + '/..')
|
67
75
|
end
|
@@ -16,6 +16,7 @@ module Corrupt
|
|
16
16
|
end
|
17
17
|
|
18
18
|
# Return the headers for the response.
|
19
|
+
# TODO: Save the header hash and allow setting of custom keys.
|
19
20
|
def headers
|
20
21
|
{ 'Content-Length' => content.size.to_s,
|
21
22
|
'Content-Type' => 'text/html' }
|
@@ -32,7 +33,7 @@ module Corrupt
|
|
32
33
|
[status, headers, content]
|
33
34
|
end
|
34
35
|
|
35
|
-
# Set the template file to be rendered.
|
36
|
+
# Set the template file to be rendered or return the Corrupt::Template object.
|
36
37
|
def template(file = nil)
|
37
38
|
@template ||= Corrupt::Template.new(file)
|
38
39
|
end
|
@@ -4,7 +4,6 @@ module Corrupt
|
|
4
4
|
# Generator to create a new Corrupt application.
|
5
5
|
class App
|
6
6
|
|
7
|
-
# A list of directories to create when making a new application.
|
8
7
|
DIRS = [
|
9
8
|
'app',
|
10
9
|
'app/controllers',
|
@@ -28,7 +27,6 @@ module Corrupt
|
|
28
27
|
'tmp',
|
29
28
|
]
|
30
29
|
|
31
|
-
# A list of files to copy for a new application.
|
32
30
|
FILES = [
|
33
31
|
'config.ru',
|
34
32
|
'Rakefile',
|
@@ -68,6 +66,8 @@ module Corrupt
|
|
68
66
|
|
69
67
|
private
|
70
68
|
|
69
|
+
# This method is responsible for running the generator methods
|
70
|
+
# (creating directories, copying files, etc.).
|
71
71
|
def setup_app!
|
72
72
|
Dir.mkdir(@path) unless File.exists?(@path)
|
73
73
|
create_directories
|
@@ -76,12 +76,14 @@ module Corrupt
|
|
76
76
|
$stdout.puts "Application created in: #{@path}"
|
77
77
|
end
|
78
78
|
|
79
|
+
# Create a directory for each entry in +DIRS+.
|
79
80
|
def create_directories
|
80
81
|
DIRS.each do |dir|
|
81
82
|
Dir.mkdir(File.join(@path, dir))
|
82
83
|
end
|
83
84
|
end
|
84
85
|
|
86
|
+
# Copy each +FILES+ entry, preserving the path.
|
85
87
|
def copy_files
|
86
88
|
FILES.each do |file|
|
87
89
|
base_file = File.expand_path(File.join(Corrupt.root, file))
|
data/lib/corrupt/router.rb
CHANGED
@@ -8,15 +8,15 @@ module Corrupt
|
|
8
8
|
# route.map '/path', :controller => 'Kickass', :action => 'take_names'
|
9
9
|
# end
|
10
10
|
def initialize(&block)
|
11
|
-
@@routes =
|
11
|
+
@@routes = {}
|
12
12
|
yield self if block_given?
|
13
13
|
end
|
14
14
|
|
15
15
|
# Maps incoming URLs to a controller and action.
|
16
16
|
# TODO: Maybe change the routes storage to a hash like:
|
17
17
|
# @@routes[path] # => options
|
18
|
-
def map(path, options)
|
19
|
-
@@routes
|
18
|
+
def map(path, options = {})
|
19
|
+
@@routes[path] = options
|
20
20
|
end
|
21
21
|
|
22
22
|
# Return the configured routes.
|
@@ -24,17 +24,16 @@ module Corrupt
|
|
24
24
|
@@routes
|
25
25
|
end
|
26
26
|
|
27
|
-
# Dispatch
|
27
|
+
# Dispatch an incoming request +path+ to a controller and action.
|
28
28
|
def self.dispatch(path)
|
29
|
-
|
30
|
-
|
31
|
-
if route.empty?
|
32
|
-
Exceptions.new.four_oh_four
|
33
|
-
else
|
34
|
-
response = route[1] # 2nd element is the controller/action hash.
|
29
|
+
response = routes[path]
|
30
|
+
if response
|
35
31
|
Corrupt::Controller.const_get(response[:controller]).new.send(response[:action])
|
32
|
+
else
|
33
|
+
Exceptions.new.four_oh_four
|
36
34
|
end
|
37
35
|
end
|
38
|
-
|
36
|
+
|
37
|
+
end # Router
|
39
38
|
|
40
39
|
end # Corrupt
|
data/lib/corrupt/system.rb
CHANGED
@@ -21,10 +21,12 @@ module Corrupt
|
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
|
+
# Setup the Corrupt::Config instance.
|
24
25
|
def load_app_config
|
25
26
|
Corrupt::Config.setup(Corrupt.config_file)
|
26
27
|
end
|
27
28
|
|
29
|
+
# Load any application controllers.
|
28
30
|
def load_controllers
|
29
31
|
app_controller = "#{Corrupt.app_root}/controllers/app_controller.rb"
|
30
32
|
controllers = Dir["#{Corrupt.app_root}/controllers/*.rb"].sort
|
@@ -36,6 +38,7 @@ module Corrupt
|
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
41
|
+
# Load any application models.
|
39
42
|
def load_models
|
40
43
|
models = Dir["#{Corrupt.app_root}/models/*.rb"].sort
|
41
44
|
models.each do |model|
|
@@ -43,10 +46,13 @@ module Corrupt
|
|
43
46
|
end
|
44
47
|
end
|
45
48
|
|
49
|
+
# Load the application <tt>/config/routes.rb</tt>.
|
46
50
|
def prepare_router
|
47
|
-
load File.expand_path(
|
51
|
+
load File.expand_path(Corrupt.app_root + '/../config/routes.rb')
|
48
52
|
end
|
49
53
|
|
54
|
+
# Setup the database connection.
|
55
|
+
# TODO: This should only be ran if the application uses a database.
|
50
56
|
def setup_database
|
51
57
|
database = File.join(Corrupt.app_root, '..', Corrupt::Config['database'])
|
52
58
|
DataMapper.setup(:default, "sqlite3:///#{database}")
|
@@ -7,6 +7,13 @@ describe Router do
|
|
7
7
|
|
8
8
|
it 'should store the configured routes' do
|
9
9
|
@router.map '/', :controller => 'Main', :action => 'index'
|
10
|
-
|
10
|
+
@router.map '/kickass', :controller => 'Kickass', :action => 'take_names'
|
11
|
+
Router.routes.size.should == 2
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should respond to either /main or /main/' do
|
15
|
+
@router.map '/main', :controller => 'Main', :action => 'index'
|
16
|
+
get('/main')[0].should == 200
|
17
|
+
get('/main/')[0].should == 200
|
11
18
|
end
|
12
19
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'spec'
|
3
3
|
|
4
|
+
# TODO: This is kinda convoluted and stupid. Should just stick to one path for the specs.
|
4
5
|
begin
|
5
|
-
require 'corrupt'
|
6
|
+
require File.dirname(__FILE__) + '/../lib/corrupt'
|
6
7
|
rescue LoadError
|
7
|
-
|
8
|
-
|
8
|
+
begin
|
9
|
+
require File.dirname(__FILE__) + '/../vendor/corrupt/corrupt'
|
10
|
+
rescue LoadError
|
11
|
+
require 'corrupt'
|
12
|
+
end
|
9
13
|
end
|
10
14
|
|
11
15
|
ENV['CORRUPT_ENV'] = 'test'
|
data/tasks/corrupt.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
namespace :corrupt do
|
4
|
+
task :vendor_env do
|
5
|
+
@destination = 'vendor/corrupt'
|
6
|
+
@vendor_dir = File.dirname(__FILE__) + '/../vendor'
|
7
|
+
end
|
8
|
+
|
9
|
+
task :clean_vendor => [ :vendor_env ] do
|
10
|
+
FileUtils.rm_r(@destination) if File.exists?(@destination)
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'Freeze the Corrupt gem into ./vendor'
|
14
|
+
task :freeze => [ :clean_vendor ] do
|
15
|
+
`gem unpack corrupt --target #{@vendor_dir}`
|
16
|
+
FileUtils.mv(Dir['vendor/corrupt-*'].first, @destination)
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'Un-freeze the Corrupt gem (remove ./vendor/corrupt/)'
|
20
|
+
task :unfreeze => [ :clean_vendor ]
|
21
|
+
end
|
data/tasks/doc.rake
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
APP_ROOT = File.join(File.dirname(__FILE__), '..')
|
2
|
+
|
3
|
+
desc 'Generate API documentation'
|
4
|
+
task :doc do
|
5
|
+
Rake::Task['doc:api'].invoke
|
6
|
+
end
|
7
|
+
|
8
|
+
namespace :doc do
|
9
|
+
task :setup_rdoc do
|
10
|
+
@file_list = FileList[ "#{File.join(APP_ROOT, 'README')}",
|
11
|
+
"#{APP_ROOT}/app/**/*.rb",
|
12
|
+
"#{APP_ROOT}/lib/**/*.rb" ]
|
13
|
+
# Substitute APP_ROOT with a dot. Makes for a better index in the generated docs.
|
14
|
+
@files = @file_list.collect {|f| f.gsub(/#{APP_ROOT}/, '.')}
|
15
|
+
@options = %W[
|
16
|
+
--all
|
17
|
+
--inline-source
|
18
|
+
--line-numbers
|
19
|
+
--op #{File.join(APP_ROOT, 'doc', 'api')}
|
20
|
+
--title 'Corrupt API Documentation'
|
21
|
+
]
|
22
|
+
# Generate a diagram, yes/no?
|
23
|
+
@options << '-d' if RUBY_PLATFORM !~ /win32/ && `which dot` =~ /\/dot/ && !ENV['NODOT']
|
24
|
+
end
|
25
|
+
|
26
|
+
task :api => [:setup_rdoc] do
|
27
|
+
run_rdoc(@options, @files)
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'Remove generated API documentation'
|
31
|
+
task :clear do
|
32
|
+
sh "rm -rf #{File.join(APP_ROOT, 'doc', 'api')}"
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'Rebuild API documentation'
|
36
|
+
task :rebuild do
|
37
|
+
Rake::Task['doc:clear'].invoke
|
38
|
+
Rake::Task['doc:api'].invoke
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def run_rdoc(options, files)
|
45
|
+
options = options.join(' ') if options.is_a? Array
|
46
|
+
files = files.join(' ') if files.is_a? Array
|
47
|
+
sh "rdoc #{options} #{files}"
|
48
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: corrupt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dale Campbell
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-19 00:00:00 -05:00
|
13
13
|
default_executable: corrupt
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -86,6 +86,8 @@ files:
|
|
86
86
|
- spec/spec.opts
|
87
87
|
- spec/spec_helper.rb
|
88
88
|
- tasks/app.rake
|
89
|
+
- tasks/corrupt.rake
|
90
|
+
- tasks/doc.rake
|
89
91
|
- tasks/gem.rake
|
90
92
|
- tasks/notes.rake
|
91
93
|
- tasks/spec.rake
|