grape-starter 0.8.7 → 1.0.0

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
  SHA256:
3
- metadata.gz: 4dfa9a76e1ab4ba6bce2e9aa5a845d3badb99b90446fbb9aa2714dae5449901d
4
- data.tar.gz: 73814dbd39bc08faba9b3ba4a21ac90aeef3b099e9294359c6ce805fe438b610
3
+ metadata.gz: e073b45cc89020c1371c9d38206265d3bdf4087316dfc12988394663eb10f935
4
+ data.tar.gz: 1446043c5698906fac0f89342f73a27dfbc7e252d2ac1a121be61ae0d25599a2
5
5
  SHA512:
6
- metadata.gz: 13a86d442ec14d2bbe639b2847b99d2b0a064e23dbb6992c7a76715dbfa405bac1ea6253e1b548ea3e40c6ce6189bc075a58af469e3540b295f777465b63dd1e
7
- data.tar.gz: 8030e723fec17634d51d8c52ad917cee13936224f8855822ce0d264226c78d19083bf002e240374ad4cedb6a7c1e67ca674ceb42e6c9c6cd773f17b996e0c529
6
+ metadata.gz: c42f38b0c69e3661b655802276ba280b5c104e289d86ab100fbba572692dd11fe9d558f5cec35927b9fc8617ca8c876fdc26abaaad609aaed86521bb7941fa37
7
+ data.tar.gz: d894032459bf6daf5ea08386313944251f77cfca81d18b7b9fbd4347db0f7f750294fa5e6d6fcaceccd22d3f273753c9c483be5a9290a10826b5ad237a6a74e1
data/.gitignore CHANGED
@@ -8,7 +8,6 @@ Gemfile.lock
8
8
  docker-compose.yml
9
9
  Dockerfile
10
10
  tmp/
11
- .rspec
12
11
  pkg/
13
12
  template/Gemfile.lock
14
13
  grape-starter.md
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -7,11 +7,16 @@ before_install:
7
7
  - gem install bundler
8
8
 
9
9
  rvm:
10
- - 2.5.0
11
- - 2.4.3
12
- - ruby-head
10
+ - 2.5.1
11
+ - 2.4.4
13
12
 
14
13
  matrix:
15
14
  fast_finish: true
15
+
16
+ include:
17
+ - rvm: ruby-head
18
+ - rvm: 2.3.7
19
+
16
20
  allow_failures:
17
21
  - rvm: ruby-head
22
+ - rvm: 2.3.7
@@ -2,6 +2,12 @@
2
2
 
3
3
  - contributions
4
4
 
