Capcode 0.8.9 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +13 -1
- data/doc/rdoc/classes/Capcode.html +410 -545
- data/doc/rdoc/classes/Capcode/Configuration.html +263 -0
- data/doc/rdoc/classes/Capcode/Helpers.html +154 -345
- data/doc/rdoc/classes/Capcode/Helpers/Authorization.html +6 -6
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/README_rdoc.html +42 -2
- data/doc/rdoc/files/lib/capcode/configuration_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode/render/text_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode_rb.html +14 -1
- data/doc/rdoc/fr_class_index.html +1 -1
- data/doc/rdoc/fr_file_index.html +0 -13
- data/doc/rdoc/fr_method_index.html +12 -14
- data/examples/render-image.rb +1 -1
- data/examples/render-text.rb +4 -1
- data/examples/rest.rb +1 -0
- data/examples/sample.rb +5 -3
- data/examples/upload.rb +1 -0
- data/lib/capcode.rb +45 -61
- data/lib/capcode/configuration.rb +69 -34
- data/lib/capcode/render/text.rb +1 -1
- data/lib/capcode/version.rb +1 -1
- metadata +31 -106
- data/doc/rdoc/classes/Capcode/Mab.html +0 -118
- data/doc/rdoc/files/lib/capcode/render/binary_rb.html +0 -101
- data/doc/rdoc/files/lib/capcode/render/email_rb.html +0 -108
- data/doc/rdoc/files/lib/capcode/render/erb_rb.html +0 -108
- data/doc/rdoc/files/lib/capcode/render/haml_rb.html +0 -108
- data/doc/rdoc/files/lib/capcode/render/json_rb.html +0 -108
- data/doc/rdoc/files/lib/capcode/render/markaby_rb.html +0 -108
- data/doc/rdoc/files/lib/capcode/render/mustache_rb.html +0 -108
- data/doc/rdoc/files/lib/capcode/render/none_rb.html +0 -101
- data/doc/rdoc/files/lib/capcode/render/redirect_rb.html +0 -101
- data/doc/rdoc/files/lib/capcode/render/sass_rb.html +0 -108
- data/doc/rdoc/files/lib/capcode/render/static_rb.html +0 -101
- data/doc/rdoc/files/lib/capcode/render/webdav_rb.html +0 -124
- data/doc/rdoc/files/lib/capcode/render/xml_rb.html +0 -101
- data/examples/auth-webdav.rb +0 -29
- data/examples/blog-ar.rb +0 -81
- data/examples/blog-ar.yml +0 -3
- data/examples/blog-couchdb-run.rb +0 -10
- data/examples/blog-couchdb.rb +0 -314
- data/examples/blog-couchdb.ru +0 -12
- data/examples/blog-couchdb.yml +0 -2
- data/examples/blog-dm.rb +0 -63
- data/examples/blog-dm.yml +0 -2
- data/examples/blog-mongodb-run.rb +0 -10
- data/examples/blog-mongodb.rb +0 -304
- data/examples/blog-mongodb.yml +0 -3
- data/examples/blog-sq.rb +0 -82
- data/examples/blog-sq.yml +0 -3
- data/examples/mail/mail_html.rhtml +0 -1
- data/examples/mail/mail_text.rhtml +0 -1
- data/examples/mail/ok.rhtml +0 -1
- data/examples/mail/rubyfr.png +0 -0
- data/examples/mustache/with_class.mustache +0 -8
- data/examples/mustache/without_class.mustache +0 -1
- data/examples/render-binary.rb +0 -46
- data/examples/render-email.rb +0 -68
- data/examples/render-erb.rb +0 -19
- data/examples/render-haml_sass.rb +0 -26
- data/examples/render-json.rb +0 -13
- data/examples/render-markaby.rb +0 -29
- data/examples/render-mustache.rb +0 -30
- data/examples/render-redirect.rb +0 -19
- data/examples/render-static.rb +0 -21
- data/examples/render-static.ru +0 -19
- data/examples/render-use.rb +0 -32
- data/examples/render-webdav.rb +0 -26
- data/examples/render-xml.rb +0 -24
- data/examples/rss.rb +0 -48
- data/examples/static/coderay.css +0 -131
- data/examples/static/index.html +0 -24
- data/examples/test/index.html +0 -1
- data/lib/capcode/base/ar.rb +0 -54
- data/lib/capcode/base/couchdb.rb +0 -23
- data/lib/capcode/base/dm.rb +0 -33
- data/lib/capcode/base/mongodb.rb +0 -27
- data/lib/capcode/base/sq.rb +0 -58
- data/lib/capcode/render/binary.rb +0 -8
- data/lib/capcode/render/email.rb +0 -73
- data/lib/capcode/render/erb.rb +0 -59
- data/lib/capcode/render/haml.rb +0 -60
- data/lib/capcode/render/json.rb +0 -14
- data/lib/capcode/render/markaby.rb +0 -38
- data/lib/capcode/render/mustache.rb +0 -37
- data/lib/capcode/render/none.rb +0 -7
- data/lib/capcode/render/redirect.rb +0 -7
- data/lib/capcode/render/sass.rb +0 -48
- data/lib/capcode/render/static.rb +0 -14
- data/lib/capcode/render/webdav.rb +0 -49
- data/lib/capcode/render/xml.rb +0 -119
data/examples/render-webdav.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
$:.unshift( "../lib" )
|
2
|
-
require 'capcode'
|
3
|
-
require 'capcode/render/webdav'
|
4
|
-
|
5
|
-
module Capcode
|
6
|
-
|
7
|
-
# Render file from /Users/greg/temp !!!
|
8
|
-
class WebDav < Route '/temp'
|
9
|
-
def get
|
10
|
-
render :webdav => "/Users/greg"
|
11
|
-
end
|
12
|
-
|
13
|
-
def method_missing(id, *a, &b)
|
14
|
-
get
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class Index < Route '/'
|
19
|
-
def get
|
20
|
-
render "WebDav server acces : <a href='#{URL(Capcode::WebDav)}'>#{URL(Capcode::WebDav)}</a>"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
Capcode.run( )
|
data/examples/render-xml.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
$:.unshift( "../lib" )
|
2
|
-
require 'capcode'
|
3
|
-
require 'capcode/render/xml'
|
4
|
-
|
5
|
-
module Capcode
|
6
|
-
class Index < Route '/'
|
7
|
-
def get
|
8
|
-
render :xml => :index
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
module Capcode::Views
|
14
|
-
def index
|
15
|
-
xml? :version => '1.0'
|
16
|
-
html do
|
17
|
-
body do
|
18
|
-
h1 "Hello XML !"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
Capcode.run( )
|
data/examples/rss.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
$:.unshift( "../lib" )
|
2
|
-
require 'rubygems'
|
3
|
-
require 'capcode'
|
4
|
-
require 'capcode/render/xml'
|
5
|
-
|
6
|
-
## !! THIS IS JUSTE FOR THIS EXAMPLE !!
|
7
|
-
class Hash
|
8
|
-
def method_missing( id, *a )
|
9
|
-
self[id.id2name.to_sym]
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
module Capcode
|
14
|
-
class RSS < Route "/rss"
|
15
|
-
def get
|
16
|
-
@posts = [
|
17
|
-
{ :title => "Welcome", :body => "This is a RSS example for Capcode!", :iid => 1, :created_at => Time.now() },
|
18
|
-
{ :title => "Just For Fun", :body => "See more examples on the Capcode Website...", :iid => 2, :created_at => Time.now() },
|
19
|
-
]
|
20
|
-
render :xml => :rss_view
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
module Capcode::Views
|
26
|
-
def rss_view
|
27
|
-
xml? :version => '1.0'
|
28
|
-
rss :version => "2.0" do
|
29
|
-
channel do
|
30
|
-
title "Capcode News"
|
31
|
-
description "Capcode Framework."
|
32
|
-
link "http://example.com/"
|
33
|
-
|
34
|
-
@posts.each do |post|
|
35
|
-
item do
|
36
|
-
title post.title
|
37
|
-
link "http://example.com/posts/#{post.iid}"
|
38
|
-
description post.body
|
39
|
-
pubDate Time.parse(post.created_at.to_s).rfc822()
|
40
|
-
guid "http://example.com/posts/#{post.iid}"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
Capcode.run()
|
data/examples/static/coderay.css
DELETED
@@ -1,131 +0,0 @@
|
|
1
|
-
.CodeRay {
|
2
|
-
background-color: #f8f8f8;
|
3
|
-
border: 1px solid silver;
|
4
|
-
font-family: 'Courier New', 'Terminal', monospace;
|
5
|
-
color: #000;
|
6
|
-
}
|
7
|
-
.CodeRay pre { margin: 0px }
|
8
|
-
|
9
|
-
div.CodeRay { }
|
10
|
-
|
11
|
-
span.CodeRay { white-space: pre; border: 0px; padding: 2px }
|
12
|
-
|
13
|
-
table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px }
|
14
|
-
table.CodeRay td { padding: 2px 4px; vertical-align: top }
|
15
|
-
|
16
|
-
.CodeRay .line_numbers, .CodeRay .no {
|
17
|
-
background-color: #def;
|
18
|
-
color: gray;
|
19
|
-
text-align: right;
|
20
|
-
}
|
21
|
-
.CodeRay .line_numbers tt { font-weight: bold }
|
22
|
-
.CodeRay .line_numbers .highlighted { color: red }
|
23
|
-
.CodeRay .no { padding: 0px 4px }
|
24
|
-
.CodeRay .code { width: 100% }
|
25
|
-
|
26
|
-
ol.CodeRay { font-size: 10pt }
|
27
|
-
ol.CodeRay li { white-space: pre }
|
28
|
-
|
29
|
-
.CodeRay .code pre { overflow: auto }
|
30
|
-
|
31
|
-
.CodeRay .debug { color:white ! important; background:blue ! important; }
|
32
|
-
|
33
|
-
.CodeRay .af { color:#00C }
|
34
|
-
.CodeRay .an { color:#007 }
|
35
|
-
.CodeRay .at { color:#f08 }
|
36
|
-
.CodeRay .av { color:#700 }
|
37
|
-
.CodeRay .aw { color:#C00 }
|
38
|
-
.CodeRay .bi { color:#509; font-weight:bold }
|
39
|
-
.CodeRay .c { color:#888; }
|
40
|
-
|
41
|
-
.CodeRay .ch { color:#04D }
|
42
|
-
.CodeRay .ch .k { color:#04D }
|
43
|
-
.CodeRay .ch .dl { color:#039 }
|
44
|
-
|
45
|
-
.CodeRay .cl { color:#B06; font-weight:bold }
|
46
|
-
.CodeRay .cm { color:#A08; font-weight:bold }
|
47
|
-
.CodeRay .co { color:#036; font-weight:bold }
|
48
|
-
.CodeRay .cr { color:#0A0 }
|
49
|
-
.CodeRay .cv { color:#369 }
|
50
|
-
.CodeRay .de { color:#B0B; }
|
51
|
-
.CodeRay .df { color:#099; font-weight:bold }
|
52
|
-
.CodeRay .di { color:#088; font-weight:bold }
|
53
|
-
.CodeRay .dl { color:black }
|
54
|
-
.CodeRay .do { color:#970 }
|
55
|
-
.CodeRay .dt { color:#34b }
|
56
|
-
.CodeRay .ds { color:#D42; font-weight:bold }
|
57
|
-
.CodeRay .e { color:#666; font-weight:bold }
|
58
|
-
.CodeRay .en { color:#800; font-weight:bold }
|
59
|
-
.CodeRay .er { color:#F00; background-color:#FAA }
|
60
|
-
.CodeRay .ex { color:#F00; font-weight:bold }
|
61
|
-
.CodeRay .fl { color:#60E; font-weight:bold }
|
62
|
-
.CodeRay .fu { color:#06B; font-weight:bold }
|
63
|
-
.CodeRay .gv { color:#d70; font-weight:bold }
|
64
|
-
.CodeRay .hx { color:#058; font-weight:bold }
|
65
|
-
.CodeRay .i { color:#00D; font-weight:bold }
|
66
|
-
.CodeRay .ic { color:#B44; font-weight:bold }
|
67
|
-
|
68
|
-
.CodeRay .il { background: #ddd; color: black }
|
69
|
-
.CodeRay .il .il { background: #ccc }
|
70
|
-
.CodeRay .il .il .il { background: #bbb }
|
71
|
-
.CodeRay .il .idl { background: #ddd; font-weight: bold; color: #666 }
|
72
|
-
.CodeRay .idl { background-color: #bbb; font-weight: bold; color: #666; }
|
73
|
-
|
74
|
-
.CodeRay .im { color:#f00; }
|
75
|
-
.CodeRay .in { color:#B2B; font-weight:bold }
|
76
|
-
.CodeRay .iv { color:#33B }
|
77
|
-
.CodeRay .la { color:#970; font-weight:bold }
|
78
|
-
.CodeRay .lv { color:#963 }
|
79
|
-
.CodeRay .oc { color:#40E; font-weight:bold }
|
80
|
-
.CodeRay .of { color:#000; font-weight:bold }
|
81
|
-
.CodeRay .op { }
|
82
|
-
.CodeRay .pc { color:#038; font-weight:bold }
|
83
|
-
.CodeRay .pd { color:#369; font-weight:bold }
|
84
|
-
.CodeRay .pp { color:#579; }
|
85
|
-
.CodeRay .ps { color:#00C; font-weight: bold; }
|
86
|
-
.CodeRay .pt { color:#349; font-weight:bold }
|
87
|
-
.CodeRay .r, .kw { color:#080; font-weight:bold }
|
88
|
-
|
89
|
-
.CodeRay .ke { color: #808; }
|
90
|
-
.CodeRay .ke .dl { color: #606; }
|
91
|
-
.CodeRay .ke .ch { color: #80f; }
|
92
|
-
.CodeRay .vl { color: #088; }
|
93
|
-
|
94
|
-
.CodeRay .rx { background-color:#fff0ff }
|
95
|
-
.CodeRay .rx .k { color:#808 }
|
96
|
-
.CodeRay .rx .dl { color:#404 }
|
97
|
-
.CodeRay .rx .mod { color:#C2C }
|
98
|
-
.CodeRay .rx .fu { color:#404; font-weight: bold }
|
99
|
-
|
100
|
-
.CodeRay .s { background-color:#fff0f0; color: #D20; }
|
101
|
-
.CodeRay .s .s { background-color:#ffe0e0 }
|
102
|
-
.CodeRay .s .s .s { background-color:#ffd0d0 }
|
103
|
-
.CodeRay .s .k { }
|
104
|
-
.CodeRay .s .ch { color: #b0b; }
|
105
|
-
.CodeRay .s .dl { color: #710; }
|
106
|
-
|
107
|
-
.CodeRay .sh { background-color:#f0fff0; color:#2B2 }
|
108
|
-
.CodeRay .sh .k { }
|
109
|
-
.CodeRay .sh .dl { color:#161 }
|
110
|
-
|
111
|
-
.CodeRay .sy { color:#A60 }
|
112
|
-
.CodeRay .sy .k { color:#A60 }
|
113
|
-
.CodeRay .sy .dl { color:#630 }
|
114
|
-
|
115
|
-
.CodeRay .ta { color:#070 }
|
116
|
-
.CodeRay .tf { color:#070; font-weight:bold }
|
117
|
-
.CodeRay .ts { color:#D70; font-weight:bold }
|
118
|
-
.CodeRay .ty { color:#339; font-weight:bold }
|
119
|
-
.CodeRay .v { color:#036 }
|
120
|
-
.CodeRay .xt { color:#444 }
|
121
|
-
|
122
|
-
.CodeRay .ins { background: #afa; }
|
123
|
-
.CodeRay .del { background: #faa; }
|
124
|
-
.CodeRay .chg { color: #aaf; background: #007; }
|
125
|
-
.CodeRay .head { color: #f8f; background: #505 }
|
126
|
-
|
127
|
-
.CodeRay .ins .ins { color: #080; font-weight:bold }
|
128
|
-
.CodeRay .del .del { color: #800; font-weight:bold }
|
129
|
-
.CodeRay .chg .chg { color: #66f; }
|
130
|
-
.CodeRay .head .head { color: #f4f; }
|
131
|
-
|
data/examples/static/index.html
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
<html>
|
2
|
-
<head>
|
3
|
-
<link href="/style" media="screen" rel="Stylesheet" type="text/css" />
|
4
|
-
</head>
|
5
|
-
<body>
|
6
|
-
<h1>Capcode hello !</h1>
|
7
|
-
|
8
|
-
<p>
|
9
|
-
Code :
|
10
|
-
<pre>:::ruby
|
11
|
-
# In an object instance variable (denoted with '@'), remember a block.
|
12
|
-
def remember(&a_block)
|
13
|
-
@block = a_block
|
14
|
-
end
|
15
|
-
|
16
|
-
# Invoke the above method, giving it a block which takes a name.
|
17
|
-
remember {|name| puts "Hello, #{name}!"}
|
18
|
-
|
19
|
-
# When the time is right (for the object) -- call the closure!
|
20
|
-
@block.call("Jon")
|
21
|
-
# => "Hello, Jon!"</pre>
|
22
|
-
</p>
|
23
|
-
</body>
|
24
|
-
</html>
|
data/examples/test/index.html
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
welcome in test directory
|
data/lib/capcode/base/ar.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'active_record'
|
3
|
-
rescue LoadError => e
|
4
|
-
raise MissingLibrary, "ActiveRecord could not be loaded (is it installed?): #{e.message}"
|
5
|
-
end
|
6
|
-
|
7
|
-
module Capcode
|
8
|
-
# This module contains the resources needed in a model
|
9
|
-
module Resource
|
10
|
-
end
|
11
|
-
|
12
|
-
# This class allow you to define models
|
13
|
-
Base = ActiveRecord::Base
|
14
|
-
|
15
|
-
# Schema info
|
16
|
-
class SchemaInfo < Base
|
17
|
-
end
|
18
|
-
|
19
|
-
class << self
|
20
|
-
# This class allow you to define models
|
21
|
-
def Model( n )
|
22
|
-
@final = [n, @final.to_f].max
|
23
|
-
m = (@migrations ||= [])
|
24
|
-
Class.new(ActiveRecord::Migration) do
|
25
|
-
meta_def(:version) { n }
|
26
|
-
meta_def(:inherited) { |k| m << k }
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def db_connect( dbfile, logfile ) #:nodoc:
|
31
|
-
dbconfig = YAML::load(File.open(dbfile)).keys_to_sym
|
32
|
-
version = dbconfig.delete(:schema_version) { |_| @final }
|
33
|
-
|
34
|
-
ActiveRecord::Base.establish_connection(dbconfig)
|
35
|
-
ActiveRecord::Base.logger = Logger.new(logfile)
|
36
|
-
|
37
|
-
if @migrations
|
38
|
-
unless SchemaInfo.table_exists?
|
39
|
-
ActiveRecord::Schema.define do
|
40
|
-
create_table SchemaInfo.table_name do |t|
|
41
|
-
t.column :version, :float
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
si = SchemaInfo.find(:first) || SchemaInfo.new(:version => 0)
|
46
|
-
@migrations.each do |k|
|
47
|
-
k.migrate(:up) if si.version < k.version and k.version <= version
|
48
|
-
k.migrate(:down) if si.version >= k.version and k.version > version
|
49
|
-
end
|
50
|
-
si.update_attributes(:version => version)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
data/lib/capcode/base/couchdb.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
begin
|
3
|
-
require 'couch_foo'
|
4
|
-
rescue LoadError => e
|
5
|
-
raise MissingLibrary, "CouchFoo could not be loaded (is it installed?): #{e.message}"
|
6
|
-
end
|
7
|
-
require 'yaml'
|
8
|
-
require 'logger'
|
9
|
-
|
10
|
-
module Capcode
|
11
|
-
module Resource
|
12
|
-
end
|
13
|
-
|
14
|
-
Base = CouchFoo::Base
|
15
|
-
|
16
|
-
class << self
|
17
|
-
def db_connect( dbfile, logfile )
|
18
|
-
dbconfig = YAML::load(File.open(dbfile)).keys_to_sym
|
19
|
-
Base.set_database(dbconfig)
|
20
|
-
Base.logger = Logger.new(logfile)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/lib/capcode/base/dm.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
begin
|
3
|
-
require 'dm-core'
|
4
|
-
rescue LoadError => e
|
5
|
-
raise MissingLibrary, "DataMapper could not be loaded (is it installed?): #{e.message}"
|
6
|
-
end
|
7
|
-
require 'yaml'
|
8
|
-
require 'logger'
|
9
|
-
|
10
|
-
module Capcode
|
11
|
-
Resource = DataMapper::Resource
|
12
|
-
|
13
|
-
# use DataMapper
|
14
|
-
#
|
15
|
-
# class Story < Capcode::Base
|
16
|
-
# include Capcode::Base
|
17
|
-
# property :id, Integer, :serial => true
|
18
|
-
# property :title, String
|
19
|
-
# property :body, String
|
20
|
-
# property :date, String
|
21
|
-
# end
|
22
|
-
class Base
|
23
|
-
end
|
24
|
-
|
25
|
-
class << self
|
26
|
-
def db_connect( dbfile, logfile ) #:nodoc:
|
27
|
-
dbconfig = YAML::load(File.open(dbfile)).keys_to_sym
|
28
|
-
DataMapper.setup(:default, dbconfig)
|
29
|
-
DataMapper::Logger.new(logfile, :debug)
|
30
|
-
DataMapper.auto_upgrade!
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/lib/capcode/base/mongodb.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
begin
|
3
|
-
require 'mongoid'
|
4
|
-
rescue LoadError => e
|
5
|
-
raise MissingLibrary, "Mongoid could not be loaded (is it installed?): #{e.message}"
|
6
|
-
end
|
7
|
-
require 'yaml'
|
8
|
-
require 'logger'
|
9
|
-
|
10
|
-
module Capcode
|
11
|
-
module Resource
|
12
|
-
end
|
13
|
-
|
14
|
-
Base = Mongoid::Document
|
15
|
-
|
16
|
-
class << self
|
17
|
-
def db_connect( dbfile, logfile )
|
18
|
-
dbconfig = YAML::load(File.open(dbfile)).keys_to_sym
|
19
|
-
|
20
|
-
connection = Mongo::Connection.new(dbconfig[:host], dbconfig[:port])
|
21
|
-
Mongoid.database = connection.db(dbconfig[:database])
|
22
|
-
if dbconfig[:username]
|
23
|
-
Mongoid.database.authenticate(dbconfig[:username], dbconfig[:password])
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/lib/capcode/base/sq.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'sequel'
|
3
|
-
Sequel.extension :migration
|
4
|
-
Sequel.extension :inflector
|
5
|
-
rescue LoadError => e
|
6
|
-
raise LoadError, "Sequel could not be loaded (is it installed?): #{e.message}"
|
7
|
-
end
|
8
|
-
|
9
|
-
module Capcode
|
10
|
-
# This module contains the resources needed in a model
|
11
|
-
module Resource
|
12
|
-
end
|
13
|
-
|
14
|
-
# This class allow you to define models
|
15
|
-
class Base
|
16
|
-
def self.method_missing( name, *args, &block )
|
17
|
-
if block_given?
|
18
|
-
Capcode::db[self.to_s.tableize.to_sym].__send__(name.to_sym, *args, &block)
|
19
|
-
else
|
20
|
-
Capcode::db[self.to_s.tableize.to_sym].__send__(name.to_sym, *args)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class << self
|
26
|
-
# This class allow you to define models
|
27
|
-
def Model( n )
|
28
|
-
@final = [n, @final.to_f].max
|
29
|
-
m = (@migrations ||= [])
|
30
|
-
Class.new(Sequel::Migration) do
|
31
|
-
meta_def(:version) { n }
|
32
|
-
meta_def(:inherited) { |k| m << k }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def db
|
37
|
-
@db ||= Sequel.connect(@dbconfig)
|
38
|
-
end
|
39
|
-
|
40
|
-
def db_connect( dbfile, logfile )
|
41
|
-
@dbconfig = YAML::load(File.open(dbfile)).keys_to_sym
|
42
|
-
@dbconfig[:adapter] = "sqlite" if @dbconfig[:adapter] == "sqlite3"
|
43
|
-
version = dbconfig.delete(:schema_version) { |_| @final }
|
44
|
-
|
45
|
-
if @migrations
|
46
|
-
Capcode::db.create_table? :schema_table do
|
47
|
-
Float :version
|
48
|
-
end
|
49
|
-
si = Capcode::db[:schema_table].first || (Capcode::db[:schema_table].insert(:version => 0); {:version => 0})
|
50
|
-
@migrations.each do |k|
|
51
|
-
k.apply(Capcode::db, :up) if si[:version] < k.version and k.version <= version
|
52
|
-
k.apply(Capcode::db, :down) if si[:version] >= k.version and k.version > version
|
53
|
-
end
|
54
|
-
Capcode::db[:schema_table].where(:version => si[:version]).update(:version => version)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|