grape-cli 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 12c7f4da7fe67274338d4835afd2ab92eb06cf3d
4
+ data.tar.gz: d1187e7cb21dd992a429f856ca6a992008fa24f2
5
+ SHA512:
6
+ metadata.gz: eba3e15288959cb074ddbbdbd238889d33422e15726521df3e036b6dd6ceb2d9bf0494f58a3ab8da2c914a643a0385185223f143bdc6ce4a83afee32b3729060
7
+ data.tar.gz: 8bb42785cb2c4a14e2539bdacc159ac6e7a87c53e71ec064268a2e478cdb25a45a4e80fe8d6db4c0a8f92908c14fc849f97561180d4b8184d770c9e9287f3a24
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in grape-cli.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 wswidzinski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
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)
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'grape-cli'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install grape-cli
18
+
19
+ ## Usage
20
+ Create new Grape app in current directory with provided application name
21
+
22
+ $ grape new application_name
23
+
24
+ Start application server
25
+
26
+ $ cd application_name
27
+ $ grape server
28
+ or
29
+
30
+ $ grape s
31
+ Go to http://localhost:9292/
32
+
33
+ Start application console
34
+
35
+ $ grape console
36
+ or
37
+
38
+ $ grape c
39
+
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/elpassion/grape-cli. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
44
+
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
49
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "grape/cli"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/grape ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.dirname(__FILE__) + '/../lib'
4
+
5
+ require "grape/cli"
6
+
7
+ GrapeCli.start(ARGV)
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/grape-cli.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'grape/cli/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "grape-cli"
8
+ spec.version = Grape::Cli::VERSION
9
+ spec.authors = ["wswidzinski", "michalwarda", "koszcz", "ghostbuster91"]
10
+ spec.email = ["swidzinskiw@gmail.com"]
11
+
12
+ spec.summary = %q{ Write a short summary, because Rubygems requires one.}
13
+ spec.description = %q{ Write a longer description or delete this line.}
14
+ spec.homepage = "http://github.com/elpassion/grape-cli"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "bin"
27
+ spec.executables = ["grape"]
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "thor", "~> 0.19"
31
+ spec.add_dependency "bundler", "~> 1.10"
32
+ spec.add_dependency "racksh"
33
+
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "minitest"
36
+ spec.add_development_dependency "pry"
37
+ end
@@ -0,0 +1,21 @@
1
+ require 'grape/command_generator'
2
+
3
+ class ApplicationFactory
4
+ @@instance = ApplicationFactory.new
5
+
6
+ def self.instance
7
+ @@instance
8
+ end
9
+
10
+ def self.instance=(instance)
11
+ @@instance = instance
12
+ end
13
+
14
+ def command_generator
15
+ CommandGenerator.new
16
+ end
17
+
18
+ def verbose_output
19
+ true
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ class ClassNameGenerator
2
+ def initialize(app_name)
3
+ @app_name = app_name
4
+ end
5
+
6
+ def generate
7
+ @app_name.split('_').collect(&:capitalize).join
8
+ end
9
+ end
@@ -0,0 +1,15 @@
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
@@ -0,0 +1,36 @@
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
+
11
+ def self.source_root
12
+ File.dirname(__FILE__)
13
+ end
14
+
15
+ def new(app_name)
16
+ application_template_path = File.join(GrapeCli.source_root, 'template/application')
17
+ destination_path = File.join(options[:work_dir], app_name)
18
+ config = create_config(app_name)
19
+
20
+ directory(application_template_path, destination_path, config)
21
+
22
+ inside destination_path do
23
+ run(ApplicationFactory.instance.command_generator.bundle_install, config)
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def create_config(app_name)
30
+ {
31
+ app_name: app_name,
32
+ verbose: ApplicationFactory.instance.verbose_output,
33
+ class_name: ClassNameGenerator.new(app_name).generate
34
+ }
35
+ end
36
+ end
@@ -0,0 +1,15 @@
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
@@ -0,0 +1,16 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'pg'
4
+
5
+ gem 'grape', '~> 0.13.0'
6
+
7
+ gem 'activerecord', '~> 4.2.1', require: 'active_record'
8
+ gem 'grape-activerecord'
9
+ gem 'grape-swagger', '~> 0.10.2'
10
+ gem 'rack', '~> 1.6.0'
11
+ gem 'racksh'
12
+
13
+ group :development, :test do
14
+ gem 'rake', '~> 10.4.2'
15
+ gem 'pry'
16
+ end
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'grape/activerecord/rake'
4
+
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts 'Run `bundle install` to install missing gems'
10
+ exit e.status_code
11
+ end
12
+
13
+ require 'rake'
14
+
15
+ task :environment do
16
+ ENV['RACK_ENV'] ||= 'development'
17
+ require File.expand_path('../config/environment', __FILE__)
18
+ end
19
+
20
+ task db: :environment
21
+
22
+ task routes: :environment do
23
+ <%= config[:app_name] %>::API.routes.each do |route|
24
+ method = route.route_method.ljust(10)
25
+ path = route.route_path
26
+ puts " #{method} #{path}"
27
+ end
28
+ end
@@ -0,0 +1,10 @@
1
+ module <%= config[:class_name] %>
2
+ class API < Grape::API
3
+ prefix 'api'
4
+ format :json
5
+
6
+ mount <%= config[:class_name] %>::HelloWorld
7
+
8
+ add_swagger_documentation api_version: 'v1'
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module <%= config[:class_name] %>
2
+ class HelloWorld < Grape::API
3
+ get '/hello_world' do
4
+ { message: 'hello world' }
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'app'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'boot'
5
+
6
+ Bundler.require :default, ENV['RACK_ENV']
7
+
8
+ Dir[File.expand_path('../../app/models/*.rb', __FILE__)].each { |file| require file }
9
+ Dir[File.expand_path('../../app/resources/*.rb', __FILE__)].each { |file| require file }
10
+
11
+ require 'api'
@@ -0,0 +1,2 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
@@ -0,0 +1,17 @@
1
+ default: &default
2
+ adapter: postgresql
3
+ encoding: unicode
4
+ username: <%= ENV['DATABASE_USERNAME'] %>
5
+ password: <%= ENV['DATABASE_PASSWORD'] %>
6
+ pool: 5
7
+
8
+ development:
9
+ <<: *default
10
+ database: <%= config[:app_name] %>_api_development
11
+
12
+ test:
13
+ <<: *default
14
+ database: <%= config[:app_name] %>_api_test
15
+
16
+ production:
17
+ url: <%= ENV['DATABASE_URL'] %>
@@ -0,0 +1,3 @@
1
+ ENV['RACK_ENV'] ||= 'test'
2
+
3
+ require File.expand_path('../application', __FILE__)
@@ -0,0 +1,5 @@
1
+ require File.expand_path('../config/environment', __FILE__)
2
+
3
+ use ActiveRecord::ConnectionAdapters::ConnectionManagement
4
+
5
+ run <%= config[:class_name] %>::API.new
@@ -0,0 +1,5 @@
1
+ module Grape
2
+ module Cli
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
data/lib/grape/cli.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'thor'
2
+ require 'grape/cli/new'
3
+ require 'grape/cli/server'
4
+ require 'grape/cli/console'
5
+ require 'grape/cli/version'
6
+
7
+ module Grape
8
+ end
@@ -0,0 +1,13 @@
1
+ class CommandGenerator
2
+ def bundle_install
3
+ 'bundle install'
4
+ end
5
+
6
+ def run_server
7
+ 'rackup'
8
+ end
9
+
10
+ def run_console
11
+ 'racksh'
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grape-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - wswidzinski
8
+ - michalwarda
9
+ - koszcz
10
+ - ghostbuster91
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2015-09-25 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: thor
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '0.19'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '0.19'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - "~>"
35
+ - !ruby/object:Gem::Version
36
+ version: '1.10'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1.10'
44
+ - !ruby/object:Gem::Dependency
45
+ name: racksh
46
+ requirement: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ - !ruby/object:Gem::Dependency
59
+ name: rake
60
+ requirement: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - "~>"
63
+ - !ruby/object:Gem::Version
64
+ version: '10.0'
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '10.0'
72
+ - !ruby/object:Gem::Dependency
73
+ name: minitest
74
+ requirement: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ - !ruby/object:Gem::Dependency
87
+ name: pry
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ description: " Write a longer description or delete this line."
101
+ email:
102
+ - swidzinskiw@gmail.com
103
+ executables:
104
+ - grape
105
+ extensions: []
106
+ extra_rdoc_files: []
107
+ files:
108
+ - ".gitignore"
109
+ - ".travis.yml"
110
+ - CODE_OF_CONDUCT.md
111
+ - Gemfile
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - bin/console
116
+ - bin/grape
117
+ - bin/setup
118
+ - grape-cli.gemspec
119
+ - lib/grape/application_factory.rb
120
+ - lib/grape/class_name_generator.rb
121
+ - lib/grape/cli.rb
122
+ - lib/grape/cli/console.rb
123
+ - lib/grape/cli/new.rb
124
+ - lib/grape/cli/server.rb
125
+ - lib/grape/cli/template/application/Gemfile
126
+ - lib/grape/cli/template/application/Rakefile.tt
127
+ - lib/grape/cli/template/application/app/api.rb.tt
128
+ - lib/grape/cli/template/application/app/resources/hello_world.rb.tt
129
+ - lib/grape/cli/template/application/config.ru.tt
130
+ - lib/grape/cli/template/application/config/application.rb
131
+ - lib/grape/cli/template/application/config/boot.rb
132
+ - lib/grape/cli/template/application/config/database.yml.tt
133
+ - lib/grape/cli/template/application/config/environment.rb
134
+ - lib/grape/cli/version.rb
135
+ - lib/grape/command_generator.rb
136
+ homepage: http://github.com/elpassion/grape-cli
137
+ licenses:
138
+ - MIT
139
+ metadata:
140
+ allowed_push_host: https://rubygems.org
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.4.6
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Write a short summary, because Rubygems requires one.
161
+ test_files: []