5
+ ### 1.0.0
6
+
7
+ - [67a5f](https://github.com/LeFnord/grape-starter/commit/b1f32801844ed9a98bc4d5f7c938451ef7667a5f) - supports creating a migration file
8
+ - [de26b](https://github.com/LeFnord/grape-starter/commit/22ad2170176b9602cff2239a7d0469c823cde26b) - ci adoptions
9
+ - [7ad69](https://github.com/LeFnord/grape-starter/commit/925fa5fb161c8cc26c96834e185d8299a207ad69) - spec improvements
10
+
5
11
  ### 0.8.7
6
12
 
7
13
  - [c7cb2](https://github.com/LeFnord/grape-starter/commit/4be5bd9b7c06611e096d6eaa23d7168136bc7cb2) - updates dependencies; makes rubocop happy
data/Gemfile CHANGED
@@ -5,11 +5,12 @@ source 'http://rubygems.org'
5
5
  gemspec
6
6
 
7
7
  group :development, :test do
8
- gem 'grape', '>= 0.19.1'
8
+ gem 'grape', '~> 1.0'
9
9
  gem 'pry', platforms: [:mri]
10
10
  gem 'pry-byebug', platforms: [:mri]
11
11
  gem 'rack-cors', require: false
12
12
  gem 'rack-test', require: false
13
- gem 'rake', '>= 10.0'
14
- gem 'rspec', '>= 3.0'
13
+ gem 'rake', '~> 12.0'
14
+ gem 'rspec', '~> 3.7'
15
+ gem 'rspec-command'
15
16
  end
data/README.md CHANGED
@@ -97,8 +97,9 @@ This adds endpoint and lib file and belonging specs, and a mount entry in base.r
97
97
 
98
98
  Using it with following options:
99
99
  ```
100
- -e, --entity # a grape entity file will also be created
101
- -o, --orm # sets the parent class of libe file (e.g: `Foo < Sequel::Model` for Sequel)
100
+ -e, --entity # a grape entity file will also be created
101
+ -m, --migration # adds also a migration file, if an ORM is used
102
+ -o, --orm # sets the parent class of libe file (e.g: `Foo < Sequel::Model` for Sequel)
102
103
  ```
103
104
  to add CRUD endpoints for resource foo. By given http methods only this one would be generated.
104
105
  For available methods see: [`Templates::Endpoints`](https://github.com/LeFnord/grape-starter/blob/d7bb6c4946dc27fcafa5a75435b45bfe2b7277f0/lib/starter/builder/templates/endpoints.rb#L7-L26).
@@ -61,6 +61,8 @@ command :add do |c|
61
61
  desc: 'adds entity file'
62
62
  c.switch [:o, :orm], negatable: false,
63
63
  desc: 'inherit from ORM'
64
+ c.switch [:m, :migration], negatable: false,
65
+ desc: 'create also migration file'
64
66
 
65
67
  c.action do |global_options, options, args|
66
68
  exit_now! 'no resource given' if args.empty?
@@ -27,6 +27,9 @@ module Starter
27
27
  # name - A String as project name
28
28
  # source - A String which provides the template path
29
29
  # destination - A String which provides the new project path
30
+ # options - A Hash to provide some optional arguments (default: {})
31
+ # :prefix - Sets the Prefix for the API
32
+ # :orm - Sets and creates ORM specific files
30
33
  def new!(name, source, destination, options = {})
31
34
  @resource = name
32
35
  @destination = destination
@@ -38,29 +41,25 @@ module Starter
38
41
  replace_static(File.join(config[:file]), config[:pattern])
39
42
  end
40
43
 
44
+ Starter::Config.save(
45
+ dest: destination,
46
+ content: { prefix: prefix, orm: options[:orm].to_s }
47
+ )
48
+
41
49
  Orms.build(destination, options[:orm]) if options[:orm]
42
- Starter::Config.save(dest: destination, content: { prefix: prefix })
43
50
 
44
51
  self
45
52
  end
46
53
 
47
- def config_static
48
- [
49
- { file: %w[script server], pattern: "API-#{resource}" },
50
- { file: %w[api base.rb], pattern: prefix ? "prefix :#{prefix}" : nil },
51
- { file: %w[spec requests root_spec.rb], pattern: prefix ? "/#{prefix}" : nil },
52
- { file: %w[spec requests documentation_spec.rb], pattern: prefix ? "/#{prefix}" : nil }
53
- ]
54
- end
55
-
56
54
  # would be called from add command
57
55
  #
58
56
  # resource - A String as name
59
57
  # options - A Hash to provide some optional arguments (default: {})
60
- # :set – whitespace separated list of http verbs
61
- # (default: nil, possible: post get put patch delete)
62
- # :force - A Boolean, if given existent files should be overwriten (default: false)
63
- # :entity - A Boolean, if given an entity file would be created (default: false)
58
+ # :set – Whitespace separated list of http verbs
59
+ # (default: nil, possible: post get put patch delete)
60
+ # :force - A Boolean, if given existent files should be overwriten (default: false)
61
+ # :entity - A Boolean, if given an entity file would be created (default: false)
62
+ # :orm - A Boolean, if given the created lib/model file will be inherited orm specific (default: false)
64
63
  def add!(resource, options = {})
65
64
  @resource = resource
66
65
  @set = options[:set]
@@ -68,6 +67,7 @@ module Starter
68
67
  @entity = options[:entity]
69
68
  @orm = options[:orm]
70
69
 
70
+ Orms.add_migration(klass_name, resource.downcase) if @orm
71
71
  save_resource
72
72
  end
73
73
 
@@ -75,7 +75,7 @@ module Starter
75
75
  #
76
76
  # resource - A String, which indicates the resource to remove
77
77
  # options - A Hash to provide some optional arguments (default: {})
78
- # :entity - A Boolean, if given an entity file would also be removed (default: nil -> false)
78
+ # :entity - A Boolean, if given an entity file would also be removed (default: nil -> false)
79
79
  def remove!(resource, options = {})
80
80
  @resource = resource
81
81
  @entity = options[:entity]
@@ -105,7 +105,18 @@ module Starter
105
105
 
106
106
  # #new! project creation releated helper methods
107
107
  #
108
- # replace something in existend files
108
+ # defines static files to be created
109
+ def config_static
110
+ [
111
+ { file: %w[script server], pattern: "API-#{resource}" },
112
+ { file: %w[api base.rb], pattern: prefix ? "prefix :#{prefix}" : nil },
113
+ { file: %w[spec requests root_spec.rb], pattern: prefix ? "/#{prefix}" : nil },
114
+ { file: %w[spec requests documentation_spec.rb], pattern: prefix ? "/#{prefix}" : nil }
115
+ ]
116
+ end
117
+
118
+ #
119
+ # replace something in static files
109
120
  def replace_static(file, replacement)
110
121
  server_file = File.join(destination, file)
111
122
 
@@ -4,18 +4,12 @@ module Starter
4
4
  class Orms
5
5
  class << self
6
6
  def build(dest, orm)
7
- @orm = orm
8
- case orm.downcase
9
- when 'sequel'
10
- require 'starter/builder/templates/sequel'
11
- extend(::Starter::Templates::Sequel)
12
- when 'activerecord', 'ar'
13
- require 'starter/builder/templates/activerecord'
14
- extend(::Starter::Templates::ActiveRecord)
7
+ load_orm(orm: orm)
8
+ return if @orm.nil?
9
+
10
+ if @orm == 'ar' || @orm == 'activerecord'
15
11
  # Fixes pooling
16
12
  add_middleware(dest, 'ActiveRecord::Rack::ConnectionManagement')
17
- else
18
- return
19
13
  end
20
14
 
21
15
  build_initializer(File.join(dest, 'config', 'initializers'))
@@ -23,8 +17,6 @@ module Starter
23
17
  append_to_file(File.join(dest, 'Rakefile'), rakefile)
24
18
  append_to_file(File.join(dest, 'Gemfile'), gemfile)
25
19
  prepare_for_migrations(File.join(dest, 'db'))
26
-
27
- Starter::Config.save(dest: dest, content: { orm: orm.downcase })
28
20
  end
29
21
 
30
22
  def config
@@ -56,6 +48,30 @@ module Starter
56
48
  FILE
57
49
  end
58
50
 
51
+ def add_migration(klass_name, resource)
52
+ load_orm
53
+ return if @orm.nil?
54
+
55
+ file_name = "#{Time.now.strftime('%Y%m%d%H%m%S')}_Create#{klass_name}.rb"
56
+ migration_dest = File.join(Dir.pwd, 'db', 'migrations', file_name)
57
+ FileFoo.write_file(migration_dest, migration(klass_name, resource))
58
+ end
59
+
60
+ def load_orm(orm: ::Starter::Config.read[:orm])
61
+ @orm = orm
62
+
63
+ case @orm
64
+ when 'sequel'
65
+ require 'starter/builder/templates/sequel'
66
+ extend(::Starter::Templates::Sequel)
67
+ when 'activerecord', 'ar'
68
+ require 'starter/builder/templates/activerecord'
69
+ extend(::Starter::Templates::ActiveRecord)
70
+ else
71
+ @orm = nil
72
+ end
73
+ end
74
+
59
75
  private
60
76
 
61
77
  def adapter
@@ -86,6 +86,19 @@ module Starter
86
86
  gem 'sqlite3'
87
87
  FILE
88
88
  end
89
+
90
+ def migration(klass_name, resource)
91
+ <<-FILE.strip_heredoc
92
+ class Create#{klass_name} < ActiveRecord::Migration[5.1]
93
+ def change
94
+ create_table :#{resource} do |t|
95
+
96
+ t.timestamps
97
+ end
98
+ end
99
+ end
100
+ FILE
101
+ end
89
102
  end
90
103
  end
91
104
  end
@@ -86,6 +86,21 @@ module Starter
86
86
  gem 'sqlite3'
87
87
  FILE
88
88
  end
89
+
90
+ def migration(_klass_name, resource)
91
+ <<-FILE.strip_heredoc
92
+ Sequel.migration do
93
+ change do
94
+ create_table :#{resource} do
95
+ primary_key :id
96
+
97
+ DateTime :created_at
98
+ DateTime :updated_at
99
+ end
100
+ end
101
+ end
102
+ FILE
103
+ end
89
104
  end
90
105
  end
91
106
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Starter
4
- VERSION = '0.8.7'
4
+ VERSION = '1.0.0'
5
5
  end
@@ -7,7 +7,6 @@ gem 'thin'
7
7
  gem 'rack'
8
8
  gem 'rack-cors'
9
9
 
10
- # FIXME: lock to specific version before you are going into production
11
10
  gem 'grape'
12
11
  gem 'grape-entity'
13
12
  gem 'grape-swagger'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-starter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.7
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - LeFnord
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-08 00:00:00.000000000 Z
11
+ date: 2018-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -76,6 +76,7 @@ extra_rdoc_files: []
76
76
  files:
77
77
  - ".gitignore"
78
78
  - ".inch.yml"
79
+ - ".rspec"
79
80
  - ".rubocop.yml"
80
81
  - ".rubocop_todo.yml"
81
82
  - ".travis.yml"