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/.document
DELETED
data/.rvmrc
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
rvm use 1.9.3@ki --create
|
data/LICENSE.txt
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2013 Cristian Mircea Messel
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
-
a copy of this software and associated documentation files (the
|
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
-
the following conditions:
|
|
10
|
-
|
|
11
|
-
The above copyright notice and this permission notice shall be
|
|
12
|
-
included in all copies or substantial portions of the Software.
|
|
13
|
-
|
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
DELETED
data/VERSION
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
0.3.3
|
data/examples/base/Gemfile
DELETED
data/examples/base/Gemfile.lock
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: ../../
|
|
3
|
-
specs:
|
|
4
|
-
ki (0.0.1)
|
|
5
|
-
rack
|
|
6
|
-
thin
|
|
7
|
-
thor
|
|
8
|
-
|
|
9
|
-
GEM
|
|
10
|
-
specs:
|
|
11
|
-
daemons (1.1.9)
|
|
12
|
-
eventmachine (1.0.0)
|
|
13
|
-
rack (1.5.1)
|
|
14
|
-
thin (1.5.0)
|
|
15
|
-
daemons (>= 1.0.9)
|
|
16
|
-
eventmachine (>= 0.12.6)
|
|
17
|
-
rack (>= 1.0.0)
|
|
18
|
-
thor (0.17.0)
|
|
19
|
-
|
|
20
|
-
PLATFORMS
|
|
21
|
-
ruby
|
|
22
|
-
|
|
23
|
-
DEPENDENCIES
|
|
24
|
-
ki!
|
data/examples/base/app.rb
DELETED
data/examples/base/config.yml
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
chdir: PATH_TO_YOUR_APP
|
|
3
|
-
environment: development
|
|
4
|
-
address: 0.0.0.0
|
|
5
|
-
port: 3000
|
|
6
|
-
timeout: 30
|
|
7
|
-
log: log/thin.log
|
|
8
|
-
pid: tmp/pids/thin.pid
|
|
9
|
-
max_conns: 1024
|
|
10
|
-
max_persistent_conns: 100
|
|
11
|
-
require: []
|
|
12
|
-
wait: 30
|
|
13
|
-
daemonize: false
|
|
14
|
-
database_name: np
|
|
15
|
-
database_host: 127.0.0.1
|
|
16
|
-
database_port: 27017
|
data/gfx/colors.xcf
DELETED
|
Binary file
|
data/gfx/ki3.eps
DELETED
|
Binary file
|
data/gfx/logo.png
DELETED
|
Binary file
|
data/ki_wrap.rb
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
require 'httparty'
|
|
2
|
-
|
|
3
|
-
class Resource
|
|
4
|
-
include HTTParty
|
|
5
|
-
base_uri 'localhost:3000'
|
|
6
|
-
|
|
7
|
-
def self.create h
|
|
8
|
-
post("/#{klass}.json", h)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def self.find h
|
|
12
|
-
get("/#{klass}.json", h)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
private
|
|
16
|
-
|
|
17
|
-
def self.klass
|
|
18
|
-
to_s.downcase
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
class Storage < Resource
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
class User < Resource
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# user = 'mess121'
|
|
29
|
-
# pass = '123'
|
|
30
|
-
#
|
|
31
|
-
# p User.create({ :body => { 'mail' => user, 'password' => pass}})
|
|
32
|
-
# p User.find({ :query => { 'mail' => user, 'password' => pass}})
|
|
33
|
-
#
|
|
34
|
-
# p Storage.create({ :body => { 'mail' => user, 'password' => pass, 'cool' => true, 'vals' => [3,3.14,4.20]}})
|
|
35
|
-
# p Storage.find({ :query => { 'mail' => user, 'password' => pass}})
|
data/lib/conf.rb
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
require 'singleton'
|
|
2
|
-
|
|
3
|
-
module Ki
|
|
4
|
-
# named conf because ruby has Config class :(
|
|
5
|
-
# in version 2 Config class will be deprecated and
|
|
6
|
-
# replace with RbConfig
|
|
7
|
-
# When you update to ruby2, think about changing the name
|
|
8
|
-
class Conf
|
|
9
|
-
include Singleton
|
|
10
|
-
|
|
11
|
-
attr_accessor :yaml
|
|
12
|
-
|
|
13
|
-
def initialize
|
|
14
|
-
super
|
|
15
|
-
|
|
16
|
-
config_path = File.join(Dir.pwd, 'config.yml')
|
|
17
|
-
if File.exists? config_path
|
|
18
|
-
@yaml = YAML.load_file(config_path)
|
|
19
|
-
else
|
|
20
|
-
@yaml = YAML.load({
|
|
21
|
-
'database_host' => '127.0.0.1',
|
|
22
|
-
'database_port' => 27017,
|
|
23
|
-
'database_name' => 'ki_default_db'
|
|
24
|
-
}.to_yaml)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
data/lib/db.rb
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
require 'mongo'
|
|
2
|
-
require 'singleton'
|
|
3
|
-
require 'json'
|
|
4
|
-
|
|
5
|
-
module Ki
|
|
6
|
-
class Db
|
|
7
|
-
include Singleton
|
|
8
|
-
|
|
9
|
-
attr_reader :db
|
|
10
|
-
|
|
11
|
-
def initialize
|
|
12
|
-
super
|
|
13
|
-
|
|
14
|
-
config
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def collection_names
|
|
18
|
-
@db.collection_names.delete_if{|name| name =~ /^system/}
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def remove_collections
|
|
22
|
-
collection_names.each{|c| @db[c].drop}
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def find_all name
|
|
26
|
-
@db[name].find.collect{ |row| row }.stringify_ids
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def find name, id
|
|
30
|
-
@db[name].find( { '_id' => BSON::ObjectId(id) }).to_a.stringify_ids.first
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def find_by name, hash
|
|
34
|
-
if hash['id']
|
|
35
|
-
hash['_id'] = BSON::ObjectId(hash['id'])
|
|
36
|
-
hash.delete('id')
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
@db[name].find(hash).to_a.stringify_ids
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def create name, hash
|
|
43
|
-
@db[name].insert(hash).to_s
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# document doesn't update if :_id is in the hash
|
|
47
|
-
# all prev object data is deleted
|
|
48
|
-
def update name, hash
|
|
49
|
-
id = hash['id']
|
|
50
|
-
hash.delete('id')
|
|
51
|
-
@db[name].update({:_id => BSON::ObjectId(id)}, hash)
|
|
52
|
-
id
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def delete name, id
|
|
56
|
-
@db[name].remove(:_id => BSON::ObjectId(id))
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def db_name db_name
|
|
60
|
-
Conf.instance.yaml['database_name'] = db_name
|
|
61
|
-
@db = @con.db(db_name)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def config
|
|
65
|
-
yaml = Conf.instance.yaml
|
|
66
|
-
@con = Mongo::Connection.new(yaml['database_host'], yaml['database_port'])
|
|
67
|
-
@db = @con.db(yaml['database_name'])
|
|
68
|
-
rescue Mongo::ConnectionFailure
|
|
69
|
-
puts "Could not connect to MongoDB"
|
|
70
|
-
exit 1
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
data/lib/helpers.rb
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
module Ki
|
|
2
|
-
module Helpers
|
|
3
|
-
# Example usage from haml
|
|
4
|
-
# locals is the param variable
|
|
5
|
-
#
|
|
6
|
-
# = partial 'index', locals
|
|
7
|
-
def partial s, hash={}
|
|
8
|
-
Util.render_partial(s, hash)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def partial? s
|
|
12
|
-
path = Util.root_view_path(s)
|
|
13
|
-
File.exists? path
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def css url
|
|
17
|
-
render_haml "%link{:href => '#{url}', :rel => 'stylesheet'}"
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def js url
|
|
21
|
-
render_haml "%script{:src => '#{url}'}"
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def haml s
|
|
25
|
-
render_haml s
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
private
|
|
29
|
-
|
|
30
|
-
def render_haml s
|
|
31
|
-
Haml::Engine.new(s).render
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
data/lib/ki_cli.rb
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
require 'thor'
|
|
2
|
-
|
|
3
|
-
require 'util'
|
|
4
|
-
|
|
5
|
-
class KiGenerator < Thor::Group
|
|
6
|
-
include Thor::Actions
|
|
7
|
-
|
|
8
|
-
def self.source_root
|
|
9
|
-
File.join(File.dirname(__FILE__), '..', 'examples', 'base')
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
class AppGenerator < KiGenerator
|
|
14
|
-
|
|
15
|
-
argument :app_name
|
|
16
|
-
|
|
17
|
-
def prepare_dir
|
|
18
|
-
dest_root = File.join(Dir.pwd, app_name)
|
|
19
|
-
|
|
20
|
-
if Dir.exists? dest_root
|
|
21
|
-
unless yes? "#{app_name} already exists. Do you want to overwrite it?"
|
|
22
|
-
say 'aborted'
|
|
23
|
-
exit 1
|
|
24
|
-
end
|
|
25
|
-
else
|
|
26
|
-
Dir.mkdir dest_root
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def create_app
|
|
31
|
-
dest_root = File.join(Dir.pwd, app_name)
|
|
32
|
-
|
|
33
|
-
['Gemfile', 'config.ru', 'app.rb', 'config.yml'].each do |f|
|
|
34
|
-
copy_file f, File.join(dest_root, f)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
class KiCli < Thor
|
|
40
|
-
register AppGenerator, :new, 'new [APP_NAME]', 'generate a new app'
|
|
41
|
-
|
|
42
|
-
desc 'config', 'set a specific value to a key in config.yml'
|
|
43
|
-
method_option :key, :type => :string, :aliases => '-k', :desc => 'specify which key to use'
|
|
44
|
-
method_option :val, :type => :string, :aliases => '-v', :desc => 'specify value for the key'
|
|
45
|
-
def config
|
|
46
|
-
if options[:key].nil? || options[:val].nil?
|
|
47
|
-
say "key and val required", :red
|
|
48
|
-
return 0
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
path = File.join(Dir.pwd, 'config.yml')
|
|
52
|
-
lines = File.open(path, 'r').read.split("\n")
|
|
53
|
-
File.open(path, 'w') { |f|
|
|
54
|
-
lines.each do |l|
|
|
55
|
-
if l.start_with? options[:key]
|
|
56
|
-
|
|
57
|
-
l = options[:key].to_s + ": " + options[:val].to_s
|
|
58
|
-
end
|
|
59
|
-
f.write l + "\n"
|
|
60
|
-
end
|
|
61
|
-
}
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
desc 'server', 'starts the app'
|
|
65
|
-
# method_option :reload, :type => :boolean, :aliases => '-r', :desc => 'Recommended for development'
|
|
66
|
-
method_option :port, :type => :numeric, :aliases => '-p', :desc => 'port'
|
|
67
|
-
def server
|
|
68
|
-
port = options[:port] ? options[:port] : 3000
|
|
69
|
-
# if options[:reload]
|
|
70
|
-
# say 'Starting Ki Reloaded', :yellow
|
|
71
|
-
#else
|
|
72
|
-
say 'Starting Ki', :green
|
|
73
|
-
#end
|
|
74
|
-
system "bundle exec thin start -p #{port}"
|
|
75
|
-
end
|
|
76
|
-
end
|
data/lib/mockreq.rb
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
module Ki
|
|
2
|
-
class MockReq
|
|
3
|
-
attr_accessor :request_method
|
|
4
|
-
attr_accessor :params
|
|
5
|
-
|
|
6
|
-
def get?
|
|
7
|
-
request_method == 'GET'
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def post?
|
|
11
|
-
request_method == 'POST'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def put?
|
|
15
|
-
request_method == 'PUT'
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def delete?
|
|
19
|
-
request_method == 'DELETE'
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def search?
|
|
23
|
-
request_method == 'SEARCH'
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
class ReqFactory
|
|
28
|
-
def self.new sym, params={}
|
|
29
|
-
case sym
|
|
30
|
-
when :get, :post, :put, :delete, :head, :search
|
|
31
|
-
mr = MockReq.new
|
|
32
|
-
mr.request_method = sym.to_s.upcase
|
|
33
|
-
mr.params = params
|
|
34
|
-
return mr
|
|
35
|
-
when :post_homer
|
|
36
|
-
mr = MockReq.new
|
|
37
|
-
mr.request_method = 'POST'
|
|
38
|
-
mr.params = { 'user' => 'homer' }
|
|
39
|
-
return mr
|
|
40
|
-
else
|
|
41
|
-
raise "not a valid factory"
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
data/lib/model.rb
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
require 'modules/callbacks'
|
|
2
|
-
require 'modules/restrictions'
|
|
3
|
-
require 'modules/query_interface'
|
|
4
|
-
require 'modules/model_helpers'
|
|
5
|
-
require 'modules/email'
|
|
6
|
-
|
|
7
|
-
module Ki
|
|
8
|
-
class Model
|
|
9
|
-
extend Restrictions
|
|
10
|
-
extend QueryInterface
|
|
11
|
-
|
|
12
|
-
include Callbacks
|
|
13
|
-
include ModelHelpers
|
|
14
|
-
|
|
15
|
-
attr_accessor :hash
|
|
16
|
-
attr_accessor :req
|
|
17
|
-
|
|
18
|
-
layout :layout
|
|
19
|
-
|
|
20
|
-
def initialize req
|
|
21
|
-
@hash = {}
|
|
22
|
-
@db = Db.instance
|
|
23
|
-
@req = req
|
|
24
|
-
|
|
25
|
-
action = to_action(req)
|
|
26
|
-
raise 'action forbidden' if forbidden_actions.include? action
|
|
27
|
-
ccall action
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def find
|
|
31
|
-
raise 'params missing' unless @req.params
|
|
32
|
-
@hash = @db.find_by(class_name, @req.params)
|
|
33
|
-
raise "#{class_name} not found" if @hash.nil?
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def create
|
|
37
|
-
check_for_required_attributes
|
|
38
|
-
check_for_unique_attributes
|
|
39
|
-
@hash['id'] = @db.create(class_name, @req.params)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def update
|
|
43
|
-
raise 'params missing' unless @req.params
|
|
44
|
-
raise 'param id missing' unless @req.params['id']
|
|
45
|
-
check_for_required_attributes
|
|
46
|
-
@hash['id'] = @db.update(class_name, @req.params)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def delete
|
|
50
|
-
raise 'params missing' unless @req.params
|
|
51
|
-
raise 'param id missing' unless @req.params['id']
|
|
52
|
-
@hash = @db.delete(class_name, @req.params['id'])
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def to_json
|
|
56
|
-
@hash.to_json
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def class_name
|
|
60
|
-
self.class.to_s.downcase
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
private
|
|
64
|
-
|
|
65
|
-
def check_for_required_attributes
|
|
66
|
-
required_attributes.each do |ra|
|
|
67
|
-
if !@req.params.keys.include?(ra.to_s)
|
|
68
|
-
raise "#{ra.to_s} missing"
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def check_for_unique_attributes
|
|
74
|
-
unique_attributes.each do |ua|
|
|
75
|
-
u = self.class.find({ua.to_s => params[ua.to_s]})
|
|
76
|
-
unless u.empty?
|
|
77
|
-
raise "#{ua.to_s} not unique"
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def to_action req
|
|
83
|
-
case req.request_method
|
|
84
|
-
when 'GET'
|
|
85
|
-
:find
|
|
86
|
-
when 'POST'
|
|
87
|
-
:create
|
|
88
|
-
when 'PUT'
|
|
89
|
-
:update
|
|
90
|
-
when 'DELETE'
|
|
91
|
-
:delete
|
|
92
|
-
when 'SEARCH'
|
|
93
|
-
:find
|
|
94
|
-
else
|
|
95
|
-
raise 'unkown action'
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
# calls method m + before and after methods
|
|
100
|
-
def ccall m
|
|
101
|
-
before_all
|
|
102
|
-
send "before_#{m.to_s}".to_sym
|
|
103
|
-
send m.to_sym
|
|
104
|
-
send "after_#{m.to_s}".to_sym
|
|
105
|
-
after_all
|
|
106
|
-
rescue BSON::InvalidObjectId
|
|
107
|
-
raise "invalid id format: #{params['id']}"
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|