g2 0.0.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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/Gemfile +12 -0
- data/Guardfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/g2 +4 -0
- data/g2.gemspec +24 -0
- data/lib/g2.rb +7 -0
- data/lib/g2/cli.rb +69 -0
- data/lib/g2/templates/application.erb +35 -0
- data/lib/g2/templates/gemfile.erb +14 -0
- data/lib/g2/templates/rakefile.erb +40 -0
- data/lib/g2/templates/rspec_config.erb +1 -0
- data/lib/g2/templates/server.erb +26 -0
- data/lib/g2/templates/spec_helper.erb +0 -0
- data/lib/g2/version.rb +3 -0
- data/spec/lib/g2/cli_spec.rb +7 -0
- data/spec/spec_helper.rb +4 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c73c1365f8686c7938c56686f7e8dce9934d1531
|
4
|
+
data.tar.gz: 0bcfa1eeaf1b245d3f1e0920bb03f37541a86ccb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bb3d9b5ae6032b10abf1f211ac90b0009b351634346e226353b7a466d0bdf19ae0847d18abb0c25b2123989596df2801b29e7bb25e0f527d9fdf1a626f2a620b
|
7
|
+
data.tar.gz: 27ea9ba2d8432ad6d347ec7b88a1fabcf3cd64005814d6e53d3011361aeab18106832e183de6ab8c689754245de3b5512f4a41412b8038d7fe8bfc1a0655b279
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 lizhe
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# G2
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'g2'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install g2
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/g2
ADDED
data/g2.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'g2/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "g2"
|
8
|
+
spec.version = G2::VERSION
|
9
|
+
spec.authors = ["lizhe"]
|
10
|
+
spec.email = ["me@lizhe.name"]
|
11
|
+
spec.description = %q{a tool to help you to manage goliath grape based application}
|
12
|
+
spec.summary = %q{rock with goliath and grape}
|
13
|
+
spec.homepage = "https://github.com/markee/g2"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "thor"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
data/lib/g2.rb
ADDED
data/lib/g2/cli.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require "thor"
|
2
|
+
|
3
|
+
module G2
|
4
|
+
class Cli < Thor
|
5
|
+
include Thor::Actions
|
6
|
+
|
7
|
+
source_root File.dirname(__FILE__)
|
8
|
+
|
9
|
+
desc "new", "create a new grape goliath application"
|
10
|
+
def new app_root
|
11
|
+
say "create a new grape goliath application named #{app_root}", :green
|
12
|
+
@app_name = app_root.capitalize
|
13
|
+
|
14
|
+
# create folder structure
|
15
|
+
%w{app app/apis app/helpers app/models config config/environments db script log tmp tmp/pids spec}.each do |item|
|
16
|
+
empty_directory app_root + "/" + item
|
17
|
+
end
|
18
|
+
|
19
|
+
# create basic files
|
20
|
+
{
|
21
|
+
application: "config/application.rb",
|
22
|
+
spec_helper: "spec/spec_helper.rb",
|
23
|
+
gemfile: "Gemfile",
|
24
|
+
rakefile: "Rakefile",
|
25
|
+
rspec_config: ".rspec",
|
26
|
+
server: "script/server.rb"
|
27
|
+
}.each do |k, v|
|
28
|
+
template("templates/#{k}.erb", "#{app_root}/#{v}")
|
29
|
+
end
|
30
|
+
|
31
|
+
inside app_root do
|
32
|
+
run "bundle install"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "server", "start goliath server"
|
37
|
+
method_option :port, :aliases => "-p", :desc => "server port"
|
38
|
+
method_option :environment, :aliases => "-e", :desc => "server environment"
|
39
|
+
method_option :pid, :aliases => "-P", :desc => "server pid path"
|
40
|
+
method_option :log, :aliases => "-l", :desc => "server log path"
|
41
|
+
method_option :daemon, :aliases => "-d", :desc => "run server as daemon"
|
42
|
+
def server
|
43
|
+
command = "ruby script/server.rb -p #{options[:port] || 3030} -e #{options[:environment] || 'development'}"
|
44
|
+
|
45
|
+
if options[:log]
|
46
|
+
command += " -l #{options[:log]}"
|
47
|
+
else
|
48
|
+
command += " -s"
|
49
|
+
end
|
50
|
+
if options[:pid]
|
51
|
+
command += " -P #{options[:pid]}"
|
52
|
+
end
|
53
|
+
if options[:daemon]
|
54
|
+
command += " -d"
|
55
|
+
end
|
56
|
+
|
57
|
+
exec command
|
58
|
+
end
|
59
|
+
|
60
|
+
desc "console", "start console"
|
61
|
+
def console
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "generator", "generate files"
|
65
|
+
def generate
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
app_dir = File.expand_path("../../app", __FILE__)
|
2
|
+
|
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 %>
|
24
|
+
class Application < Grape::API
|
25
|
+
format :json
|
26
|
+
|
27
|
+
$app_resources[:helpers].each do |helper_item|
|
28
|
+
helper helper_item
|
29
|
+
end
|
30
|
+
|
31
|
+
$app_resources[:apis].each do |api_item|
|
32
|
+
mount api_item
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
|
+
require 'em-synchrony/activerecord'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
def db_conf
|
7
|
+
config = YAML.load File.read('config/database.yml')
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :db do
|
11
|
+
desc "loads database configuration in for other tasks to run"
|
12
|
+
task :load_config do
|
13
|
+
env = ENV["G2_ENV"]
|
14
|
+
ActiveRecord::Base.establish_connection db_conf[env]
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "creates and migrates your database"
|
18
|
+
task :setup => :load_config do
|
19
|
+
Rake::Task["db:create"].invoke
|
20
|
+
Rake::Task["db:migrate"].invoke
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "migrate your database"
|
24
|
+
task :migrate do
|
25
|
+
migration_path = ActiveRecord::Migrator.migrations_paths
|
26
|
+
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
27
|
+
ActiveRecord::Migrator.migrate migration_path, version
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'Drops the database'
|
31
|
+
task :drop => :load_config do
|
32
|
+
ActiveRecord::Base.connection.drop_database db_conf[env]['database']
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'Creates the database'
|
36
|
+
task :create => :load_config do
|
37
|
+
ActiveRecord::Base.connection.create_database db_conf[env]['database']
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler/setup"
|
3
|
+
require "active_support"
|
4
|
+
require 'goliath'
|
5
|
+
require 'em-synchrony/activerecord'
|
6
|
+
require 'grape'
|
7
|
+
|
8
|
+
Goliath::Request.log_block = proc do |env, response, elapsed_time|
|
9
|
+
request_params = env.params.collect { |param| param.join(": ") }
|
10
|
+
method = env[Goliath::Request::REQUEST_METHOD]
|
11
|
+
path = env[Goliath::Request::REQUEST_URI]
|
12
|
+
|
13
|
+
env[Goliath::Request::RACK_LOGGER].info("#{request_params}")
|
14
|
+
env[Goliath::Request::RACK_LOGGER].info("#{response.status} #{method} #{path} in #{'%.2f' % elapsed_time} ms")
|
15
|
+
end
|
16
|
+
|
17
|
+
require File.expand_path('../../config/application', __FILE__)
|
18
|
+
|
19
|
+
class Boot < Goliath::API
|
20
|
+
use Goliath::Rack::Params
|
21
|
+
|
22
|
+
def response(env)
|
23
|
+
<%= @app_name %>::Application.call(env)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
File without changes
|
data/lib/g2/version.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: g2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- lizhe
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: a tool to help you to manage goliath grape based application
|
56
|
+
email:
|
57
|
+
- me@lizhe.name
|
58
|
+
executables:
|
59
|
+
- g2
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- .rspec
|
65
|
+
- Gemfile
|
66
|
+
- Guardfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/g2
|
71
|
+
- g2.gemspec
|
72
|
+
- lib/g2.rb
|
73
|
+
- lib/g2/cli.rb
|
74
|
+
- lib/g2/templates/application.erb
|
75
|
+
- lib/g2/templates/gemfile.erb
|
76
|
+
- lib/g2/templates/rakefile.erb
|
77
|
+
- lib/g2/templates/rspec_config.erb
|
78
|
+
- lib/g2/templates/server.erb
|
79
|
+
- lib/g2/templates/spec_helper.erb
|
80
|
+
- lib/g2/version.rb
|
81
|
+
- spec/lib/g2/cli_spec.rb
|
82
|
+
- spec/spec_helper.rb
|
83
|
+
homepage: https://github.com/markee/g2
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.0.3
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: rock with goliath and grape
|
107
|
+
test_files:
|
108
|
+
- spec/lib/g2/cli_spec.rb
|
109
|
+
- spec/spec_helper.rb
|