grape_press 0.0.1

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.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +44 -0
  8. data/Rakefile +7 -0
  9. data/bin/press +5 -0
  10. data/grape_press.gemspec +27 -0
  11. data/lib/grape_press/cli.rb +30 -0
  12. data/lib/grape_press/configuration.rb +24 -0
  13. data/lib/grape_press/files.rb +68 -0
  14. data/lib/grape_press/templates/Gemfile.erb +31 -0
  15. data/lib/grape_press/templates/Guardfile.erb +6 -0
  16. data/lib/grape_press/templates/Rakefile.erb +54 -0
  17. data/lib/grape_press/templates/app/api/api.rb.erb +8 -0
  18. data/lib/grape_press/templates/app/api/v1/api.rb.erb +16 -0
  19. data/lib/grape_press/templates/app/application.rb.erb +37 -0
  20. data/lib/grape_press/templates/bin/console.erb +8 -0
  21. data/lib/grape_press/templates/config/database_mysql.yml.erb +13 -0
  22. data/lib/grape_press/templates/config/database_pg.yml.erb +11 -0
  23. data/lib/grape_press/templates/config/database_sqlite.yml.erb +11 -0
  24. data/lib/grape_press/templates/config/environment.rb.erb +13 -0
  25. data/lib/grape_press/templates/config/initializers/active_record.rb.erb +5 -0
  26. data/lib/grape_press/templates/config/initializers/mongoid.rb.erb +1 -0
  27. data/lib/grape_press/templates/config/locales/en.yml.erb +8 -0
  28. data/lib/grape_press/templates/config/mongoid.yml.erb +71 -0
  29. data/lib/grape_press/templates/config.ru.erb +26 -0
  30. data/lib/grape_press/templates/dot_rspec.erb +2 -0
  31. data/lib/grape_press/templates/readme.md.erb +3 -0
  32. data/lib/grape_press/templates/spec/spec_helper.rb.erb +28 -0
  33. data/lib/grape_press/templates/spec/spec_helper_ar.rb.erb +49 -0
  34. data/lib/grape_press/templates/spec/spec_helper_mongoid.rb.erb +46 -0
  35. data/lib/grape_press/tree.rb +50 -0
  36. data/lib/grape_press/version.rb +3 -0
  37. data/lib/grape_press.rb +5 -0
  38. data/spec/grape_press_spec.rb +11 -0
  39. data/spec/spec_helper.rb +2 -0
  40. metadata +155 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0bbd671aa64207d8186f1c236f87295746d8b210
