sumcli 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +6 -0
  7. data/Gemfile.lock +144 -0
  8. data/LICENSE.txt +20 -0
  9. data/README.md +43 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/docker-compose.yml +2 -0
  14. data/exe/sumcli +18 -0
  15. data/lib/sumcli/cli.rb +37 -0
  16. data/lib/sumcli/command.rb +121 -0
  17. data/lib/sumcli/commands/.gitkeep +1 -0
  18. data/lib/sumcli/commands/add/service.rb +30 -0
  19. data/lib/sumcli/commands/add.rb +24 -0
  20. data/lib/sumcli/commands/g/endpoint.rb +69 -0
  21. data/lib/sumcli/commands/g.rb +24 -0
  22. data/lib/sumcli/commands/new.rb +25 -0
  23. data/lib/sumcli/templates/.gitkeep +1 -0
  24. data/lib/sumcli/templates/add/service/.gitkeep +1 -0
  25. data/lib/sumcli/templates/g/endpoint/.gitkeep +1 -0
  26. data/lib/sumcli/templates/g/endpoint/entity.rb.erb +7 -0
  27. data/lib/sumcli/templates/g/endpoint/new.rb.erb +8 -0
  28. data/lib/sumcli/templates/g/endpoint/test.rb.erb +19 -0
  29. data/lib/sumcli/templates/new/.gitkeep +1 -0
  30. data/lib/sumcli/templates/new/app/.editorconfig +12 -0
  31. data/lib/sumcli/templates/new/app/.gitignore +9 -0
  32. data/lib/sumcli/templates/new/app/.rspec +2 -0
  33. data/lib/sumcli/templates/new/app/.ruby-version +1 -0
  34. data/lib/sumcli/templates/new/app/Dockerfile +14 -0
  35. data/lib/sumcli/templates/new/app/Gemfile +35 -0
  36. data/lib/sumcli/templates/new/app/Guardfile +33 -0
  37. data/lib/sumcli/templates/new/app/Procfile +5 -0
  38. data/lib/sumcli/templates/new/app/README.md +103 -0
  39. data/lib/sumcli/templates/new/app/Rakefile +38 -0
  40. data/lib/sumcli/templates/new/app/api/base.rb +6 -0
  41. data/lib/sumcli/templates/new/app/api/endpoints/base.rb +15 -0
  42. data/lib/sumcli/templates/new/app/app/exceptions/not_found_error.rb +1 -0
  43. data/lib/sumcli/templates/new/app/bin/console +13 -0
  44. data/lib/sumcli/templates/new/app/config/application.rb +15 -0
  45. data/lib/sumcli/templates/new/app/config/environment.rb +4 -0
  46. data/lib/sumcli/templates/new/app/config.ru +5 -0
  47. data/lib/sumcli/templates/new/app/docker-compose.yml +2 -0
  48. data/lib/sumcli/templates/new/app/spec/spec_helper.rb +39 -0
  49. data/lib/sumcli/version.rb +3 -0
  50. data/lib/sumcli.rb +6 -0
  51. data/sumcli.gemspec +53 -0
  52. metadata +445 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 94b43a29661d0deb26d7fe4cf3e0f2128a9812b82986f4a04fd7e34973545bff
4
+ data.tar.gz: 483c020c4eae626fcbc6ae98034239218cd02929b6cf0c86adbf95a232e17e16
5
+ SHA512:
6
+ metadata.gz: da0b86d8b42d721f6b6fa41da1c4d56715d9795fcdd06fc61bde51e56321754f5ea5d0275603400f602a5c2ffd36fb6badeea1742315a2229c906229b7db4261
7
+ data.tar.gz: 68fa839a31d1dc61f977bb7b5d544e36347ad5af4caa32e5c15d9e02af8fa98f08dc4a8601494dc586721527f2a2f5cfbecbd6ed249df2fc981c8abe8153b0cf
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ tags
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.4.1
7
+ before_install: gem install bundler -v 1.17.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at rodrigo.souza@sumup.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in sumcli.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,144 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sumcli (0.1.0)
5
+ activesupport (~> 5.0)
6
+ pastel (~> 0.7.2)
7
+ thor (~> 0.20.0)
8
+ tty-box (~> 0.3.0)
9
+ tty-color (~> 0.4)
10
+ tty-command (~> 0.8.0)
11
+ tty-config (~> 0.3.0)
12
+ tty-cursor (~> 0.6)
13
+ tty-editor (~> 0.5.0)
14
+ tty-file (~> 0.7.0)
15
+ tty-font (~> 0.2.0)
16
+ tty-markdown (~> 0.5.0)
17
+ tty-pager (~> 0.12.0)
18
+ tty-pie (~> 0.1.0)
19
+ tty-platform (~> 0.2.0)
20
+ tty-progressbar (~> 0.16.0)
21
+ tty-prompt (~> 0.18.0)
22
+ tty-screen (~> 0.6)
23
+ tty-spinner (~> 0.9.0)
24
+ tty-table (~> 0.10.0)
25
+ tty-tree (~> 0.2.0)
26
+ tty-which (~> 0.4)
27
+
28
+ GEM
29
+ remote: https://rubygems.org/
30
+ specs:
31
+ activesupport (5.2.3)
32
+ concurrent-ruby (~> 1.0, >= 1.0.2)
33
+ i18n (>= 0.7, < 2)
34
+ minitest (~> 5.1)
35
+ tzinfo (~> 1.1)
36
+ concurrent-ruby (1.1.5)
37
+ diff-lcs (1.3)
38
+ equatable (0.5.0)
39
+ i18n (1.6.0)
40
+ concurrent-ruby (~> 1.0)
41
+ kramdown (1.16.2)
42
+ minitest (5.11.3)
43
+ necromancer (0.4.0)
44
+ pastel (0.7.2)
45
+ equatable (~> 0.5.0)
46
+ tty-color (~> 0.4.0)
47
+ rake (10.5.0)
48
+ rouge (3.3.0)
49
+ rspec (3.8.0)
50
+ rspec-core (~> 3.8.0)
51
+ rspec-expectations (~> 3.8.0)
52
+ rspec-mocks (~> 3.8.0)
53
+ rspec-core (3.8.0)
54
+ rspec-support (~> 3.8.0)
55
+ rspec-expectations (3.8.3)
56
+ diff-lcs (>= 1.2.0, < 2.0)
57
+ rspec-support (~> 3.8.0)
58
+ rspec-mocks (3.8.0)
59
+ diff-lcs (>= 1.2.0, < 2.0)
60
+ rspec-support (~> 3.8.0)
61
+ rspec-support (3.8.0)
62
+ strings (0.1.5)
63
+ strings-ansi (~> 0.1)
64
+ unicode-display_width (~> 1.5)
65
+ unicode_utils (~> 1.4)
66
+ strings-ansi (0.1.0)
67
+ thor (0.20.3)
68
+ thread_safe (0.3.6)
69
+ timers (4.3.0)
70
+ tty-box (0.3.0)
71
+ pastel (~> 0.7.2)
72
+ strings (~> 0.1.4)
73
+ tty-cursor (~> 0.6.0)
74
+ tty-color (0.4.3)
75
+ tty-command (0.8.2)
76
+ pastel (~> 0.7.0)
77
+ tty-config (0.3.1)
78
+ tty-cursor (0.6.1)
79
+ tty-editor (0.5.0)
80
+ tty-prompt (~> 0.18)
81
+ tty-which (~> 0.4)
82
+ tty-file (0.7.1)
83
+ diff-lcs (~> 1.3)
84
+ pastel (~> 0.7.2)
85
+ tty-prompt (~> 0.18)
86
+ tty-font (0.2.0)
87
+ tty-markdown (0.5.1)
88
+ kramdown (~> 1.16.2)
89
+ pastel (~> 0.7.2)
90
+ rouge (~> 3.3)
91
+ strings (~> 0.1.4)
92
+ tty-color (~> 0.4)
93
+ tty-screen (~> 0.6)
94
+ tty-pager (0.12.1)
95
+ strings (~> 0.1.4)
96
+ tty-screen (~> 0.6)
97
+ tty-which (~> 0.4)
98
+ tty-pie (0.1.0)
99
+ pastel (~> 0.7.2)
100
+ tty-cursor (~> 0.6.0)
101
+ tty-platform (0.2.0)
102
+ tty-progressbar (0.16.0)
103
+ strings-ansi (~> 0.1.0)
104
+ tty-cursor (~> 0.6.0)
105
+ tty-screen (~> 0.6.4)
106
+ unicode-display_width (~> 1.3)
107
+ tty-prompt (0.18.1)
108
+ necromancer (~> 0.4.0)
109
+ pastel (~> 0.7.0)
110
+ timers (~> 4.0)
111
+ tty-cursor (~> 0.6.0)
112
+ tty-reader (~> 0.5.0)
113
+ tty-reader (0.5.0)
114
+ tty-cursor (~> 0.6.0)
115
+ tty-screen (~> 0.6.4)
116
+ wisper (~> 2.0.0)
117
+ tty-screen (0.6.5)
118
+ tty-spinner (0.9.0)
119
+ tty-cursor (~> 0.6.0)
120
+ tty-table (0.10.0)
121
+ equatable (~> 0.5.0)
122
+ necromancer (~> 0.4.0)
123
+ pastel (~> 0.7.2)
124
+ strings (~> 0.1.0)
125
+ tty-screen (~> 0.6.4)
126
+ tty-tree (0.2.0)
127
+ tty-which (0.4.1)
128
+ tzinfo (1.2.5)
129
+ thread_safe (~> 0.1)
130
+ unicode-display_width (1.6.0)
131
+ unicode_utils (1.4.0)
132
+ wisper (2.0.0)
133
+
134
+ PLATFORMS
135
+ ruby
136
+
137
+ DEPENDENCIES
138
+ bundler (~> 1.17)
139
+ rake (~> 10.0)
140
+ rspec (~> 3.0)
141
+ sumcli!
142
+
143
+ BUNDLED WITH
144
+ 1.17.3
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Rodrigo Alves
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Sumcli
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sumcli`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sumcli'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sumcli
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sumcli. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## Code of Conduct
38
+
39
+ Everyone interacting in the Sumcli project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/sumcli/blob/master/CODE_OF_CONDUCT.md).
40
+
41
+ ## Copyright
42
+
43
+ Copyright (c) 2019 Rodrigo Alves. See [MIT License](LICENSE.txt) for further details.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sumcli"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,2 @@
1
+ version: '3'
2
+ services:
data/exe/sumcli ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ lib_path = File.expand_path('../lib', __dir__)
5
+ $:.unshift(lib_path) if !$:.include?(lib_path)
6
+ require 'sumcli/cli'
7
+
8
+ Signal.trap('INT') do
9
+ warn("\n#{caller.join("\n")}: interrupted")
10
+ exit(1)
11
+ end
12
+
13
+ begin
14
+ Sumcli::CLI.start
15
+ rescue Sumcli::CLI::Error => err
16
+ puts "ERROR: #{err.message}"
17
+ exit 1
18
+ end
data/lib/sumcli/cli.rb ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+
5
+ module Sumcli
6
+ # Handle the application command line parsing
7
+ # and the dispatch to various command objects
8
+ #
9
+ # @api public
10
+ class CLI < Thor
11
+ # Error raised by this runner
12
+ Error = Class.new(StandardError)
13
+
14
+ desc 'version', 'sumcli version'
15
+ def version
16
+ require_relative 'version'
17
+ puts "v#{Sumcli::VERSION}"
18
+ end
19
+ map %w(--version -v) => :version
20
+
21
+ require_relative 'commands/g'
22
+ require_relative 'commands/new'
23
+ require_relative 'commands/add'
24
+ register Sumcli::Commands::G, 'g', 'g endpoint', 'Generates a new REST endpoint'
25
+ register Sumcli::Commands::Add, 'add', 'add service', 'It adds a service to the docker file'
26
+ desc 'new NAME', 'Creates a new application'
27
+ method_option :help, aliases: '-h', type: :boolean,
28
+ desc: 'Display usage information'
29
+ def new(name)
30
+ if options[:help]
31
+ invoke :help, ['new']
32
+ else
33
+ Sumcli::Commands::New.new(name, options).execute
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ module Sumcli
6
+ class Command
7
+ extend Forwardable
8
+
9
+ def_delegators :command, :run
10
+
11
+ # Execute this command
12
+ #
13
+ # @api public
14
+ def execute(*)
15
+ raise(
16
+ NotImplementedError,
17
+ "#{self.class}##{__method__} must be implemented"
18
+ )
19
+ end
20
+
21
+ # The external commands runner
22
+ #
23
+ # @see http://www.rubydoc.info/gems/tty-command
24
+ #
25
+ # @api public
26
+ def command(**options)
27
+ require 'tty-command'
28
+ TTY::Command.new(options)
29
+ end
30
+
31
+ # The cursor movement
32
+ #
33
+ # @see http://www.rubydoc.info/gems/tty-cursor
34
+ #
35
+ # @api public
36
+ def cursor
37
+ require 'tty-cursor'
38
+ TTY::Cursor
39
+ end
40
+
41
+ # Open a file or text in the user's preferred editor
42
+ #
43
+ # @see http://www.rubydoc.info/gems/tty-editor
44
+ #
45
+ # @api public
46
+ def editor
47
+ require 'tty-editor'
48
+ TTY::Editor
49
+ end
50
+
51
+ # File manipulation utility methods
52
+ #
53
+ # @see http://www.rubydoc.info/gems/tty-file
54
+ #
55
+ # @api public
56
+ def generator
57
+ require 'tty-file'
58
+ TTY::File
59
+ end
60
+
61
+ # Terminal output paging
62
+ #
63
+ # @see http://www.rubydoc.info/gems/tty-pager
64
+ #
65
+ # @api public
66
+ def pager(**options)
67
+ require 'tty-pager'
68
+ TTY::Pager.new(options)
69
+ end
70
+
71
+ # Terminal platform and OS properties
72
+ #
73
+ # @see http://www.rubydoc.info/gems/tty-pager
74
+ #
75
+ # @api public
76
+ def platform
77
+ require 'tty-platform'
78
+ TTY::Platform.new
79
+ end
80
+
81
+ # The interactive prompt
82
+ #
83
+ # @see http://www.rubydoc.info/gems/tty-prompt
84
+ #
85
+ # @api public
86
+ def prompt(**options)
87
+ require 'tty-prompt'
88
+ TTY::Prompt.new(options)
89
+ end
90
+
91
+ # Get terminal screen properties
92
+ #
93
+ # @see http://www.rubydoc.info/gems/tty-screen
94
+ #
95
+ # @api public
96
+ def screen
97
+ require 'tty-screen'
98
+ TTY::Screen
99
+ end
100
+
101
+ # The unix which utility
102
+ #
103
+ # @see http://www.rubydoc.info/gems/tty-which
104
+ #
105
+ # @api public
106
+ def which(*args)
107
+ require 'tty-which'
108
+ TTY::Which.which(*args)
109
+ end
110
+
111
+ # Check if executable exists
112
+ #
113
+ # @see http://www.rubydoc.info/gems/tty-which
114
+ #
115
+ # @api public
116
+ def exec_exist?(*args)
117
+ require 'tty-which'
118
+ TTY::Which.exist?(*args)
119
+ end
120
+ end
121
+ end
@@ -0,0 +1 @@
1
+ #
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../command'
4
+
5
+ module Sumcli
6
+ module Commands
7
+ class Add
8
+ class Service < Sumcli::Command
9
+
10
+ DOCKER_FILE = 'docker-compose.yml'
11
+
12
+ def initialize(name, options)
13
+ @name = name
14
+ @options = options
15
+ end
16
+
17
+ def execute(input: $stdin, output: $stdout)
18
+ self.send("add_#{@name}")
19
+
20
+ output.puts @name + ' added to docker-compose'
21
+ end
22
+
23
+ def add_postgres()
24
+ generator.inject_into_file DOCKER_FILE,
25
+ " db:\n" + " image: 'postgres:9.6.3'\n" + " ports:\n" + " - '5432'", after: "services:\n"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+
5
+ module Sumcli
6
+ module Commands
7
+ class Add < Thor
8
+
9
+ namespace :add
10
+
11
+ desc 'service NAME', 'Command description...'
12
+ method_option :help, aliases: '-h', type: :boolean,
13
+ desc: 'Display usage information'
14
+ def service(name)
15
+ if options[:help]
16
+ invoke :help, ['service']
17
+ else
18
+ require_relative 'add/service'
19
+ Sumcli::Commands::Add::Service.new(name, options).execute
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+ require 'ostruct'
3
+ require 'active_support/inflector'
4
+ require_relative '../../command'
5
+
6
+ module Sumcli
7
+ module Commands
8
+ class G
9
+ class Endpoint < Sumcli::Command
10
+ ENDPOINT_PATH = 'api/endpoints'
11
+ ENTITIES_PATH = 'api/entities'
12
+ TESTS_PATH = 'spec/api'
13
+
14
+ def initialize(name, method, route, options)
15
+ @name = name
16
+ @method = method
17
+ @route = route
18
+ @options = options
19
+ @variables = OpenStruct.new(name: @name, route: @route, method: @method)
20
+ end
21
+
22
+ def execute(input: $stdin, output: $stdout)
23
+ create_entity unless File.file?("#{ENTITIES_PATH}/#{@name.underscore}.rb")
24
+ create_test unless File.file?("#{TESTS_PATH}/#{@name.underscore}.rb")
25
+ create_endpoint unless File.file?("#{ENDPOINT_PATH}/#{@name.underscore}.rb")
26
+ inject_route unless @method.nil?
27
+ end
28
+
29
+ def inject_route
30
+ generator.inject_into_file("#{ENDPOINT_PATH}/#{@name.underscore}.rb", after: "# ENDPOINTS\n") do <<-RB
31
+
32
+ desc 'Describe your endpoint'
33
+ params do
34
+ # requires :id, type: Integer
35
+ end
36
+ #{@method.downcase} '#{@route}' do
37
+ # write code here..
38
+ end
39
+ RB
40
+ end
41
+ end
42
+
43
+ def create_test
44
+ generator.copy_file(
45
+ 'lib/sumcli/templates/g/endpoint/test.rb.erb',
46
+ "#{TESTS_PATH}/#{@name.underscore}_spec.rb",
47
+ context: @variables
48
+ )
49
+ end
50
+
51
+ def create_entity
52
+ generator.copy_file(
53
+ 'lib/sumcli/templates/g/endpoint/entity.rb.erb',
54
+ "#{ENTITIES_PATH}/#{@name.underscore}.rb",
55
+ context: @variables
56
+ )
57
+ end
58
+
59
+ def create_endpoint
60
+ generator.copy_file(
61
+ 'lib/sumcli/templates/g/endpoint/new.rb.erb',
62
+ "#{ENDPOINT_PATH}/#{@name.underscore}.rb",
63
+ context: @variables
64
+ )
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end