ki 0.3.3 → 0.4.1
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.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +1 -1
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -21
- data/Gemfile.lock +60 -100
- data/Guardfile +1 -1
- data/LICENSE.md +21 -0
- data/README.md +63 -0
- data/Rakefile +3 -45
- data/bin/ki +1 -1
- data/ki.gemspec +31 -137
- data/lib/ki.rb +21 -21
- data/lib/ki/api_error.rb +28 -0
- data/lib/ki/base_request.rb +34 -0
- data/lib/ki/helpers.rb +55 -0
- data/lib/ki/ki.rb +40 -0
- data/lib/ki/ki_cli.rb +46 -0
- data/lib/ki/ki_config.rb +20 -0
- data/lib/ki/middleware.rb +155 -0
- data/lib/ki/model.rb +70 -0
- data/lib/{modules → ki/modules}/callbacks.rb +0 -0
- data/lib/ki/modules/format_of.rb +10 -0
- data/lib/{modules → ki/modules}/model_helpers.rb +0 -12
- data/lib/ki/modules/public_file_helper.rb +13 -0
- data/lib/ki/modules/query_interface.rb +36 -0
- data/lib/{modules → ki/modules}/restrictions.rb +0 -30
- data/lib/ki/modules/view_helper.rb +13 -0
- data/lib/ki/orm.rb +65 -0
- data/lib/ki/version.rb +3 -0
- data/spec/examples/base/.ruby-gemset +1 -0
- data/spec/examples/base/.ruby-version +1 -0
- data/spec/examples/base/Gemfile +4 -0
- data/spec/examples/base/app.rb +1 -0
- data/{examples → spec/examples}/base/config.ru +0 -3
- data/spec/examples/base/config.yml +17 -0
- data/spec/examples/base/public/favicon.ico +0 -0
- data/spec/examples/base/public/javascripts/.gitkeep +0 -0
- data/spec/examples/base/public/stylesheets/.gitkeep +0 -0
- data/spec/examples/base/views/index.haml +6 -0
- data/spec/examples/couch-lock/.ruby-gemset +1 -0
- data/spec/examples/couch-lock/.ruby-version +1 -0
- data/spec/examples/couch-lock/Gemfile +4 -0
- data/spec/examples/couch-lock/Gemfile.lock +48 -0
- data/spec/examples/couch-lock/app.rb +42 -0
- data/spec/examples/couch-lock/config.ru +3 -0
- data/spec/examples/couch-lock/config.yml +17 -0
- data/spec/examples/couch-lock/install.sh +3 -0
- data/spec/examples/couch-lock/public/favicon.ico +0 -0
- data/spec/examples/couch-lock/public/javascripts/.gitkeep +0 -0
- data/spec/examples/couch-lock/public/stylesheets/.gitkeep +0 -0
- data/spec/examples/couch-lock/views/index.haml +18 -0
- data/spec/examples/json.northpole.ro/.ruby-gemset +1 -0
- data/spec/examples/json.northpole.ro/.ruby-version +1 -0
- data/spec/examples/json.northpole.ro/Capfile +25 -0
- data/spec/examples/json.northpole.ro/Gemfile +6 -0
- data/spec/examples/json.northpole.ro/Gemfile.lock +68 -0
- data/spec/examples/json.northpole.ro/app.rb +79 -0
- data/spec/examples/json.northpole.ro/client.rb +25 -0
- data/spec/examples/json.northpole.ro/config.ru +3 -0
- data/spec/examples/json.northpole.ro/config.yml +17 -0
- data/spec/examples/json.northpole.ro/config/deploy.rb +59 -0
- data/spec/examples/json.northpole.ro/config/deploy/production.rb +39 -0
- data/spec/examples/json.northpole.ro/foo.rb +10 -0
- data/spec/examples/json.northpole.ro/public/JNorthPole.jar +0 -0
- data/spec/examples/json.northpole.ro/public/favicon.ico +0 -0
- data/spec/examples/json.northpole.ro/public/font/FontAwesome.otf +0 -0
- data/spec/examples/json.northpole.ro/public/font/fontawesome-webfont.eot +0 -0
- data/spec/examples/json.northpole.ro/public/font/fontawesome-webfont.svg +284 -0
- data/spec/examples/json.northpole.ro/public/font/fontawesome-webfont.ttf +0 -0
- data/spec/examples/json.northpole.ro/public/font/fontawesome-webfont.woff +0 -0
- data/spec/examples/json.northpole.ro/public/images/bear.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/bg.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/cloud.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/dotnet.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/dotnet_small.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/footer.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/glyphicons-halflings-white.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/glyphicons-halflings.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/ice.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/java.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/java_small.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/json.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/json_small.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/logo.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/mobile.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/php.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/php_small.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/python.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/python_small.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/ruby.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/ruby_small.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/shell.png +0 -0
- data/spec/examples/json.northpole.ro/public/images/shell_small.png +0 -0
- data/spec/examples/json.northpole.ro/public/javascripts/analytics.js +9 -0
- data/spec/examples/json.northpole.ro/public/javascripts/app.coffee +133 -0
- data/spec/examples/json.northpole.ro/public/javascripts/docs.min.js +16 -0
- data/spec/examples/json.northpole.ro/public/javascripts/jnorthpole.coffee +34 -0
- data/spec/examples/json.northpole.ro/public/javascripts/util.coffee +31 -0
- data/spec/examples/json.northpole.ro/public/stylesheets/app.sass +23 -0
- data/spec/examples/json.northpole.ro/public/stylesheets/application.sass +222 -0
- data/spec/examples/json.northpole.ro/public/stylesheets/cover.css +154 -0
- data/spec/examples/json.northpole.ro/views/curl.haml +19 -0
- data/spec/examples/json.northpole.ro/views/doc.haml +16 -0
- data/spec/examples/json.northpole.ro/views/doc_table.haml +45 -0
- data/spec/examples/json.northpole.ro/views/dotnet.haml +24 -0
- data/spec/examples/json.northpole.ro/views/examples.haml +28 -0
- data/spec/examples/json.northpole.ro/views/faq.haml +32 -0
- data/spec/examples/json.northpole.ro/views/foo.haml +7 -0
- data/spec/examples/json.northpole.ro/views/index.haml +4 -0
- data/spec/examples/json.northpole.ro/views/java.haml +0 -0
- data/spec/examples/json.northpole.ro/views/layout.haml +42 -0
- data/spec/examples/json.northpole.ro/views/php.haml +37 -0
- data/spec/examples/json.northpole.ro/views/playground.haml +38 -0
- data/spec/examples/json.northpole.ro/views/python.haml +17 -0
- data/spec/examples/json.northpole.ro/views/ruby.haml +12 -0
- data/spec/examples/json.northpole.ro/views/signup.haml +2 -0
- data/spec/examples/json.northpole.ro/views/thanks.haml +12 -0
- data/spec/functional_spec.rb +4 -0
- data/spec/lib/ki/base_request_spec.rb +88 -0
- data/spec/lib/ki/helpers_spec.rb +12 -0
- data/spec/lib/ki/ki_config_spec.rb +7 -0
- data/spec/lib/ki/middleware_spec.rb +11 -0
- data/spec/lib/ki/model_spec.rb +100 -0
- data/spec/lib/ki/modules/format_of_spec.rb +15 -0
- data/spec/lib/ki/orm_spec.rb +83 -0
- data/spec/spec_helper.rb +18 -5
- data/spec/util_spec.rb +7 -36
- metadata +269 -193
- data/.document +0 -5
- data/.rvmrc +0 -1
- data/LICENSE.txt +0 -20
- data/README.rdoc +0 -3
- data/VERSION +0 -1
- data/examples/base/Gemfile +0 -3
- data/examples/base/Gemfile.lock +0 -24
- data/examples/base/app.rb +0 -4
- data/examples/base/config.yml +0 -16
- data/gfx/colors.xcf +0 -0
- data/gfx/ki3.eps +0 -0
- data/gfx/logo.png +0 -0
- data/ki_wrap.rb +0 -35
- data/lib/conf.rb +0 -28
- data/lib/db.rb +0 -73
- data/lib/helpers.rb +0 -34
- data/lib/ki_cli.rb +0 -76
- data/lib/mockreq.rb +0 -45
- data/lib/model.rb +0 -110
- data/lib/modules/email.rb +0 -51
- data/lib/modules/query_interface.rb +0 -42
- data/lib/req.rb +0 -57
- data/lib/resp.rb +0 -70
- data/lib/static_file.rb +0 -68
- data/lib/util.rb +0 -114
- data/lib/views/404.haml +0 -1
- data/lib/views/406.haml +0 -1
- data/lib/views/index.haml +0 -7
- data/lib/views/layout.haml +0 -1
- data/spec/conf_spec.rb +0 -6
- data/spec/db_spec.rb +0 -93
- data/spec/integration/integration_spec.rb +0 -114
- data/spec/ki_spec.rb +0 -7
- data/spec/model_spec.rb +0 -91
- data/spec/modules/callbacks_spec.rb +0 -25
- data/spec/modules/email_spec.rb +0 -19
- data/spec/modules/query_interface_spec.rb +0 -93
- data/spec/modules/restrictions_spec.rb +0 -110
- data/spec/performance/performance.sh +0 -1
- data/spec/req_spec.rb +0 -29
data/lib/modules/email.rb
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
require 'mail'
|
|
2
|
-
require 'net/smtp'
|
|
3
|
-
|
|
4
|
-
module Ki
|
|
5
|
-
module Email
|
|
6
|
-
def valid_mail? s
|
|
7
|
-
return false if s == '' || s.nil?
|
|
8
|
-
r = /^[a-z0-9\+\-\.]+@[a-z0-9]+\.[a-z0-9\.\-]+$/i =~ s
|
|
9
|
-
!r.nil?
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def send_mail *params
|
|
13
|
-
params = params[0] if params.class == Array
|
|
14
|
-
|
|
15
|
-
if params.length != 4
|
|
16
|
-
raise 'params missing'
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
params.each do |elem|
|
|
20
|
-
if !self.class.required_attributes.include? elem
|
|
21
|
-
raise "invalid attribute #{elem.to_s}"
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
from = @req[params[0].to_s]
|
|
26
|
-
to = @req[params[1].to_s]
|
|
27
|
-
subject = @req[params[2].to_s]
|
|
28
|
-
body = @req[params[3].to_s]
|
|
29
|
-
|
|
30
|
-
really_send from, to, subject, body
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def really_send f, t, s, b
|
|
34
|
-
mail = Mail.new do
|
|
35
|
-
from f
|
|
36
|
-
to t
|
|
37
|
-
subject s
|
|
38
|
-
body b
|
|
39
|
-
end
|
|
40
|
-
mail.deliver
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def really_send2 f, t, s, b
|
|
44
|
-
msgstr = "From: #{f}\nTo: #{t}\nSubject: #{s}\n\n#{b}\n"
|
|
45
|
-
Net::SMTP.start('localhost', 25) do |smtp|
|
|
46
|
-
smtp.send_message msgstr, f, t
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
end
|
|
51
|
-
end
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
module Ki
|
|
2
|
-
module QueryInterface
|
|
3
|
-
def count
|
|
4
|
-
Db.instance.db[class_name].count
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def find id
|
|
8
|
-
if id.class == String
|
|
9
|
-
Db.instance.find class_name, id
|
|
10
|
-
else
|
|
11
|
-
Db.instance.find_by class_name, id
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def find_or_create hash
|
|
16
|
-
elem = find(hash)
|
|
17
|
-
if elem.empty?
|
|
18
|
-
elem_id = create(hash)
|
|
19
|
-
elem = find(elem_id)
|
|
20
|
-
end
|
|
21
|
-
elem
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def create hash
|
|
25
|
-
Db.instance.create class_name, hash
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def update hash
|
|
29
|
-
Db.instance.update class_name, hash
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def delete id
|
|
33
|
-
Db.instance.delete class_name, id
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
private
|
|
37
|
-
|
|
38
|
-
def class_name
|
|
39
|
-
self.to_s.downcase
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
data/lib/req.rb
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
module Ki
|
|
2
|
-
class Req < Rack::Request
|
|
3
|
-
attr_accessor :code, :klass, :format
|
|
4
|
-
|
|
5
|
-
def initialize env
|
|
6
|
-
super env
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def serve
|
|
10
|
-
unless static_path_requested?
|
|
11
|
-
route
|
|
12
|
-
Resp.new(self).finish
|
|
13
|
-
else
|
|
14
|
-
StaticFile.new(self).finish
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def route
|
|
19
|
-
@klass = Util.base(path).to_class
|
|
20
|
-
@format = content_type == 'application/json' ? :json : Util.format(path)
|
|
21
|
-
if @klass || path == '/' || has_view?
|
|
22
|
-
@code = 200
|
|
23
|
-
else
|
|
24
|
-
@code = 404
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def json?
|
|
29
|
-
@format == :json
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def html?
|
|
33
|
-
@format == :html
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def index?
|
|
37
|
-
path == '/'
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def content_type_for_result
|
|
41
|
-
{
|
|
42
|
-
:json => 'application/json',
|
|
43
|
-
:html => 'text/html'
|
|
44
|
-
}[@format]
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def has_view?
|
|
48
|
-
File.exists?(Util.root_view_path(Util.base(path)))
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
private
|
|
52
|
-
|
|
53
|
-
def static_path_requested?
|
|
54
|
-
path.start_with? '/public/'
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
data/lib/resp.rb
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
require 'json'
|
|
2
|
-
|
|
3
|
-
module Ki
|
|
4
|
-
class Resp < Rack::Response
|
|
5
|
-
include Helpers
|
|
6
|
-
|
|
7
|
-
attr_accessor :req
|
|
8
|
-
|
|
9
|
-
def initialize req
|
|
10
|
-
@req = req
|
|
11
|
-
headers = {
|
|
12
|
-
'Content-Type' => @req.content_type_for_result
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
# TODO think of a way to clean this up
|
|
16
|
-
# here be dragons. don't try to understand this because it is a nested mess
|
|
17
|
-
# it is my duty to clean it. one day
|
|
18
|
-
klass = @req.klass
|
|
19
|
-
if klass.responds_to_formats.include? @req.format
|
|
20
|
-
if @req.code == 404
|
|
21
|
-
body = @req.html? ? partial('404') : { :error => 404 }
|
|
22
|
-
else
|
|
23
|
-
if @req.index?
|
|
24
|
-
body = @req.html? ? partial('index') : { :index => 200 }
|
|
25
|
-
else
|
|
26
|
-
if @req.html?
|
|
27
|
-
if klass == nil # if route is /ruby it means ruby.haml exists in views
|
|
28
|
-
body = Util.render_partial Util.base(@req.path), { 'env' => @req.env }, 'layout'
|
|
29
|
-
else
|
|
30
|
-
klass_view = Util.root_view_path(klass.to_s.downcase)
|
|
31
|
-
body = File.exists?(klass_view) ? partial(klass.to_s.downcase) : partial('index')
|
|
32
|
-
end
|
|
33
|
-
else
|
|
34
|
-
begin
|
|
35
|
-
interpret_json_params
|
|
36
|
-
body = klass.new(@req).to_json
|
|
37
|
-
rescue Exception => e
|
|
38
|
-
@req.code = 400
|
|
39
|
-
body = { :error => e.to_s }.to_json
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
else
|
|
45
|
-
@req.code = 406
|
|
46
|
-
body = @req.html? ? partial('406') : { :error => 'format not allowed' }.to_json
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
super [body], @req.code, headers
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
private
|
|
53
|
-
|
|
54
|
-
def partial s
|
|
55
|
-
Util.render_partial s, { 'env' => @req.env }, @req.klass.selected_layout
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def interpret_json_params
|
|
59
|
-
if @req.json? && @req.body.length > 0
|
|
60
|
-
begin
|
|
61
|
-
@req.body.rewind
|
|
62
|
-
@req.env.update('rack.request.form_hash' => JSON.parse(@req.body.string),
|
|
63
|
-
'rack.request.form_input' => @req.env['rack.input'])
|
|
64
|
-
rescue JSON::ParserError
|
|
65
|
-
raise "json body invalid: #{@req.body.string}"
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
data/lib/static_file.rb
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
module Ki
|
|
2
|
-
# serve files from public folder
|
|
3
|
-
# and compile them if they are coffee of sass
|
|
4
|
-
class StaticFile < Rack::File
|
|
5
|
-
attr_reader :env
|
|
6
|
-
|
|
7
|
-
def initialize req
|
|
8
|
-
super Util.root
|
|
9
|
-
@env = req.env
|
|
10
|
-
|
|
11
|
-
if ENV['RACK_ENV'] == 'development'
|
|
12
|
-
StaticFile.compile_css(@env['REQUEST_PATH'])
|
|
13
|
-
StaticFile.compile_js(@env['REQUEST_PATH'])
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
@env
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def finish
|
|
20
|
-
call(@env)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def self.compile_js filename
|
|
24
|
-
if filename.end_with? '.js'
|
|
25
|
-
js_path = File.join(Util.root, filename)
|
|
26
|
-
coffee_path = js_path.gsub('.js', '.coffee')
|
|
27
|
-
coffee_to_js coffee_path, js_path
|
|
28
|
-
elsif filename.end_with? '.coffee'
|
|
29
|
-
coffee_path = File.join(Util.root, filename)
|
|
30
|
-
js_path = coffee_path.gsub('.coffee', '.js')
|
|
31
|
-
coffee_to_js coffee_path, js_path
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def self.compile_css filename
|
|
36
|
-
if filename.end_with? '.css'
|
|
37
|
-
css_path = File.join(Util.root, filename)
|
|
38
|
-
sass_path = css_path.gsub('.css', '.sass')
|
|
39
|
-
sass_to_css sass_path, css_path
|
|
40
|
-
elsif filename.end_with? '.sass'
|
|
41
|
-
sass_path = File.join(Util.root, filename)
|
|
42
|
-
css_path = sass_path.gsub('.sass', '.css')
|
|
43
|
-
sass_to_css sass_path, css_path
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
private
|
|
48
|
-
|
|
49
|
-
def self.sass_to_css sass_path, css_path
|
|
50
|
-
if File.exists? sass_path
|
|
51
|
-
eng = Sass::Engine.new(File.read(sass_path), :syntax => :sass)
|
|
52
|
-
File.open(css_path, 'w') do |f|
|
|
53
|
-
f.puts eng.render
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def self.coffee_to_js coffee_path, js_path
|
|
59
|
-
if File.exists? coffee_path
|
|
60
|
-
coffee_file = File.read(coffee_path)
|
|
61
|
-
cont = CoffeeScript.compile(coffee_file)
|
|
62
|
-
File.open(js_path, 'w') do |f|
|
|
63
|
-
f.puts cont
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
data/lib/util.rb
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
class Array
|
|
2
|
-
def stringify_ids
|
|
3
|
-
self.collect do |e|
|
|
4
|
-
e['id'] = e['_id'].to_s
|
|
5
|
-
e.delete('_id')
|
|
6
|
-
e
|
|
7
|
-
end
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
class NilClass
|
|
12
|
-
def responds_to_formats
|
|
13
|
-
[:json, :html]
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def selected_layout
|
|
17
|
-
:layout
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
class String
|
|
22
|
-
def to_class
|
|
23
|
-
chain = self.split "::"
|
|
24
|
-
klass = Kernel
|
|
25
|
-
chain.each do |klass_string|
|
|
26
|
-
klass = klass.const_get klass_string.capitalize
|
|
27
|
-
end
|
|
28
|
-
klass.is_a?(Class) ? klass : nil
|
|
29
|
-
rescue NameError
|
|
30
|
-
nil
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
module Ki
|
|
35
|
-
class Util
|
|
36
|
-
def self.base s
|
|
37
|
-
if s == '/'
|
|
38
|
-
return ''
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
s = s.split('/')[1]
|
|
42
|
-
|
|
43
|
-
iq = s.index '?'
|
|
44
|
-
ip = s.index '.'
|
|
45
|
-
|
|
46
|
-
if ip.nil? && iq.nil?
|
|
47
|
-
return s
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
if !ip.nil?
|
|
51
|
-
return s[0...ip]
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
if !iq.nil?
|
|
55
|
-
return s[0...iq]
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def self.root_view_path name
|
|
60
|
-
File.join(root, 'views', name) + '.haml'
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def self.format s
|
|
64
|
-
if s == '/'
|
|
65
|
-
return :html
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
base = s.split('/')[1]
|
|
69
|
-
if base.include? '.'
|
|
70
|
-
base.split('.')[1].split('?')[0].to_sym rescue :html
|
|
71
|
-
else
|
|
72
|
-
:html
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def self.src_path
|
|
77
|
-
File.join(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def self.root
|
|
81
|
-
Dir.getwd
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def self.app_name
|
|
85
|
-
File.basename(root)
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def self.render_partial s, hash={}, l=:layout
|
|
89
|
-
contents = file_contents(s)
|
|
90
|
-
case l
|
|
91
|
-
when :none
|
|
92
|
-
layout_contents = "= yield"
|
|
93
|
-
else
|
|
94
|
-
layout_contents = file_contents(l.to_s)
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
haml(layout_contents).render do
|
|
98
|
-
haml(contents).render(Object.new(), hash)
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def self.haml contents
|
|
103
|
-
Haml::Engine.new("- extend Ki::Helpers\n" + contents)
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def self.file_contents s
|
|
107
|
-
path = Util.root_view_path s
|
|
108
|
-
unless File.exists? path
|
|
109
|
-
path = File.join(Util.src_path, 'views', s) + '.haml'
|
|
110
|
-
end
|
|
111
|
-
File.read(path)
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
end
|
data/lib/views/404.haml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
%center 404 - Not Found
|
data/lib/views/406.haml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
%center 406 - Not Acceptable Format
|
data/lib/views/index.haml
DELETED
data/lib/views/layout.haml
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
= yield
|
data/spec/conf_spec.rb
DELETED
data/spec/db_spec.rb
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
|
-
|
|
3
|
-
describe Ki::Db do
|
|
4
|
-
before :each do
|
|
5
|
-
@db = Ki::Db.instance
|
|
6
|
-
@db.remove_collections
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
it "should start with an empty database" do
|
|
10
|
-
@db.collection_names.empty?.should be_true
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it "should create a collection" do
|
|
14
|
-
@db.collection_names.empty?.should be_true
|
|
15
|
-
@db.create 'zoidberg', { :foo => 'bar' }
|
|
16
|
-
@db.collection_names.empty?.should be_false
|
|
17
|
-
@db.collection_names.include?('zoidberg').should be_true
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
it "should create an model" do
|
|
21
|
-
@db.db['zoidberg'].count.should == 0
|
|
22
|
-
@db.create 'zoidberg', { :foo => [1,2] }
|
|
23
|
-
@db.db['zoidberg'].count.should == 1
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
it "should return doc id when creating a model" do
|
|
27
|
-
post_id = @db.create 'zoidberg', { :foo => [1,2] }
|
|
28
|
-
post_id.class.should == String
|
|
29
|
-
bson_id = BSON::ObjectId.from_string(post_id)
|
|
30
|
-
@db.db['zoidberg'].find('_id' => bson_id).first['foo'].should == [1,2]
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "should find a specific document" do
|
|
34
|
-
post_id = @db.create 'zoidberg', { :foo => [1,2] }
|
|
35
|
-
@db.find('zoidberg', post_id)['foo'].should == [1,2]
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it "should find by _id, id, and objid" do
|
|
39
|
-
post_id = @db.create 'zoidberg', { :foo => [1,2] }
|
|
40
|
-
@db.find_by('zoidberg', {'id' => post_id})[0]['id'].should == post_id
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it "should update a document" do
|
|
44
|
-
post_id = @db.create 'zoidberg', { :foo => [1,2], :bar => 'highj' }
|
|
45
|
-
@db.update 'zoidberg', { 'id' => post_id, :foo => 3.1415 }
|
|
46
|
-
doc = @db.find('zoidberg', post_id)
|
|
47
|
-
doc['foo'].should == 3.1415
|
|
48
|
-
doc['bar'].should == nil
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it "should delete a document" do
|
|
52
|
-
post_id = @db.create 'zoidberg', { :foo => [1,2], :bar => 'highj' }
|
|
53
|
-
@db.db['zoidberg'].count.should == 1
|
|
54
|
-
@db.delete('zoidberg', post_id)
|
|
55
|
-
@db.db['zoidberg'].count.should == 0
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it "should find all documents in collection" do
|
|
59
|
-
@db.create 'zoidberg', { :foo => [1,2], :bar => 'highj' }
|
|
60
|
-
@db.create 'zoidberg', { :foo => [3,4], :bar => 'lowj' }
|
|
61
|
-
@db.find_all('zoidberg').count.should == @db.db['zoidberg'].count
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it "should find by an attribute" do
|
|
65
|
-
id = @db.create 'zoidberg', { :foo => [1,2], :bar => 'highj' }
|
|
66
|
-
@db.create 'zoidberg', { :foo => [3,4], :bar => 'lowj' }
|
|
67
|
-
@db.create 'zoidberg', { :foo => [5,6], :bar => 'lowj' }
|
|
68
|
-
r = @db.find_by 'zoidberg', { :bar => 'lowj' }
|
|
69
|
-
r.class.should == Array
|
|
70
|
-
r.length.should == 2
|
|
71
|
-
|
|
72
|
-
r = @db.find_by 'zoidberg', { :bar => 'lowj', :foo => [3,4] }
|
|
73
|
-
r.class.should == Array
|
|
74
|
-
r.length.should == 1
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it "should transform _id in BSON::ObjectId when using find_by" do
|
|
78
|
-
hash = { :foo => [1,2], :bar => 'highj' }
|
|
79
|
-
id = @db.create 'zoidberg', hash
|
|
80
|
-
hash['id'] = id
|
|
81
|
-
r = @db.find_by 'zoidberg', hash
|
|
82
|
-
r.length.should == 1
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "should be able to change db name" do
|
|
86
|
-
new_db_name = 'test_ki_change_name'
|
|
87
|
-
@db.db.name.should == DB_NAME
|
|
88
|
-
|
|
89
|
-
@db.db_name new_db_name
|
|
90
|
-
|
|
91
|
-
@db.db.name.should == new_db_name
|
|
92
|
-
end
|
|
93
|
-
end
|