grape-cli 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +18 -0
- data/Gemfile +7 -0
- data/Guardfile +12 -0
- data/README.md +31 -7
- data/Rakefile +5 -5
- data/bin/_guard-core +15 -0
- data/bin/console +3 -3
- data/bin/grape +3 -3
- data/bin/guard +15 -0
- data/grape-cli.gemspec +19 -19
- data/lib/grape_cli/actions/create_application.rb +13 -0
- data/lib/grape_cli/actions/setup_database.rb +14 -0
- data/lib/grape_cli/actions/setup_test_framework.rb +46 -0
- data/lib/{grape → grape_cli}/application_factory.rb +1 -1
- data/lib/{grape → grape_cli}/class_name_generator.rb +1 -1
- data/lib/{grape → grape_cli}/command_generator.rb +4 -0
- data/lib/grape_cli/config.rb +39 -0
- data/lib/grape_cli/core.rb +59 -0
- data/lib/grape_cli/grape_cli.rb +6 -0
- data/lib/{grape/cli/template → grape_cli/templates}/application/Gemfile.tt +13 -1
- data/lib/{grape/cli/template → grape_cli/templates}/application/Rakefile.tt +17 -0
- data/lib/{grape/cli/template → grape_cli/templates}/application/app/api.rb.tt +0 -0
- data/lib/{grape/cli/template → grape_cli/templates}/application/app/resources/hello_world.rb.tt +0 -0
- data/lib/{grape/cli/template → grape_cli/templates}/application/config/application.rb +0 -0
- data/lib/{grape/cli/template → grape_cli/templates}/application/config/boot.rb +0 -0
- data/lib/{grape/cli/template → grape_cli/templates}/application/config/environment.rb +0 -0
- data/lib/{grape/cli/template → grape_cli/templates}/application/config.ru.tt +0 -0
- data/lib/{grape/cli/template → grape_cli/templates}/database/postgres.yml.tt +2 -2
- data/lib/{grape/cli/template → grape_cli/templates}/database/sqlite.yml.tt +4 -4
- data/lib/grape_cli/templates/minitest/requests/hello_world_test.rb.tt +15 -0
- data/lib/grape_cli/templates/minitest/test_helper.rb +9 -0
- data/lib/grape_cli/templates/rspec/requests/hello_world_spec.rb.tt +21 -0
- data/lib/grape_cli/templates/rspec/spec_helper.rb +14 -0
- data/lib/grape_cli/templates/rspec_config +2 -0
- data/lib/grape_cli/version.rb +3 -0
- metadata +33 -22
- data/lib/grape/cli/console.rb +0 -15
- data/lib/grape/cli/new.rb +0 -49
- data/lib/grape/cli/server.rb +0 -15
- data/lib/grape/cli/version.rb +0 -5
- data/lib/grape/cli.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98a78fca4ad2ed7b4ff0011f4d7136bfe6631532
|
4
|
+
data.tar.gz: 12c6e20d4701ce4f12ff982a77459eb7ac7f6f80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5547baf4b7274cba44ae79d402b0b153059c56706f949774d79dab8aab814a5a9ec82aff244a4f9d03396b9a2714453fd0f57068f070d1a16c223ba9f64d6d36
|
7
|
+
data.tar.gz: 9ba742abb0f7b2d49949a0be5e4d2476adda1e42856a2f0ead89198429a23ebff08bd933c4c2717ff408dc2ce339baa166e1c73cc7dac64f5874d80d09a7706c
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Documentation:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Metrics/LineLength:
|
5
|
+
Max: 120
|
6
|
+
Exclude:
|
7
|
+
- grape-cli.gemspec
|
8
|
+
- bin/_guard-core
|
9
|
+
|
10
|
+
Style/SignalException:
|
11
|
+
EnforcedStyle: only_raise
|
12
|
+
|
13
|
+
Style/ClassVars:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/FileName:
|
17
|
+
Exclude:
|
18
|
+
- bin/_guard-core
|
data/Gemfile
CHANGED
data/Guardfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
group :red_green_refactor, halt_on_fail: true do
|
2
|
+
guard :minitest, all_on_start: false do
|
3
|
+
watch(%r{^test/(.*)\/?(.*)_test\.rb$})
|
4
|
+
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
|
5
|
+
watch(%r{^test/test_helper\.rb$}) { 'test' }
|
6
|
+
end
|
7
|
+
|
8
|
+
guard :rubocop, all_on_start: false do
|
9
|
+
watch(%r{/.+\/.rb$})
|
10
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
11
|
+
end
|
12
|
+
end
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# grape-cli [![Build Status](https://travis-ci.org/elpassion/grape-cli.svg?branch=master)](https://travis-ci.org/elpassion/grape-cli) [![Code Climate](https://codeclimate.com/github/elpassion/grape-cli/badges/gpa.svg)](https://codeclimate.com/github/elpassion/grape-cli)
|
1
|
+
# grape-cli [![Build Status](https://travis-ci.org/elpassion/grape-cli.svg?branch=master)](https://travis-ci.org/elpassion/grape-cli) [![Code Climate](https://codeclimate.com/github/elpassion/grape-cli/badges/gpa.svg)](https://codeclimate.com/github/elpassion/grape-cli) [![Gem Version](https://badge.fury.io/rb/grape-cli.svg)](http://badge.fury.io/rb/grape-cli)
|
2
2
|
|
3
|
-
Grape-CLI is a gem for bootstraping standalone Grape application.
|
3
|
+
Grape-CLI is a gem for bootstraping standalone Grape application.
|
4
4
|
It is heavily inspired by Rails/Ember generators.
|
5
5
|
|
6
6
|
## Installation
|
@@ -20,26 +20,50 @@ Or install it yourself as:
|
|
20
20
|
$ gem install grape-cli
|
21
21
|
|
22
22
|
## Usage
|
23
|
+
|
24
|
+
###New application
|
23
25
|
Create new Grape app in current directory with provided application name
|
24
26
|
|
25
27
|
$ grape new application_name
|
26
|
-
|
27
|
-
|
28
|
+
|
29
|
+
For new command you can provide multiple options:
|
30
|
+
|
31
|
+
###Test framework
|
32
|
+
|
33
|
+
$ grape new application_name --test=minitest
|
34
|
+
|
35
|
+
|
36
|
+
will create new application with minitest as test framework,
|
37
|
+
running new command without specifying `--test` option will setup application with RSpec as it's default one.
|
38
|
+
|
39
|
+
###Database
|
40
|
+
|
41
|
+
$ grape new application_name --database=postgres
|
42
|
+
|
43
|
+
|
44
|
+
will create new application with postgres as database,
|
45
|
+
running new command without specifying `--database` option will setup application with sqlite as it's default one.
|
46
|
+
|
47
|
+
###Start application server
|
28
48
|
|
29
49
|
$ cd application_name
|
30
50
|
$ grape server
|
31
|
-
or
|
51
|
+
or
|
32
52
|
|
33
53
|
$ grape s
|
34
54
|
Go to http://localhost:9292/
|
35
55
|
|
36
|
-
Start application console
|
56
|
+
###Start application console
|
37
57
|
|
38
58
|
$ grape console
|
39
|
-
or
|
59
|
+
or
|
40
60
|
|
41
61
|
$ grape c
|
42
62
|
|
63
|
+
###Run your application tets
|
64
|
+
|
65
|
+
$ grape test
|
66
|
+
|
43
67
|
|
44
68
|
## Contributing
|
45
69
|
|
data/Rakefile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
3
|
|
4
4
|
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs <<
|
6
|
-
t.libs <<
|
5
|
+
t.libs << 'test'
|
6
|
+
t.libs << 'lib'
|
7
7
|
t.test_files = FileList['test/**/*_test.rb']
|
8
8
|
end
|
9
9
|
|
10
|
-
task :
|
10
|
+
task default: :test
|
data/bin/_guard-core
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application '_guard-core' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', Pathname.new(__FILE__).realpath)
|
11
|
+
|
12
|
+
require 'rubygems'
|
13
|
+
require 'bundler/setup'
|
14
|
+
|
15
|
+
load Gem.bin_path('guard', '_guard-core')
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'grape/cli'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "grape/cli"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start
|
data/bin/grape
CHANGED
data/bin/guard
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'guard' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'pathname'
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', Pathname.new(__FILE__).realpath)
|
11
|
+
|
12
|
+
require 'rubygems'
|
13
|
+
require 'bundler/setup'
|
14
|
+
|
15
|
+
load Gem.bin_path('guard', 'guard')
|
data/grape-cli.gemspec
CHANGED
@@ -1,37 +1,37 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require '
|
4
|
+
require 'grape_cli/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
-
spec.version =
|
9
|
-
spec.authors =
|
10
|
-
spec.email =
|
7
|
+
spec.name = 'grape-cli'
|
8
|
+
spec.version = GrapeCli::VERSION
|
9
|
+
spec.authors = %w(wswidzinski michalwarda koszcz ghostbuster91)
|
10
|
+
spec.email = %w(swidzinskiw@gmail.com)
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
12
|
+
spec.summary = 'Grape-CLI is a gem for bootstraping standalone Grape application.'
|
13
|
+
spec.description = 'Grape-CLI is a gem for bootstraping standalone Grape application. It is heavily inspired by Rails/Ember generators.'
|
14
|
+
spec.homepage = 'http://github.com/elpassion/grape-cli'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
18
|
# delete this section to allow pushing this gem to any host.
|
19
19
|
if spec.respond_to?(:metadata)
|
20
20
|
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
21
|
else
|
22
|
-
raise
|
22
|
+
raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
|
23
23
|
end
|
24
24
|
|
25
25
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
-
spec.bindir =
|
27
|
-
spec.executables = [
|
28
|
-
spec.require_paths = [
|
26
|
+
spec.bindir = 'bin'
|
27
|
+
spec.executables = ['grape']
|
28
|
+
spec.require_paths = ['lib']
|
29
29
|
|
30
|
-
spec.add_dependency
|
31
|
-
spec.add_dependency
|
32
|
-
spec.add_dependency
|
30
|
+
spec.add_dependency 'thor', '~> 0.19'
|
31
|
+
spec.add_dependency 'bundler', '~> 1.10'
|
32
|
+
spec.add_dependency 'racksh'
|
33
33
|
|
34
|
-
spec.add_development_dependency
|
35
|
-
spec.add_development_dependency
|
36
|
-
spec.add_development_dependency
|
34
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
35
|
+
spec.add_development_dependency 'minitest'
|
36
|
+
spec.add_development_dependency 'pry'
|
37
37
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
3
|
+
module GrapeCli
|
4
|
+
module Actions
|
5
|
+
class CreateApplication < SimpleDelegator
|
6
|
+
def run(config, destination_path)
|
7
|
+
source_path = File.join(config[:source_root], 'templates', 'application')
|
8
|
+
|
9
|
+
directory(source_path, destination_path, config)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
3
|
+
module GrapeCli
|
4
|
+
module Actions
|
5
|
+
class SetupDatabase < SimpleDelegator
|
6
|
+
def run(config)
|
7
|
+
source_path = File.join(config[:source_root], 'templates', 'database', "#{options[:database]}.yml.tt")
|
8
|
+
destination_path = File.join(options[:work_dir], config[:app_name], 'config', 'database.yml')
|
9
|
+
|
10
|
+
template(source_path, destination_path, config)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module GrapeCli
|
2
|
+
module Actions
|
3
|
+
class SetupTestFramework
|
4
|
+
include Thor::Base
|
5
|
+
include Thor::Actions
|
6
|
+
|
7
|
+
attr_reader :options, :config
|
8
|
+
|
9
|
+
def self.source_root
|
10
|
+
File.dirname(__FILE__)
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(args = [], local_options = {}, config = {})
|
14
|
+
super
|
15
|
+
@options = local_options
|
16
|
+
@config = config
|
17
|
+
end
|
18
|
+
|
19
|
+
# rubocop:disable Metrics/AbcSize
|
20
|
+
def run
|
21
|
+
source_path = File.join(config[:source_root], 'templates', options[:test])
|
22
|
+
destination_path = File.join(options[:work_dir], config[:app_name], test_directory_name)
|
23
|
+
|
24
|
+
directory(source_path, destination_path, config)
|
25
|
+
|
26
|
+
copy_rspec_config if options[:test] == 'rspec'
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def test_directory_name
|
32
|
+
{
|
33
|
+
minitest: 'test',
|
34
|
+
rspec: 'spec'
|
35
|
+
}[options[:test].to_sym]
|
36
|
+
end
|
37
|
+
|
38
|
+
def copy_rspec_config
|
39
|
+
source_path = File.join(config[:source_root], 'templates', 'rspec_config')
|
40
|
+
destination_path = File.join(options[:work_dir], config[:app_name], '.rspec')
|
41
|
+
|
42
|
+
template(source_path, destination_path, config)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'grape_cli/class_name_generator'
|
2
|
+
require 'grape_cli/application_factory'
|
3
|
+
|
4
|
+
module GrapeCli
|
5
|
+
class Config
|
6
|
+
attr_reader :app_name, :options, :source_root
|
7
|
+
|
8
|
+
def initialize(app_name, source_root, options = {})
|
9
|
+
@app_name = app_name
|
10
|
+
@options = options
|
11
|
+
@source_root = source_root
|
12
|
+
end
|
13
|
+
|
14
|
+
def config
|
15
|
+
{
|
16
|
+
source_root: source_root,
|
17
|
+
app_name: app_name,
|
18
|
+
class_name: ClassNameGenerator.new(app_name).generate,
|
19
|
+
database: options[:database],
|
20
|
+
database_gem: database_gem,
|
21
|
+
rspec: rspec?,
|
22
|
+
verbose: ApplicationFactory.instance.verbose_output
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def rspec?
|
29
|
+
options[:test] == 'rspec'
|
30
|
+
end
|
31
|
+
|
32
|
+
def database_gem
|
33
|
+
{
|
34
|
+
postgres: 'pg',
|
35
|
+
sqlite: 'sqlite3'
|
36
|
+
}[options[:database].to_sym]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'grape_cli/application_factory'
|
2
|
+
require 'grape_cli/config'
|
3
|
+
require 'grape_cli/actions/create_application'
|
4
|
+
require 'grape_cli/actions/setup_database'
|
5
|
+
require 'grape_cli/actions/setup_test_framework'
|
6
|
+
|
7
|
+
module GrapeCli
|
8
|
+
class Core < Thor
|
9
|
+
include Thor::Actions
|
10
|
+
|
11
|
+
desc 'new APP_NAME', 'Create a new Grape application'
|
12
|
+
|
13
|
+
method_option :work_dir, default: Dir.pwd
|
14
|
+
method_option :database, aliases: 'd', default: 'sqlite', enum: %w(postgres sqlite)
|
15
|
+
method_option :test, aliases: 't', default: 'minitest', enum: %w(minitest rspec)
|
16
|
+
|
17
|
+
def self.source_root
|
18
|
+
File.dirname(__FILE__)
|
19
|
+
end
|
20
|
+
|
21
|
+
# rubocop:disable Metrics/AbcSize
|
22
|
+
def new(app_name)
|
23
|
+
config = GrapeCli::Config.new(app_name, GrapeCli::Core.source_root, options).config
|
24
|
+
application_path = File.join(options[:work_dir], app_name)
|
25
|
+
|
26
|
+
GrapeCli::Actions::CreateApplication.new(self).run(config, application_path)
|
27
|
+
GrapeCli::Actions::SetupDatabase.new(self).run(config)
|
28
|
+
GrapeCli::Actions::SetupTestFramework.new(args, options, config).run
|
29
|
+
|
30
|
+
inside application_path do
|
31
|
+
run(ApplicationFactory.instance.command_generator.bundle_install, config)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'server', 'Start the Grape server, alias "s"'
|
36
|
+
map 's' => 'server'
|
37
|
+
|
38
|
+
def server
|
39
|
+
puts 'Starting Grape server...'
|
40
|
+
|
41
|
+
run(ApplicationFactory.new.command_generator.run_server, verbose: false)
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'console', 'Start the Grape console, alias "c"'
|
45
|
+
map 'c' => 'console'
|
46
|
+
|
47
|
+
def console
|
48
|
+
puts 'Starting Grape console...'
|
49
|
+
|
50
|
+
run(ApplicationFactory.instance.command_generator.run_console, verbose: false)
|
51
|
+
end
|
52
|
+
|
53
|
+
desc 'test', 'Start tests'
|
54
|
+
|
55
|
+
def test
|
56
|
+
run(ApplicationFactory.instance.command_generator.run_tests, verbose: false)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -8,7 +8,19 @@ gem 'activerecord', '~> 4.2.1', require: 'active_record'
|
|
8
8
|
gem 'grape-activerecord'
|
9
9
|
gem 'grape-swagger', '~> 0.10.2'
|
10
10
|
gem 'rack', '~> 1.6.0'
|
11
|
-
|
11
|
+
|
12
|
+
<% if config[:rspec] %>
|
13
|
+
group :test do
|
14
|
+
gem 'rspec', '~> 3.3'
|
15
|
+
gem 'rack-test', '~> 0.6.3'
|
16
|
+
end
|
17
|
+
<% else %>
|
18
|
+
group :test do
|
19
|
+
gem 'minitest', '~> 5.8.0'
|
20
|
+
gem 'minitest-reporters'
|
21
|
+
gem 'rack-test', '~> 0.6.3'
|
22
|
+
end
|
23
|
+
<% end %>
|
12
24
|
|
13
25
|
group :development, :test do
|
14
26
|
gem 'rake', '~> 10.4.2'
|
@@ -11,6 +11,23 @@ rescue Bundler::BundlerError => e
|
|
11
11
|
end
|
12
12
|
|
13
13
|
require 'rake'
|
14
|
+
<% if config[:rspec] %>
|
15
|
+
require 'rspec/core/rake_task'
|
16
|
+
|
17
|
+
RSpec::Core::RakeTask.new(:spec)
|
18
|
+
|
19
|
+
task :default => :spec
|
20
|
+
<% else %>
|
21
|
+
require "rake/testtask"
|
22
|
+
|
23
|
+
Rake::TestTask.new(:test) do |t|
|
24
|
+
t.libs << "test"
|
25
|
+
t.libs << "lib"
|
26
|
+
t.test_files = FileList['test/**/*_test.rb']
|
27
|
+
end
|
28
|
+
|
29
|
+
task :default => :test
|
30
|
+
<% end %>
|
14
31
|
|
15
32
|
task :environment do
|
16
33
|
ENV['RACK_ENV'] ||= 'development'
|
File without changes
|
data/lib/{grape/cli/template → grape_cli/templates}/application/app/resources/hello_world.rb.tt
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -7,11 +7,11 @@ default: &default
|
|
7
7
|
|
8
8
|
development:
|
9
9
|
<<: *default
|
10
|
-
database: <%= config[:app_name] %>
|
10
|
+
database: <%= config[:app_name] %>_development
|
11
11
|
|
12
12
|
test:
|
13
13
|
<<: *default
|
14
|
-
database: <%= config[:app_name] %>
|
14
|
+
database: <%= config[:app_name] %>_test
|
15
15
|
|
16
16
|
production:
|
17
17
|
url: <%= ENV['DATABASE_URL'] %>
|
@@ -8,18 +8,18 @@ default: &default
|
|
8
8
|
adapter: sqlite3
|
9
9
|
pool: 5
|
10
10
|
timeout: 5000
|
11
|
-
|
11
|
+
|
12
12
|
development:
|
13
13
|
<<: *default
|
14
14
|
database: db/development.sqlite3
|
15
|
-
|
15
|
+
|
16
16
|
# Warning: The database defined as "test" will be erased and
|
17
17
|
# re-generated from your development database when you run "rake".
|
18
18
|
# Do not set this db to the same as development or production.
|
19
19
|
test:
|
20
20
|
<<: *default
|
21
21
|
database: db/test.sqlite3
|
22
|
-
|
22
|
+
|
23
23
|
production:
|
24
24
|
<<: *default
|
25
|
-
database: db/production.sqlite3
|
25
|
+
database: db/production.sqlite3
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class HelloWorldTest < MiniTest::Test
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
def app
|
7
|
+
<%= config[:class_name] %>::API
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_api_get_hello_world
|
11
|
+
get '/api/hello_world'
|
12
|
+
assert last_response.ok?
|
13
|
+
assert_equal 'hello world', JSON.parse(last_response.body)['message']
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
describe 'Hello World Resource' do
|
2
|
+
include Rack::Test::Methods
|
3
|
+
|
4
|
+
def app
|
5
|
+
<%= config[:class_name] %>::API
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'GET /api/hello_world' do
|
9
|
+
subject { get '/api/hello_world' }
|
10
|
+
|
11
|
+
it 'returns 200 status code' do
|
12
|
+
subject
|
13
|
+
expect(last_response.status).to eq 200
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'returns proper body' do
|
17
|
+
subject
|
18
|
+
expect(JSON.parse(last_response.body)['message']).to eq 'hello world'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rack/test'
|
2
|
+
|
3
|
+
ENV['RACK_ENV'] = 'test'
|
4
|
+
|
5
|
+
require File.expand_path('../../config/environment', __FILE__)
|
6
|
+
|
7
|
+
ActiveRecord::Base.logger = nil
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.mock_with :rspec
|
11
|
+
config.expect_with :rspec
|
12
|
+
config.raise_errors_for_deprecations!
|
13
|
+
config.order = 'random'
|
14
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- wswidzinski
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-
|
14
|
+
date: 2015-10-04 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: thor
|
@@ -97,8 +97,8 @@ dependencies:
|
|
97
97
|
- - ">="
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '0'
|
100
|
-
description:
|
101
|
-
is heavily inspired by Rails/Ember generators.
|
100
|
+
description: Grape-CLI is a gem for bootstraping standalone Grape application. It
|
101
|
+
is heavily inspired by Rails/Ember generators.
|
102
102
|
email:
|
103
103
|
- swidzinskiw@gmail.com
|
104
104
|
executables:
|
@@ -107,34 +107,45 @@ extensions: []
|
|
107
107
|
extra_rdoc_files: []
|
108
108
|
files:
|
109
109
|
- ".gitignore"
|
110
|
+
- ".rubocop.yml"
|
110
111
|
- ".travis.yml"
|
111
112
|
- CODE_OF_CONDUCT.md
|
112
113
|
- Gemfile
|
114
|
+
- Guardfile
|
113
115
|
- LICENSE.txt
|
114
116
|
- README.md
|
115
117
|
- Rakefile
|
118
|
+
- bin/_guard-core
|
116
119
|
- bin/console
|
117
120
|
- bin/grape
|
121
|
+
- bin/guard
|
118
122
|
- bin/setup
|
119
123
|
- grape-cli.gemspec
|
120
|
-
- lib/
|
121
|
-
- lib/
|
122
|
-
- lib/
|
123
|
-
- lib/
|
124
|
-
- lib/
|
125
|
-
- lib/
|
126
|
-
- lib/
|
127
|
-
- lib/
|
128
|
-
- lib/
|
129
|
-
- lib/
|
130
|
-
- lib/
|
131
|
-
- lib/
|
132
|
-
- lib/
|
133
|
-
- lib/
|
134
|
-
- lib/
|
135
|
-
- lib/
|
136
|
-
- lib/
|
137
|
-
- lib/
|
124
|
+
- lib/grape_cli/actions/create_application.rb
|
125
|
+
- lib/grape_cli/actions/setup_database.rb
|
126
|
+
- lib/grape_cli/actions/setup_test_framework.rb
|
127
|
+
- lib/grape_cli/application_factory.rb
|
128
|
+
- lib/grape_cli/class_name_generator.rb
|
129
|
+
- lib/grape_cli/command_generator.rb
|
130
|
+
- lib/grape_cli/config.rb
|
131
|
+
- lib/grape_cli/core.rb
|
132
|
+
- lib/grape_cli/grape_cli.rb
|
133
|
+
- lib/grape_cli/templates/application/Gemfile.tt
|
134
|
+
- lib/grape_cli/templates/application/Rakefile.tt
|
135
|
+
- lib/grape_cli/templates/application/app/api.rb.tt
|
136
|
+
- lib/grape_cli/templates/application/app/resources/hello_world.rb.tt
|
137
|
+
- lib/grape_cli/templates/application/config.ru.tt
|
138
|
+
- lib/grape_cli/templates/application/config/application.rb
|
139
|
+
- lib/grape_cli/templates/application/config/boot.rb
|
140
|
+
- lib/grape_cli/templates/application/config/environment.rb
|
141
|
+
- lib/grape_cli/templates/database/postgres.yml.tt
|
142
|
+
- lib/grape_cli/templates/database/sqlite.yml.tt
|
143
|
+
- lib/grape_cli/templates/minitest/requests/hello_world_test.rb.tt
|
144
|
+
- lib/grape_cli/templates/minitest/test_helper.rb
|
145
|
+
- lib/grape_cli/templates/rspec/requests/hello_world_spec.rb.tt
|
146
|
+
- lib/grape_cli/templates/rspec/spec_helper.rb
|
147
|
+
- lib/grape_cli/templates/rspec_config
|
148
|
+
- lib/grape_cli/version.rb
|
138
149
|
homepage: http://github.com/elpassion/grape-cli
|
139
150
|
licenses:
|
140
151
|
- MIT
|
data/lib/grape/cli/console.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'grape/application_factory'
|
2
|
-
|
3
|
-
class GrapeCli < Thor
|
4
|
-
include Thor::Actions
|
5
|
-
|
6
|
-
desc 'console', 'Start the Grape console, alias "c"'
|
7
|
-
|
8
|
-
def console
|
9
|
-
puts 'Starting Grape console...'
|
10
|
-
|
11
|
-
run(ApplicationFactory.instance.command_generator.run_console, verbose: false)
|
12
|
-
end
|
13
|
-
|
14
|
-
map 'c' => 'console'
|
15
|
-
end
|
data/lib/grape/cli/new.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'grape/application_factory'
|
2
|
-
require 'grape/class_name_generator'
|
3
|
-
|
4
|
-
class GrapeCli < Thor
|
5
|
-
include Thor::Actions
|
6
|
-
|
7
|
-
desc "new APP_NAME", "Create a new Grape application"
|
8
|
-
|
9
|
-
method_option :work_dir, default: Dir.pwd
|
10
|
-
method_option :database, aliases: 'd', default: 'postgres'
|
11
|
-
|
12
|
-
def self.source_root
|
13
|
-
File.dirname(__FILE__)
|
14
|
-
end
|
15
|
-
|
16
|
-
def new(app_name)
|
17
|
-
template_path = File.join(GrapeCli.source_root, 'template')
|
18
|
-
application_template_path = File.join(template_path, 'application')
|
19
|
-
destination_path = File.join(options[:work_dir], app_name)
|
20
|
-
config = create_config(app_name)
|
21
|
-
|
22
|
-
directory(application_template_path, destination_path, config)
|
23
|
-
template(File.join(template_path, 'database', "#{options[:database]}.yml.tt"),
|
24
|
-
File.join(destination_path, 'config', 'database.yml'), config)
|
25
|
-
inside destination_path do
|
26
|
-
run(ApplicationFactory.instance.command_generator.bundle_install, config)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def create_config(app_name)
|
33
|
-
{
|
34
|
-
app_name: app_name,
|
35
|
-
class_name: ClassNameGenerator.new(app_name).generate,
|
36
|
-
database: options[:database],
|
37
|
-
database_gem: database_gem(options[:database]),
|
38
|
-
verbose: ApplicationFactory.instance.verbose_output
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
|
43
|
-
def database_gem(database)
|
44
|
-
{
|
45
|
-
postgres: 'pg',
|
46
|
-
sqlite: 'sqlite3'
|
47
|
-
}[database.to_sym]
|
48
|
-
end
|
49
|
-
end
|
data/lib/grape/cli/server.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'grape/application_factory'
|
2
|
-
|
3
|
-
class GrapeCli < Thor
|
4
|
-
include Thor::Actions
|
5
|
-
|
6
|
-
desc 'server', 'Start the Grape server, alias "s"'
|
7
|
-
|
8
|
-
def server
|
9
|
-
puts 'Starting Grape server...'
|
10
|
-
|
11
|
-
run(ApplicationFactory.instance.command_generator.run_server, verbose: false)
|
12
|
-
end
|
13
|
-
|
14
|
-
map 's' => 'server'
|
15
|
-
end
|
data/lib/grape/cli/version.rb
DELETED