4
+ data.tar.gz: 9790924db1e4926ca66b2c7d628f10d5e74be355
5
+ SHA512:
6
+ metadata.gz: c3e1d15a6b3288c57a54da8c8bb9036562cdf890d8a14d68362c5906134f41a189f738bf2a08ba447678c70b5d8180cf3bcf14b1df7b1a1ac338f69e28c7233a
7
+ data.tar.gz: 015a92b7aea3bff03afd868a795a57975d831e060b006a4940385fa6c28cd86a0361039cbd7935bb990088b4e98e752ad8a619721db9a80d45b63d219c5126ab
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in grape_press.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 alexpeachey
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,44 @@
1
+ # GrapePress
2
+
3
+ Create an application starter for Grape API projects.
4
+
5
+ ## Installation
6
+
7
+ Install the gem:
8
+
9
+ $ gem install grape_press
10
+
11
+ ## Usage
12
+
13
+ `press new SlickApp`
14
+
15
+ You will be asked a few configuration questions, just answer as it suites your application.
16
+
17
+ You will then have a new application in `slick_app`.
18
+
19
+ Type `rackup` inside the `slick_app` directory to fire up your server.
20
+
21
+ ## Useful features
22
+
23
+ ### Rake commands
24
+
25
+ `rake routes`
26
+ `rake spec`
27
+
28
+ If you include ActiveRecord
29
+ `rake db:create`
30
+ `rake db:drop`
31
+ `rake db:migrate`
32
+ `rake db:rollback`
33
+
34
+ ### A console
35
+
36
+ `bin/console`
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it ( https://github.com/Originate/grape_press/fork )
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
data/bin/press ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'grape_press'
4
+
5
+ GrapePress::Cli.start(ARGV)
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'grape_press/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'grape_press'
8
+ spec.version = GrapePress::VERSION
9
+ spec.authors = ['alexpeachey']
10
+ spec.email = ['alex.peachey@gmail.com']
11
+ spec.summary = %q{Generator for Grape API projects.}
12
+ spec.description = %q{Generator for Grape API projects.}
13
+ spec.homepage = 'https://github.com/Originate/grape_press'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_dependency 'thor', '~> 0.19'
22
+ spec.add_dependency 'activesupport', '~> 4.1'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.7'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ end
@@ -0,0 +1,30 @@
1
+ require 'thor'
2
+ require 'active_support/inflector'
3
+ require 'grape_press/configuration'
4
+ require 'grape_press/tree'
5
+ require 'grape_press/files'
6
+
7
+ module GrapePress
8
+ class Cli < Thor
9
+ include Thor::Actions
10
+ include Configuration
11
+ include Tree
12
+ include Files
13
+
14
+ def self.source_root
15
+ File.dirname(__FILE__)
16
+ end
17
+
18
+ desc 'new APP', 'Generate a new Grape API Application'
19
+ def new(name)
20
+ collect(name)
21
+ generate_tree
22
+ generate_files
23
+ end
24
+
25
+ desc 'destroy APP', 'Destroy Application'
26
+ def destroy(name)
27
+ remove_dir name.underscore
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,24 @@
1
+ module GrapePress
2
+ module Configuration
3
+ attr_reader :app_name, :app_class, :active_record, :database, :mongoid
4
+
5
+ private
6
+
7
+ def collect(name)
8
+ @app_name = name.underscore
9
+ @app_class = name.camelize
10
+ @active_record = yes? 'Use ActiveRecord?'
11
+ @database = if active_record
12
+ ask 'Database?', limited_to: ['pg', 'mysql', 'sqlite', 'other']
13
+ else
14
+ :none
15
+ end
16
+ @mongoid = if active_record
17
+ false
18
+ else
19
+ yes? 'Use Mongoid?'
20
+ end
21
+ self
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,68 @@
1
+ module GrapePress
2
+ module Files
3
+ private
4
+
5
+ def generate_files
6
+ generate_core_files
7
+ generate_app_files
8
+ generate_bin_files
9
+ generate_config_files
10
+ generate_spec_files
11
+ generate_database_files
12
+ generate_mongoid_files
13
+ end
14
+
15
+ def generate_core_files
16
+ template File.join('templates', 'readme.md.erb'), File.join(app_name, 'README.md')
17
+ template File.join('templates', 'config.ru.erb'), File.join(app_name, 'config.ru')
18
+ template File.join('templates', 'Gemfile.erb'), File.join(app_name, 'Gemfile')
19
+ template File.join('templates', 'Guardfile.erb'), File.join(app_name, 'Guardfile')
20
+ template File.join('templates', 'Rakefile.erb'), File.join(app_name, 'Rakefile')
21
+ template File.join('templates', 'dot_rspec.erb'), File.join(app_name, '.rspec')
22
+ end
23
+
24
+ def generate_app_files
25
+ template File.join('templates', 'app', 'application.rb.erb'), File.join(app_name, 'app', 'application.rb')
26
+ template File.join('templates', 'app', 'api', 'api.rb.erb'), File.join(app_name, 'app', 'api', 'api.rb')
27
+ template File.join('templates', 'app', 'api', 'v1', 'api.rb.erb'), File.join(app_name, 'app', 'api', 'v1', 'api.rb')
28
+ end
29
+
30
+ def generate_bin_files
31
+ template File.join('templates', 'bin', 'console.erb'), File.join(app_name, 'bin', 'console')
32
+ chmod File.join(app_name, 'bin', 'console'), 0755
33
+ end
34
+
35
+ def generate_config_files
36
+ template File.join('templates', 'config', 'environment.rb.erb'), File.join(app_name, 'config', 'environment.rb')
37
+ template File.join('templates', 'config', 'locales', 'en.yml.erb'), File.join(app_name, 'config', 'locales', 'en.yml')
38
+ end
39
+
40
+ def generate_spec_files
41
+ if active_record
42
+ template File.join('templates', 'spec', 'spec_helper_ar.rb.erb'), File.join(app_name, 'spec', 'spec_helper.rb')
43
+ elsif mongoid
44
+ template File.join('templates', 'spec', 'spec_helper_mongoid.rb.erb'), File.join(app_name, 'spec', 'spec_helper.rb')
45
+ else
46
+ template File.join('templates', 'spec', 'spec_helper.rb.erb'), File.join(app_name, 'spec', 'spec_helper.rb')
47
+ end
48
+ end
49
+
50
+ def generate_database_files
51
+ return unless active_record
52
+ template File.join('templates', 'config', 'initializers', 'active_record.rb.erb'), File.join(app_name, 'config', 'initializers', 'active_record.rb')
53
+ if database == 'pg'
54
+ template File.join('templates', 'config', 'database_pg.yml.erb'), File.join(app_name, 'config', 'database.yml')
55
+ elsif database == 'mysql'
56
+ template File.join('templates', 'config', 'database_mysql.yml.erb'), File.join(app_name, 'config', 'database.yml')
57
+ elsif database == 'sqlite'
58
+ template File.join('templates', 'config', 'database_sqlite.yml.erb'), File.join(app_name, 'config', 'database.yml')
59
+ end
60
+ end
61
+
62
+ def generate_mongoid_files
63
+ return unless mongoid
64
+ template File.join('templates', 'config', 'initializers', 'mongoid.rb.erb'), File.join(app_name, 'config', 'initializers', 'mongoid.rb')
65
+ template File.join('templates', 'config', 'mongoid.yml.erb'), File.join(app_name, 'config', 'mongoid.yml')
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,31 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'grape', '~> 0.9.0'
4
+ gem 'grape-entity'
5
+ gem 'grape-swagger'
6
+ gem 'rack-cors'
7
+ gem 'rake'
8
+ <% if active_record %>gem 'activerecord', '~> 4.1'<% end %>
9
+ <% if database == 'pg' %>gem 'pg'<% end %>
10
+ <% if database == 'mysql' %>gem 'mysql2'<% end %>
11
+ <% if database == 'sqlite' %>gem 'sqlite3'<% end %>
12
+ <% if mongoid %>gem 'mongoid'<% end %>
13
+
14
+ group :development, :test do
15
+ gem 'dotenv'
16
+ gem 'rspec'
17
+ gem 'rack-test'
18
+ gem 'simplecov'
19
+ gem 'simplecov-html'
20
+ gem 'guard'
21
+ gem 'guard-rspec'
22
+ gem 'rb-inotify', require: false
23
+ gem 'rb-fsevent', require: false
24
+ gem 'rb-fchange', require: false
25
+ gem 'rubocop', require: false
26
+ <% if active_record %>
27
+ gem 'factory_girl'
28
+ gem 'database_cleaner'
29
+ <% end %>
30
+ end
31
+
@@ -0,0 +1,6 @@
1
+ guard :rspec, notification: true, cmd: 'rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^spec/spec_helper\.rb$})
4
+ watch(%r{^spec/support/(.+)\.rb$})
5
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
6
+ end
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env rake
2
+ $LOAD_PATH.unshift File.expand_path('../app', __FILE__)
3
+ require 'application'
4
+
5
+
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ task :default => :spec
9
+
10
+ desc 'API Routes'
11
+ task :routes do
12
+ API.routes.each do |api|
13
+ method = api.route_method.ljust(10)
14
+ path = api.route_path
15
+ puts " #{method} #{path}"
16
+ end
17
+ end
18
+
19
+ <% if active_record %>
20
+ MIGRATIONS_DIR = File.join(APP_ROOT, 'db', 'migrations')
21
+
22
+ namespace :db do
23
+ desc 'Create the database in the current GRAPE_ENV'
24
+ task :create do
25
+ config = YAML.load(File.read(File.join(APP_ROOT, 'config', 'database.yml')))[GRAPE_ENV.to_s]
26
+ ActiveRecord::Base.establish_connection config.merge(database: nil)
27
+ ActiveRecord::Base.connection.create_database config['database']
28
+ ActiveRecord::Base.establish_connection config
29
+ end
30
+
31
+ desc 'Drops the database in the current GRAPE_ENV'
32
+ task :drop do
33
+ config = YAML.load(File.read(File.join(APP_ROOT, 'config', 'database.yml')))[GRAPE_ENV.to_s]
34
+ ActiveRecord::Base.connection.drop_database config['database']
35
+ end
36
+
37
+ desc 'Migrate the database (options: VERSION=x).'
38
+ task :migrate do
39
+ ActiveRecord::Migration.verbose = true
40
+ ActiveRecord::Migrator.migrate MIGRATIONS_DIR, ENV['VERSION'] ? ENV['VERSION'].to_i : nil
41
+ end
42
+
43
+ desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n).'
44
+ task :rollback do
45
+ step = ENV['STEP'] ? ENV['STEP'].to_i : 1
46
+ ActiveRecord::Migrator.rollback MIGRATIONS_DIR, step
47
+ end
48
+
49
+ desc "Retrieves the current schema version number"
50
+ task :version do
51
+ puts "Current version: #{ActiveRecord::Migrator.current_version}"
52
+ end
53
+ end
54
+ <% end %>
@@ -0,0 +1,8 @@
1
+ require 'grape-swagger'
2
+
3
+ class API < Grape::API
4
+ format :json
5
+ default_format :json
6
+ mount V1::API
7
+ add_swagger_documentation
8
+ end
@@ -0,0 +1,16 @@
1
+ module V1
2
+ class API < Grape::API
3
+ version 'v1', using: :path
4
+
5
+ desc 'Welcome to your Grape API'
6
+ get do
7
+ 'Hello from Grape!'
8
+ end
9
+
10
+ # Mount your Resources here
11
+
12
+ # mount ResourceOne
13
+ # mount ResourceTwo
14
+
15
+ end
16
+ end
@@ -0,0 +1,37 @@
1
+ APP_ROOT = File.expand_path('../..', __FILE__)
2
+ GRAPE_ROOT = APP_ROOT
3
+
4
+ # Autoloading & Path Management
5
+ $LOAD_PATH.unshift APP_ROOT unless $LOAD_PATH.include?(APP_ROOT)
6
+ app_path = File.join(APP_ROOT, 'app')
7
+ $LOAD_PATH.unshift app unless $LOAD_PATH.include?(app_path)
8
+
9
+ # Load the Environment
10
+ require 'config/environment'
11
+
12
+ # Autoload the app
13
+ require 'active_support/all'
14
+ Dir[File.join(APP_ROOT, 'app', '*')].select { |d| File.directory? d }.each do |directory|
15
+ ActiveSupport::Dependencies.autoload_paths << directory
16
+ end
17
+
18
+ # Load any initializers
19
+ Dir[File.join(APP_ROOT, 'config', 'initializers', '**', '*.rb')].each { |f| require f }
20
+
21
+ # Eager load the app outside of development/test
22
+ unless [:development, :test].include? GRAPE_ENV
23
+ Dir[File.join(APP_ROOT, 'app', '**', '*.rb')].each do |file|
24
+ file.gsub(File.join(APP_ROOT, 'app', '*'), '')[0..-4].
25
+ split(File::SEPARATOR).
26
+ map(&:camelcase).
27
+ map { |f| f == 'Api' ? f.upcase : f }.
28
+ join('::').
29
+ constantize
30
+ end
31
+ end
32
+
33
+ # Configure I18n
34
+ I18n.enforce_available_locales = true
35
+ I18n.available_locales = :en
36
+ I18n.default_locale = :en
37
+ I18n.load_path += Dir[File.join(APP_ROOT, 'config', 'locales', '*.yml'), File.join(APP_ROOT, 'config', 'locals', '*.rb')]
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../app', __FILE__)
4
+ require 'irb'
5
+ require 'irb/completion'
6
+ require 'application'
7
+ ARGV.clear
8
+ IRB.start
@@ -0,0 +1,13 @@
1
+ development:
2
+ adapter: mysql2
3
+ encoding: utf8
4
+ database: <%= app_name %>_development
5
+ host: 127.0.0.1
6
+ port: 3306
7
+
8
+ test:
9
+ adapter: mysql2
10
+ encoding: utf8
11
+ database: <%= app_name %>_test
12
+ host: 127.0.0.1
13
+ port: 3306
@@ -0,0 +1,11 @@
1
+ development:
2
+ adapter: postgresql
3
+ encoding: unicode
4
+ database: <%= app_name %>_development
5
+ pool: 5
6
+
7
+ test:
8
+ adapter: postgresql
9
+ encoding: unicode
10
+ database: <%= app_name %>_test
11
+ pool: 5
@@ -0,0 +1,11 @@
1
+ development:
2
+ adapter: sqlite3
3
+ database: db/development.sqlite3
4
+ pool: 5
5
+ timeout: 5000
6
+
7
+ test:
8
+ adapter: sqlite3
9
+ database: db/test.sqlite3
10
+ pool: 5
11
+ timeout: 5000
@@ -0,0 +1,13 @@
1
+ # Environment - For env specific code only
2
+
3
+ # Environment Constants
4
+ GRAPE_ENV ||= (ENV['GRAPE_ENV'] || ENV['RACK_ENV'] || :development).to_sym
5
+ RACK_ENV = GRAPE_ENV
6
+
7
+ # Load Environment Specific gems
8
+ require 'bundler'
9
+ Bundler.require :default, GRAPE_ENV
10
+
11
+ # Load Environment Specific Settings
12
+ specific_environment = File.join(APP_ROOT, 'config', 'environments', "#{GRAPE_ENV}.rb")
13
+ require specific_environment if File.exist? specific_environment
@@ -0,0 +1,5 @@
1
+ require 'active_record'
2
+
3
+ ActiveRecord::Base.establish_connection(
4
+ YAML.load(File.read(File.join(APP_ROOT, 'config', 'database.yml')))[GRAPE_ENV.to_s]
5
+ )
@@ -0,0 +1 @@
1
+ Mongoid.load!(File.join(APP_ROOT, 'config/mongoid.yml'), GRAPE_ENV)
@@ -0,0 +1,8 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To learn more, please read the Rails Internationalization guide
6
+ # available at http://guides.rubyonrails.org/i18n.html.
7
+
8
+ en:
@@ -0,0 +1,71 @@
1
+ development:
2
+ # Configure available database sessions. (required)
3
+ sessions:
4
+ # Defines the default session. (required)
5
+ default:
6
+ # Defines the name of the default database that Mongoid can connect to.
7
+ # (required).
8
+ database: <%= app_name %>_development
9
+ # Provides the hosts the default session can connect to. Must be an array
10
+ # of host:port pairs. (required)
11
+ hosts:
12
+ - localhost:27017
13
+ options:
14
+ # Change the default write concern. (default = { w: 1 })
15
+ # write:
16
+ # w: 1
17
+
18
+ # Change the default consistency model to primary, secondary.
19
+ # 'secondary' will send reads to secondaries, 'primary' sends everything
20
+ # to master. (default: primary)
21
+ # read: secondary_preferred
22
+
23
+ # How many times Moped should attempt to retry an operation after
24
+ # failure. (default: 30)
25
+ # max_retries: 30
26
+
27
+ # The time in seconds that Moped should wait before retrying an
28
+ # operation on failure. (default: 1)
29
+ # retry_interval: 1
30
+ # Configure Mongoid specific options. (optional)
31
+ options:
32
+ # Includes the root model name in json serialization. (default: false)
33
+ # include_root_in_json: false
34
+
35
+ # Include the _type field in serializaion. (default: false)
36
+ # include_type_for_serialization: false
37
+
38
+ # Preload all models in development, needed when models use
39
+ # inheritance. (default: false)
40
+ # preload_models: false
41
+
42
+ # Protect id and type from mass assignment. (default: true)
43
+ # protect_sensitive_fields: true
44
+
45
+ # Raise an error when performing a #find and the document is not found.
46
+ # (default: true)
47
+ raise_not_found_error: false
48
+
49
+ # Raise an error when defining a scope with the same name as an
50
+ # existing method. (default: false)
51
+ # scope_overwrite_exception: false
52
+
53
+ # Use Active Support's time zone in conversions. (default: true)
54
+ # use_activesupport_time_zone: true
55
+
56
+ # Ensure all times are UTC in the app side. (default: false)
57
+ # use_utc: false
58
+ test:
59
+ sessions:
60
+ default:
61
+ database: <%= app_name %>_test
62
+ hosts:
63
+ - localhost:27017
64
+ options:
65
+ read: primary
66
+ # In the test environment we lower the retries and retry interval to
67
+ # low amounts for fast failures.
68
+ max_retries: 1
69
+ retry_interval: 0
70
+ options:
71
+ raise_not_found_error: false
@@ -0,0 +1,26 @@
1
+ # Rack config file
2
+ # --------------------------------------------------
3
+ #
4
+ # Only Rack specific code in here
5
+ #
6
+ # Place all application specific code in app/application.rb
7
+ # -------------------------------------------------
8
+
9
+
10
+ # Handle CORS Settings
11
+ # --------------------
12
+ require 'rack/cors'
13
+
14
+ use Rack::Cors do
15
+ allow do
16
+ origins '*'
17
+ resource '*', headers: :any, methods: [:get, :post, :put, :delete, :patch, :options]
18
+ end
19
+ end
20
+
21
+ # Run the API
22
+ # ---------------------
23
+ app = File.expand_path('../app', __FILE__)
24
+ $LOAD_PATH.unshift(app) unless $LOAD_PATH.include?(app)
25
+ require 'application'
26
+ run API::API
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ # README
2
+
3
+ Put interesting info here on how to configure the application.
@@ -0,0 +1,28 @@
1
+ ENV['RACK_ENV'] ||= 'test'
2
+ ENV['GRAPE_ENV'] ||= ENV['RACK_ENV']
3
+
4
+ if ENV['COVERAGE']
5
+ require 'simplecov'
6
+ SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
7
+ SimpleCov.start
8
+ end
9
+
10
+ app_path = File.expand_path('../../app', __FILE__)
11
+ $LOAD_PATH.unshift(app_path) unless $LOAD_PATH.include?(app_path)
12
+ require 'application'
13
+
14
+ require 'rack/test'
15
+
16
+ Dir[File.join(APP_ROOT, 'spec', 'support', '**', '*.rb')].each { |f| require f }
17
+
18
+ RSpec.configure do |config|
19
+ config.mock_with :rspec
20
+ config.run_all_when_everything_filtered = true
21
+ config.filter_run :focus
22
+ config.order = 'random'
23
+ config.include Rack::Test::Methods
24
+ end
25
+
26
+ def app
27
+ API
28
+ end
@@ -0,0 +1,49 @@
1
+ ENV['RACK_ENV'] ||= 'test'
2
+ ENV['GRAPE_ENV'] ||= ENV['RACK_ENV']
3
+
4
+ if ENV['COVERAGE']
5
+ require 'simplecov'
6
+ SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
7
+ SimpleCov.start
8
+ end
9
+
10
+ app_path = File.expand_path('../../app', __FILE__)
11
+ $LOAD_PATH.unshift(app_path) unless $LOAD_PATH.include?(app_path)
12
+ require 'application'
13
+
14
+ require 'rack/test'
15
+ require 'factory_girl'
16
+ require 'database_cleaner'
17
+ require 'rspec/rails/extensions/active_record/proxy'
18
+
19
+ Dir[File.join(APP_ROOT, 'spec', 'support', '**', '*.rb')].each { |f| require f }
20
+ Dir[File.join(APP_ROOT, 'spec', 'factories', '**', '*.rb')].each { |f| require f }
21
+
22
+ ActiveRecord::Migration.check_pending!
23
+
24
+ DatabaseCleaner.strategy = :truncation
25
+
26
+ RSpec.configure do |config|
27
+ config.mock_with :rspec
28
+ config.run_all_when_everything_filtered = true
29
+ config.filter_run :focus
30
+ config.order = 'random'
31
+ config.include Rack::Test::Methods
32
+ config.include FactoryGirl::Syntax::Methods
33
+
34
+ config.before(:suite) do
35
+ DatabaseCleaner.clean
36
+ end
37
+
38
+ config.before(:each) do
39
+ DatabaseCleaner.start
40
+ end
41
+
42
+ config.after(:each) do
43
+ DatabaseCleaner.clean
44
+ end
45
+ end
46
+
47
+ def app
48
+ API
49
+ end
@@ -0,0 +1,46 @@
1
+ ENV['RACK_ENV'] ||= 'test'
2
+ ENV['GRAPE_ENV'] ||= ENV['RACK_ENV']
3
+
4
+ if ENV['COVERAGE']
5
+ require 'simplecov'
6
+ SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
7
+ SimpleCov.start
8
+ end
9
+
10
+ app_path = File.expand_path('../../app', __FILE__)
11
+ $LOAD_PATH.unshift(app_path) unless $LOAD_PATH.include?(app_path)
12
+ require 'application'
13
+
14
+ require 'rack/test'
15
+ require 'factory_girl'
16
+ require 'database_cleaner'
17
+
18
+ Dir[File.join(APP_ROOT, 'spec', 'support', '**', '*.rb')].each { |f| require f }
19
+ Dir[File.join(APP_ROOT, 'spec', 'factories', '**', '*.rb')].each { |f| require f }
20
+
21
+ DatabaseCleaner.strategy = :truncation
22
+
23
+ RSpec.configure do |config|
24
+ config.mock_with :rspec
25
+ config.run_all_when_everything_filtered = true
26
+ config.filter_run :focus
27
+ config.order = 'random'
28
+ config.include Rack::Test::Methods
29
+ config.include FactoryGirl::Syntax::Methods
30
+
31
+ config.before(:suite) do
32
+ DatabaseCleaner.clean
33
+ end
34
+
35
+ config.before(:each) do
36
+ DatabaseCleaner.start
37
+ end
38
+
39
+ config.after(:each) do
40
+ DatabaseCleaner.clean
41
+ end
42
+ end
43
+
44
+ def app
45
+ API
46
+ end
@@ -0,0 +1,50 @@
1
+ module GrapePress
2
+ module Tree
3
+ private
4
+
5
+ def generate_tree
6
+ generate_app_tree
7
+ generate_bin_tree
8
+ generate_config_tree
9
+ generate_spec_tree
10
+ generate_database_tree
11
+ generate_models_tree
12
+ end
13
+
14
+ def generate_app_tree
15
+ empty_directory app_name
16
+ empty_directory File.join(app_name, 'app')
17
+ empty_directory File.join(app_name, 'app', 'api')
18
+ empty_directory File.join(app_name, 'app', 'api', 'v1')
19
+ empty_directory File.join(app_name, 'app', 'api', 'v1', 'entities')
20
+ end
21
+
22
+ def generate_bin_tree
23
+ empty_directory File.join(app_name, 'bin')
24
+ end
25
+
26
+ def generate_config_tree
27
+ empty_directory File.join(app_name, 'config')
28
+ empty_directory File.join(app_name, 'config', 'environments')
29
+ empty_directory File.join(app_name, 'config', 'initializers')
30
+ empty_directory File.join(app_name, 'config', 'locales')
31
+ end
32
+
33
+ def generate_spec_tree
34
+ empty_directory File.join(app_name, 'spec')
35
+ empty_directory File.join(app_name, 'spec', 'support')
36
+ end
37
+
38
+ def generate_database_tree
39
+ return unless active_record
40
+ empty_directory File.join(app_name, 'db')
41
+ empty_directory File.join(app_name, 'db', 'migrations')
42
+ end
43
+
44
+ def generate_models_tree
45
+ return unless active_record || mongoid
46
+ empty_directory File.join(app_name, 'app', 'models')
47
+ empty_directory File.join(app_name, 'spec', 'models')
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,3 @@
1
+ module GrapePress
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'grape_press/version'
2
+ require 'grape_press/cli'
3
+
4
+ module GrapePress
5
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe GrapePress do
4
+ it 'has a version number' do
5
+ expect(GrapePress::VERSION).not_to be nil
6
+ end
7
+
8
+ it 'does something useful' do
9
+ expect(false).to eq(true)
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'grape_press'
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grape_press
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - alexpeachey
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.19'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Generator for Grape API projects.
84
+ email:
85
+ - alex.peachey@gmail.com
86
+ executables:
87
+ - press
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/press
99
+ - grape_press.gemspec
100
+ - lib/grape_press.rb
101
+ - lib/grape_press/cli.rb
102
+ - lib/grape_press/configuration.rb
103
+ - lib/grape_press/files.rb
104
+ - lib/grape_press/templates/Gemfile.erb
105
+ - lib/grape_press/templates/Guardfile.erb
106
+ - lib/grape_press/templates/Rakefile.erb
107
+ - lib/grape_press/templates/app/api/api.rb.erb
108
+ - lib/grape_press/templates/app/api/v1/api.rb.erb
109
+ - lib/grape_press/templates/app/application.rb.erb
110
+ - lib/grape_press/templates/bin/console.erb
111
+ - lib/grape_press/templates/config.ru.erb
112
+ - lib/grape_press/templates/config/database_mysql.yml.erb
113
+ - lib/grape_press/templates/config/database_pg.yml.erb
114
+ - lib/grape_press/templates/config/database_sqlite.yml.erb
115
+ - lib/grape_press/templates/config/environment.rb.erb
116
+ - lib/grape_press/templates/config/initializers/active_record.rb.erb
117
+ - lib/grape_press/templates/config/initializers/mongoid.rb.erb
118
+ - lib/grape_press/templates/config/locales/en.yml.erb
119
+ - lib/grape_press/templates/config/mongoid.yml.erb
120
+ - lib/grape_press/templates/dot_rspec.erb
121
+ - lib/grape_press/templates/readme.md.erb
122
+ - lib/grape_press/templates/spec/spec_helper.rb.erb
123
+ - lib/grape_press/templates/spec/spec_helper_ar.rb.erb
124
+ - lib/grape_press/templates/spec/spec_helper_mongoid.rb.erb
125
+ - lib/grape_press/tree.rb
126
+ - lib/grape_press/version.rb
127
+ - spec/grape_press_spec.rb
128
+ - spec/spec_helper.rb
129
+ homepage: https://github.com/Originate/grape_press
130
+ licenses:
131
+ - MIT
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.2.2
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: Generator for Grape API projects.
153
+ test_files:
154
+ - spec/grape_press_spec.rb
155
+ - spec/spec_helper.rb