ki 0.2.1 → 0.2.2

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -0,0 +1,16 @@
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/ki.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "ki"
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Cristian Mircea Messel"]
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
33
33
  "examples/base/Gemfile.lock",
34
34
  "examples/base/app.rb",
35
35
  "examples/base/config.ru",
36
+ "examples/base/config.yml",
36
37
  "gfx/colors.xcf",
37
38
  "gfx/ki3.eps",
38
39
  "gfx/logo.png",
data/lib/db.rb CHANGED
@@ -47,8 +47,9 @@ module Ki
47
47
  end
48
48
 
49
49
  def config_db
50
- yaml = read_yaml
51
- config yaml['host'], yaml['port'], yaml['db_name']
50
+ config_path = File.join(Dir.pwd, 'config.yml')
51
+ yaml = YAML.load_file(config_path)
52
+ config yaml['database_host'], yaml['database_port'], yaml['database_name']
52
53
  end
53
54
 
54
55
  def config host, port, db_name
@@ -59,22 +60,6 @@ module Ki
59
60
  puts "Could not connect to MongoDB"
60
61
  exit 1
61
62
  end
62
-
63
- private
64
-
65
- def read_yaml
66
- config_path = File.join(Dir.pwd, 'config.yml')
67
- yaml = {}
68
- if File.exists? config_path
69
- YAML.load_file(config_path)
70
- else
71
- {
72
- 'host' => '127.0.0.1',
73
- 'port' => 27017,
74
- 'db_name' => Util.app_name
75
- }
76
- end
77
- end
78
63
  end
79
64
  end
80
65
 
data/lib/ki.rb CHANGED
@@ -22,3 +22,8 @@ module Ki
22
22
  end
23
23
  end
24
24
  end
25
+
26
+ Dir['public/**/**'].each do |s|
27
+ Ki::StaticFile.compile_css(s)
28
+ Ki::StaticFile.compile_js(s)
29
+ end
data/lib/ki_cli.rb CHANGED
@@ -10,14 +10,6 @@ class KiGenerator < Thor::Group
10
10
  end
11
11
  end
12
12
 
13
- class ConfigGenerator < KiGenerator
14
- def generate
15
- create_file 'config.yml' do
16
- "host: 127.0.0.1\nport: 27017\ndb_name: #{Ki::Util.app_name}\n"
17
- end
18
- end
19
- end
20
-
21
13
  class AppGenerator < KiGenerator
22
14
 
23
15
  argument :app_name
@@ -38,7 +30,7 @@ class AppGenerator < KiGenerator
38
30
  def create_app
39
31
  dest_root = File.join(Dir.pwd, app_name)
40
32
 
41
- ['Gemfile', 'config.ru', 'app.rb'].each do |f|
33
+ ['Gemfile', 'config.ru', 'app.rb', 'config.yml'].each do |f|
42
34
  copy_file f, File.join(dest_root, f)
43
35
  end
44
36
  end
@@ -46,7 +38,6 @@ end
46
38
 
47
39
  class KiCli < Thor
48
40
  register AppGenerator, :new, 'new [APP_NAME]', 'generate a new app'
49
- register ConfigGenerator, :config, 'config', 'generate a new config.yml'
50
41
 
51
42
  desc 'server', 'starts the app'
52
43
  # method_option :reload, :type => :boolean, :aliases => '-r', :desc => 'Recommended for development'
@@ -12,6 +12,15 @@ module Ki
12
12
  end
13
13
  end
14
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
+
15
24
  def create hash
16
25
  Db.instance.create class_name, hash
17
26
  end
data/lib/static_file.rb CHANGED
@@ -20,26 +20,46 @@ module Ki
20
20
 
21
21
  def self.compile_js filename
22
22
  if filename.end_with? '.js'
23
- path = File.join(Util.root, filename)
24
- coffee_path = path.gsub('.js', '.coffee')
25
- if File.exists? coffee_path
26
- cont = CoffeeScript.compile File.read(coffee_path)
27
- File.open(path, 'w') do |f|
28
- f.puts cont
29
- end
30
- end
23
+ js_path = File.join(Util.root, filename)
24
+ coffee_path = js_path.gsub('.js', '.coffee')
25
+ coffee_to_js coffee_path, js_path
26
+ elsif filename.end_with? '.coffee'
27
+ coffee_path = File.join(Util.root, filename)
28
+ js_path = coffee_path.gsub('.coffee', '.js')
29
+ coffee_to_js coffee_path, js_path
31
30
  end
32
31
  end
33
32
 
34
33
  def self.compile_css filename
35
34
  if filename.end_with? '.css'
36
- path = File.join(Util.root, filename)
37
- sass_path = path.gsub('.css', '.sass')
38
- if File.exists? sass_path
39
- eng = Sass::Engine.new(File.read(sass_path), :syntax => :sass)
40
- File.open(path, 'w') do |f|
41
- f.puts eng.render
42
- end
35
+ css_path = File.join(Util.root, filename)
36
+ sass_path = css_path.gsub('.css', '.sass')
37
+ sass_to_css sass_path, css_path
38
+ elsif filename.end_with? '.sass'
39
+ sass_path = File.join(Util.root, filename)
40
+ css_path = sass_path.gsub('.sass', '.css')
41
+ sass_to_css sass_path, css_path
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def self.sass_to_css sass_path, css_path
48
+ if File.exists? sass_path
49
+ p "Compiling #{sass_path}"
50
+ eng = Sass::Engine.new(File.read(sass_path), :syntax => :sass)
51
+ File.open(css_path, 'w') do |f|
52
+ f.puts eng.render
53
+ end
54
+ end
55
+ end
56
+
57
+ def self.coffee_to_js coffee_path, js_path
58
+ if File.exists? coffee_path
59
+ p "Compiling #{coffee_path}"
60
+ cont = CoffeeScript.compile(File.read(coffee_path))
61
+ File.open(js_path, 'w') do |f|
62
+ f.puts cont
43
63
  end
44
64
  end
45
65
  end
@@ -75,4 +75,19 @@ describe Ki::QueryInterface do
75
75
  Software.find(id)['version'].should == 1.2
76
76
  }.to change(Software, :count).by(0)
77
77
  end
78
+
79
+ it "should find or create" do
80
+ class Crab < Ki::Model
81
+ end
82
+ hash = {'user' => 'name', 'birth' => '2015'}
83
+
84
+ Crab.find(hash).empty?.should be_true
85
+ expect {
86
+ Crab.find_or_create hash
87
+ }.to change(Crab, :count).by(1)
88
+
89
+ expect {
90
+ Crab.find_or_create hash
91
+ }.to change(Crab, :count).by(0)
92
+ end
78
93
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -292,6 +292,7 @@ files:
292
292
  - examples/base/Gemfile.lock
293
293
  - examples/base/app.rb
294
294
  - examples/base/config.ru
295
+ - examples/base/config.yml
295
296
  - gfx/colors.xcf
296
297
  - gfx/ki3.eps
297
298
  - gfx/logo.png
@@ -342,7 +343,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
342
343
  version: '0'
343
344
  segments:
344
345
  - 0
345
- hash: -2680538544156376822
346
+ hash: 524519885161704144
346
347
  required_rubygems_version: !ruby/object:Gem::Requirement
347
348
  none: false
348
349
  requirements: