g2 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c73c1365f8686c7938c56686f7e8dce9934d1531
4
- data.tar.gz: 0bcfa1eeaf1b245d3f1e0920bb03f37541a86ccb
3
+ metadata.gz: 0bf5bcca29bb9fea528235464c1e32e0b6b236ba
4
+ data.tar.gz: 3282c4b1bb2bbbf967b9d799221c6f401e366d73
5
5
  SHA512:
6
- metadata.gz: bb3d9b5ae6032b10abf1f211ac90b0009b351634346e226353b7a466d0bdf19ae0847d18abb0c25b2123989596df2801b29e7bb25e0f527d9fdf1a626f2a620b
7
- data.tar.gz: 27ea9ba2d8432ad6d347ec7b88a1fabcf3cd64005814d6e53d3011361aeab18106832e183de6ab8c689754245de3b5512f4a41412b8038d7fe8bfc1a0655b279
6
+ metadata.gz: d09081eecc157bcd5ded193736cd2a177ee4f6e255c1d3a922b1d47d11dbe5f6f56448d3eea942aff0b3d621ac7aa91042c8fa6e58ed0e0aa64d05f68549edc3
7
+ data.tar.gz: bfc93cda1577268d0375391d2649dad4b4ea9ca4aa66249cab4f3df8179b2643d0ce61b7108535e1c3caa6948719b90f70107e0069be1fdc80f9f83f2ba8216b
@@ -6,7 +6,7 @@ module G2
6
6
 
7
7
  source_root File.dirname(__FILE__)
8
8
 
9
- desc "new", "create a new grape goliath application"
9
+ desc "new [app]", "create a new grape goliath application"
10
10
  def new app_root
11
11
  say "create a new grape goliath application named #{app_root}", :green
12
12
  @app_name = app_root.capitalize
@@ -19,8 +19,10 @@ module G2
19
19
  # create basic files
20
20
  {
21
21
  application: "config/application.rb",
22
+ database: "config/database.yml",
22
23
  spec_helper: "spec/spec_helper.rb",
23
24
  gemfile: "Gemfile",
25
+ guardfile: "Guardfile",
24
26
  rakefile: "Rakefile",
25
27
  rspec_config: ".rspec",
26
28
  server: "script/server.rb"
@@ -33,13 +35,13 @@ module G2
33
35
  end
34
36
  end
35
37
 
36
- desc "server", "start goliath server"
38
+ desc "s [options]", "start goliath server"
37
39
  method_option :port, :aliases => "-p", :desc => "server port"
38
40
  method_option :environment, :aliases => "-e", :desc => "server environment"
39
41
  method_option :pid, :aliases => "-P", :desc => "server pid path"
40
42
  method_option :log, :aliases => "-l", :desc => "server log path"
41
43
  method_option :daemon, :aliases => "-d", :desc => "run server as daemon"
42
- def server
44
+ def s
43
45
  command = "ruby script/server.rb -p #{options[:port] || 3030} -e #{options[:environment] || 'development'}"
44
46
 
45
47
  if options[:log]
@@ -57,12 +59,14 @@ module G2
57
59
  exec command
58
60
  end
59
61
 
60
- desc "console", "start console"
61
- def console
62
+ desc "c", "start console"
63
+ def c
64
+ say "not implemented yet ):", :yellow
62
65
  end
63
66
 
64
- desc "generator", "generate files"
65
- def generate
67
+ desc "g", "generate files"
68
+ def g
69
+ say "not implemented yet ):", :yellow
66
70
  end
67
71
 
68
72
  end
@@ -1,34 +1,15 @@
1
- app_dir = File.expand_path("../../app", __FILE__)
1
+ db_config = YAML.load_file(G2.config.config_dir + '/database.yml')
2
+ ActiveRecord::Base.establish_connection(db_config[G2.env.to_s])
2
3
 
3
- %w{apis helpers models}.each do |dir|
4
- $LOAD_PATH.unshift File.join(app_dir, dir)
5
- end
6
-
7
- $app_resources = { }
8
-
9
- [:apis, :helpers, :models].each do |item|
10
- $app_resources[item] = []
11
-
12
- Dir.foreach(File.join(app_dir, item.to_s)) do |entry|
13
- next if entry == "." || entry == ".."
14
- if entry.end_with?("rb")
15
- file_name = entry.split(".rb").first.camelize
16
- require entry
17
-
18
- $app_resources[item] << file_name.constantize
19
- end
20
- end
21
- end
22
-
23
- module <%= @app_name %>
4
+ module Gog2
24
5
  class Application < Grape::API
25
6
  format :json
26
7
 
27
- $app_resources[:helpers].each do |helper_item|
8
+ G2.config.app_resources[:helpers].each do |helper_item|
28
9
  helper helper_item
29
10
  end
30
11
 
31
- $app_resources[:apis].each do |api_item|
12
+ G2.config.app_resources[:apis].each do |api_item|
32
13
  mount api_item
33
14
  end
34
15
  end
@@ -0,0 +1,16 @@
1
+ defaults: &defaults
2
+ adapter: mysql2
3
+ encoding: utf8
4
+ pool: 5
5
+ host: localhost
6
+ username: root
7
+ password: root
8
+
9
+ development:
10
+ <<: *defaults
11
+ database: <%= @app_name %>_development
12
+
13
+ test:
14
+ <<: *defaults
15
+ database: <%= @app_name %>_test
16
+
@@ -6,9 +6,13 @@ gem 'em-synchrony'
6
6
 
7
7
  gem 'activerecord', '~> 4.0.2'
8
8
  gem 'mysql2'
9
+ gem 'em-http-request'
10
+
11
+ group :development do
12
+ gem 'guard-rspec'
13
+ end
9
14
 
10
15
  group :test do
11
16
  gem 'factory_girl'
12
17
  gem 'rspec'
13
- gem 'rack-test', require: 'rack/test'
14
18
  end
@@ -0,0 +1,8 @@
1
+ guard :rspec do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^app/apis/(.+)\.rb$}) { |m| "spec/apis/#{m[1]}_spec.rb" }
4
+ watch(%r{^app/models/(.+)\.rb$}) { |m| "spec/models/#{m[1]}_spec.rb" }
5
+ watch(%r{^app/helpers/(.+)\.rb$}) { |m| "spec/helpers/#{m[1]}_spec.rb" }
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
@@ -1,9 +1,68 @@
1
1
  require "rubygems"
2
2
  require "bundler/setup"
3
+
3
4
  require "active_support"
4
- require 'goliath'
5
- require 'em-synchrony/activerecord'
6
- require 'grape'
5
+ require "grape"
6
+ require "goliath"
7
+ require "em-synchrony/activerecord"
8
+ require 'yaml'
9
+ require 'mysql2'
10
+
11
+ require "pry"
12
+
13
+ class G2
14
+ def self.config
15
+ @instance ||= G2.new
16
+ end
17
+
18
+ def self.env
19
+ Goliath.env
20
+ end
21
+
22
+ def root_dir
23
+ @root_dir ||= File.expand_path("../..", __FILE__)
24
+ end
25
+
26
+ def app_dir
27
+ @app_dir ||= File.join(root_dir, "app")
28
+ end
29
+
30
+ def config_dir
31
+ @config_dir ||= File.join(root_dir, "config")
32
+ end
33
+
34
+ def app_resources
35
+ @app_resources ||= load_resources
36
+ end
37
+
38
+ private
39
+
40
+ def load_resources
41
+ app_resources = { }
42
+
43
+ [:apis, :helpers, :models].each do |item|
44
+ app_resources[item] = []
45
+
46
+ Dir.foreach(File.join(app_dir, item.to_s)) do |entry|
47
+ next if entry == "." || entry == ".."
48
+ if entry.end_with?("rb")
49
+ file_name = entry.split(".rb").first.camelize
50
+ require entry
51
+
52
+ app_resources[item] << file_name.constantize
53
+ end
54
+ end
55
+ end
56
+
57
+ app_resources
58
+ end
59
+
60
+ end
61
+
62
+ %w{apis helpers models}.each do |dir|
63
+ $LOAD_PATH.unshift File.join(G2.config.app_dir, dir)
64
+ end
65
+ $LOAD_PATH.unshift G2.config.config_dir
7
66
 
8
67
  Goliath::Request.log_block = proc do |env, response, elapsed_time|
9
68
  request_params = env.params.collect { |param| param.join(": ") }
@@ -14,7 +73,7 @@ Goliath::Request.log_block = proc do |env, response, elapsed_time|
14
73
  env[Goliath::Request::RACK_LOGGER].info("#{response.status} #{method} #{path} in #{'%.2f' % elapsed_time} ms")
15
74
  end
16
75
 
17
- require File.expand_path('../../config/application', __FILE__)
76
+ require "application"
18
77
 
19
78
  class Boot < Goliath::API
20
79
  use Goliath::Rack::Params
@@ -0,0 +1,31 @@
1
+ require "goliath"
2
+ require "goliath/test_helper"
3
+ require "json"
4
+ require "pry"
5
+
6
+ Goliath.env = :test
7
+
8
+ require File.expand_path('../../script/server', __FILE__)
9
+
10
+ module ApiTestHelper
11
+ def get path, params={}, &block
12
+ with_api Boot, params do
13
+ get_request path: path do |c|
14
+ block.call c
15
+ end
16
+ end
17
+ end
18
+
19
+ def post path, params={}, &block
20
+ with_api Boot, params do
21
+ get_request path: path do |c|
22
+ block.call c
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ RSpec.configure do |c|
29
+ c.include Goliath::TestHelper
30
+ c.include ApiTestHelper
31
+ end
@@ -1,3 +1,3 @@
1
1
  module G2
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: g2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - lizhe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-04 00:00:00.000000000 Z
11
+ date: 2013-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,7 +72,9 @@ files:
72
72
  - lib/g2.rb
73
73
  - lib/g2/cli.rb
74
74
  - lib/g2/templates/application.erb
75
+ - lib/g2/templates/database.erb
75
76
  - lib/g2/templates/gemfile.erb
77
+ - lib/g2/templates/guardfile.erb
76
78
  - lib/g2/templates/rakefile.erb
77
79
  - lib/g2/templates/rspec_config.erb
78
80
  - lib/g2/templates/server.erb