shogun 6.2.1 → 6.2.2

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 (140) hide show
  1. checksums.yaml +4 -4
  2. data/lib/shogun/version.rb +1 -1
  3. data/scaffold/generate/resource.rb +15 -0
  4. data/scaffold/generate/resource/create.rb +10 -0
  5. data/scaffold/generate/resource/create/authorizer.rb +21 -0
  6. data/scaffold/generate/resource/create/control.rb +27 -0
  7. data/scaffold/generate/resource/create/denormalizer.rb +31 -0
  8. data/scaffold/generate/resource/create/normalizer.rb +22 -0
  9. data/scaffold/generate/resource/create/validator.rb +14 -0
  10. data/scaffold/generate/resource/destroy.rb +11 -0
  11. data/scaffold/generate/resource/destroy/authorizer.rb +21 -0
  12. data/scaffold/generate/resource/destroy/control.rb +37 -0
  13. data/scaffold/generate/resource/destroy/denormalizer.rb +31 -0
  14. data/scaffold/generate/resource/destroy/normalizer.rb +28 -0
  15. data/scaffold/generate/resource/destroy/validator.rb +20 -0
  16. data/scaffold/generate/resource/endpoint.rb +16 -0
  17. data/scaffold/generate/resource/list.rb +10 -0
  18. data/scaffold/generate/resource/list/authorizer.rb +21 -0
  19. data/scaffold/generate/resource/list/control.rb +26 -0
  20. data/scaffold/generate/resource/list/denormalizer.rb +33 -0
  21. data/scaffold/generate/resource/list/normalizer.rb +58 -0
  22. data/scaffold/generate/resource/list/validator.rb +24 -0
  23. data/scaffold/generate/resource/model.rb +21 -0
  24. data/scaffold/generate/resource/null.rb +11 -0
  25. data/scaffold/generate/resource/presenter.rb +24 -0
  26. data/scaffold/generate/resource/show.rb +10 -0
  27. data/scaffold/generate/resource/show/authorizer.rb +21 -0
  28. data/scaffold/generate/resource/show/control.rb +31 -0
  29. data/scaffold/generate/resource/show/denormalizer.rb +18 -0
  30. data/scaffold/generate/resource/show/normalizer.rb +37 -0
  31. data/scaffold/generate/resource/show/validator.rb +21 -0
  32. data/scaffold/generate/resource/update.rb +11 -0
  33. data/scaffold/generate/resource/update/authorizer.rb +21 -0
  34. data/scaffold/generate/resource/update/control.rb +37 -0
  35. data/scaffold/generate/resource/update/denormalizer.rb +31 -0
  36. data/scaffold/generate/resource/update/normalizer.rb +37 -0
  37. data/scaffold/generate/resource/update/validator.rb +14 -0
  38. data/scaffold/new/project/Envfile +17 -0
  39. data/scaffold/new/project/Gemfile +18 -0
  40. data/scaffold/new/project/LICENSE +22 -0
  41. data/scaffold/new/project/Procfile +1 -0
  42. data/scaffold/new/project/README.md +32 -0
  43. data/scaffold/new/project/Rakefile +9 -0
  44. data/scaffold/new/project/config.ru +8 -0
  45. data/scaffold/new/project/config/puma.rb +167 -0
  46. data/scaffold/new/project/gitignore +39 -0
  47. data/scaffold/new/project/lib/namespace.rb +29 -0
  48. data/scaffold/new/project/lib/namespace/accounts.rb +15 -0
  49. data/scaffold/new/project/lib/namespace/accounts/create.rb +10 -0
  50. data/scaffold/new/project/lib/namespace/accounts/create/control.rb +27 -0
  51. data/scaffold/new/project/lib/namespace/accounts/create/denormalizer.rb +35 -0
  52. data/scaffold/new/project/lib/namespace/accounts/create/normalizer.rb +42 -0
  53. data/scaffold/new/project/lib/namespace/accounts/create/validator.rb +34 -0
  54. data/scaffold/new/project/lib/namespace/accounts/destroy.rb +11 -0
  55. data/scaffold/new/project/lib/namespace/accounts/destroy/authorizer.rb +21 -0
  56. data/scaffold/new/project/lib/namespace/accounts/destroy/control.rb +37 -0
  57. data/scaffold/new/project/lib/namespace/accounts/destroy/denormalizer.rb +35 -0
  58. data/scaffold/new/project/lib/namespace/accounts/destroy/normalizer.rb +28 -0
  59. data/scaffold/new/project/lib/namespace/accounts/destroy/validator.rb +20 -0
  60. data/scaffold/new/project/lib/namespace/accounts/endpoint.rb +16 -0
  61. data/scaffold/new/project/lib/namespace/accounts/list.rb +10 -0
  62. data/scaffold/new/project/lib/namespace/accounts/list/control.rb +26 -0
  63. data/scaffold/new/project/lib/namespace/accounts/list/denormalizer.rb +37 -0
  64. data/scaffold/new/project/lib/namespace/accounts/list/normalizer.rb +58 -0
  65. data/scaffold/new/project/lib/namespace/accounts/list/validator.rb +24 -0
  66. data/scaffold/new/project/lib/namespace/accounts/model.rb +49 -0
  67. data/scaffold/new/project/lib/namespace/accounts/null.rb +11 -0
  68. data/scaffold/new/project/lib/namespace/accounts/presenter.rb +40 -0
  69. data/scaffold/new/project/lib/namespace/accounts/show.rb +10 -0
  70. data/scaffold/new/project/lib/namespace/accounts/show/control.rb +31 -0
  71. data/scaffold/new/project/lib/namespace/accounts/show/denormalizer.rb +22 -0
  72. data/scaffold/new/project/lib/namespace/accounts/show/normalizer.rb +37 -0
  73. data/scaffold/new/project/lib/namespace/accounts/show/validator.rb +21 -0
  74. data/scaffold/new/project/lib/namespace/accounts/update.rb +11 -0
  75. data/scaffold/new/project/lib/namespace/accounts/update/authorizer.rb +21 -0
  76. data/scaffold/new/project/lib/namespace/accounts/update/control.rb +37 -0
  77. data/scaffold/new/project/lib/namespace/accounts/update/denormalizer.rb +35 -0
  78. data/scaffold/new/project/lib/namespace/accounts/update/normalizer.rb +52 -0
  79. data/scaffold/new/project/lib/namespace/accounts/update/validator.rb +47 -0
  80. data/scaffold/new/project/lib/namespace/errors.rb +8 -0
  81. data/scaffold/new/project/lib/namespace/errors/denormalizer.rb +24 -0
  82. data/scaffold/new/project/lib/namespace/errors/presenter.rb +16 -0
  83. data/scaffold/new/project/lib/namespace/server.rb +54 -0
  84. data/scaffold/new/project/lib/namespace/sessions.rb +11 -0
  85. data/scaffold/new/project/lib/namespace/sessions/create.rb +11 -0
  86. data/scaffold/new/project/lib/namespace/sessions/create/authorizer.rb +19 -0
  87. data/scaffold/new/project/lib/namespace/sessions/create/control.rb +26 -0
  88. data/scaffold/new/project/lib/namespace/sessions/create/denormalizer.rb +30 -0
  89. data/scaffold/new/project/lib/namespace/sessions/create/normalizer.rb +31 -0
  90. data/scaffold/new/project/lib/namespace/sessions/create/validator.rb +21 -0
  91. data/scaffold/new/project/lib/namespace/sessions/destroy.rb +10 -0
  92. data/scaffold/new/project/lib/namespace/sessions/destroy/control.rb +32 -0
  93. data/scaffold/new/project/lib/namespace/sessions/destroy/denormalizer.rb +29 -0
  94. data/scaffold/new/project/lib/namespace/sessions/destroy/normalizer.rb +20 -0
  95. data/scaffold/new/project/lib/namespace/sessions/destroy/validator.rb +16 -0
  96. data/scaffold/new/project/lib/namespace/sessions/endpoint.rb +13 -0
  97. data/scaffold/new/project/lib/namespace/sessions/model.rb +25 -0
  98. data/scaffold/new/project/lib/namespace/sessions/presenter.rb +40 -0
  99. data/scaffold/new/project/spec/lib/namespace/accounts/create/control_spec.rb +1 -0
  100. data/scaffold/new/project/spec/lib/namespace/accounts/create/denormalizer_spec.rb +1 -0
  101. data/scaffold/new/project/spec/lib/namespace/accounts/create/normalizer_spec.rb +1 -0
  102. data/scaffold/new/project/spec/lib/namespace/accounts/create/validator_spec.rb +1 -0
  103. data/scaffold/new/project/spec/lib/namespace/accounts/destroy/control_spec.rb +1 -0
  104. data/scaffold/new/project/spec/lib/namespace/accounts/destroy/denormalizer_spec.rb +1 -0
  105. data/scaffold/new/project/spec/lib/namespace/accounts/destroy/normalizer_spec.rb +1 -0
  106. data/scaffold/new/project/spec/lib/namespace/accounts/destroy/validator_spec.rb +1 -0
  107. data/scaffold/new/project/spec/lib/namespace/accounts/endpoint_spec.rb +1 -0
  108. data/scaffold/new/project/spec/lib/namespace/accounts/list/control_spec.rb +1 -0
  109. data/scaffold/new/project/spec/lib/namespace/accounts/list/denormalizer_spec.rb +1 -0
  110. data/scaffold/new/project/spec/lib/namespace/accounts/list/normalizer_spec.rb +1 -0
  111. data/scaffold/new/project/spec/lib/namespace/accounts/list/validator_spec.rb +1 -0
  112. data/scaffold/new/project/spec/lib/namespace/accounts/model_spec.rb +1 -0
  113. data/scaffold/new/project/spec/lib/namespace/accounts/presenter_spec.rb +1 -0
  114. data/scaffold/new/project/spec/lib/namespace/accounts/show/control_spec.rb +1 -0
  115. data/scaffold/new/project/spec/lib/namespace/accounts/show/denormalizer_spec.rb +1 -0
  116. data/scaffold/new/project/spec/lib/namespace/accounts/show/normalizer_spec.rb +1 -0
  117. data/scaffold/new/project/spec/lib/namespace/accounts/show/validator_spec.rb +1 -0
  118. data/scaffold/new/project/spec/lib/namespace/accounts/update/control_spec.rb +1 -0
  119. data/scaffold/new/project/spec/lib/namespace/accounts/update/denormalizer_spec.rb +1 -0
  120. data/scaffold/new/project/spec/lib/namespace/accounts/update/normalizer_spec.rb +1 -0
  121. data/scaffold/new/project/spec/lib/namespace/accounts/update/validator_spec.rb +1 -0
  122. data/scaffold/new/project/spec/lib/namespace/errors/denormalizer_spec.rb +1 -0
  123. data/scaffold/new/project/spec/lib/namespace/errors/presenter_spec.rb +1 -0
  124. data/scaffold/new/project/spec/lib/namespace/errors/presenters_spec.rb +1 -0
  125. data/scaffold/new/project/spec/lib/namespace/model_spec.rb +1 -0
  126. data/scaffold/new/project/spec/lib/namespace/server_spec.rb +1 -0
  127. data/scaffold/new/project/spec/lib/namespace/sessions/create/control_spec.rb +1 -0
  128. data/scaffold/new/project/spec/lib/namespace/sessions/create/denormalizer_spec.rb +1 -0
  129. data/scaffold/new/project/spec/lib/namespace/sessions/create/normalizer_spec.rb +1 -0
  130. data/scaffold/new/project/spec/lib/namespace/sessions/create/validator_spec.rb +1 -0
  131. data/scaffold/new/project/spec/lib/namespace/sessions/destroy/control_spec.rb +1 -0
  132. data/scaffold/new/project/spec/lib/namespace/sessions/destroy/denormalizer_spec.rb +1 -0
  133. data/scaffold/new/project/spec/lib/namespace/sessions/destroy/normalizer_spec.rb +1 -0
  134. data/scaffold/new/project/spec/lib/namespace/sessions/destroy/validator_spec.rb +1 -0
  135. data/scaffold/new/project/spec/lib/namespace/sessions/endpoint_spec.rb +1 -0
  136. data/scaffold/new/project/spec/lib/namespace/sessions/model_spec.rb +1 -0
  137. data/scaffold/new/project/spec/lib/namespace/sessions/presenter_spec.rb +1 -0
  138. data/scaffold/new/project/spec/lib/namespace_spec.rb +7 -0
  139. data/scaffold/new/project/spec/spec_helper.rb +3 -0
  140. metadata +138 -1
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby -wKU
2
+
3
+ variable :APPLICATION_LOG_LEVEL, :string
4
+ variable :APPLICATION_SESSION_SECRET, :string
5
+ variable :CLIENT_HOST, :string
6
+ variable :SERVER_HOST, :string
7
+ variable :PUMA_THREADS_MAX, :integer
8
+ variable :PUMA_THREADS_MIN, :integer
9
+ variable :PUMA_WORKERS, :integer
10
+ variable :PUMA_WORKER_TIMEOUT, :integer
11
+ variable :RACK_ENV, :string
12
+ variable :PORT,:integer
13
+ variable :DATABASE_POOL, :integer
14
+ variable :DATABASE_REAP_FREQUENCY, :integer
15
+ variable :DATABASE_TIMEZONE, :string
16
+ variable :DATABASE_TIMEOUT, :integer
17
+ variable :DATABASE_URL, :string
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby -wKU
2
+
3
+ source "https://rubygems.org"
4
+
5
+ ruby "2.1.5"
6
+
7
+ gem "shogun", "~> 6.0.0"
8
+ gem "oj", "~> 2.11.1"
9
+ gem "jwt", "~> 1.2.0"
10
+ gem "puma", "~> 2.10.2"
11
+ gem "pg", "~> 0.17.1"
12
+ gem "bcrypt", "~> 3.1.9"
13
+ gem "moneta", "~> 0.8.0"
14
+ gem "pry", "~> 0.10.1"
15
+ gem "rspec", "~> 3.1.0"
16
+ gem "guard", "~> 2.10.2"
17
+ gem "envied", "~> 0.8.1"
18
+ gem "dotenv", "~> 1.0.2"
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 {{author}}
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.
@@ -0,0 +1 @@
1
+ web: bundle exec puma --config config/puma.rb --port $PORT
@@ -0,0 +1,32 @@
1
+ {{namespace}}
2
+ ========
3
+
4
+ - [![Quality](http://img.shields.io/codeclimate/github/{{author}}/{{namespace}}.svg?style=flat-square)](https://codeclimate.com/github/{{author}}/{{namespace}})
5
+ - [![Coverage](http://img.shields.io/codeclimate/coverage/github/{{author}}/{{namespace}}.svg?style=flat-square)](https://codeclimate.com/github/{{author}}/{{namespace}})
6
+ - [![Build](http://img.shields.io/travis-ci/{{author}}/{{namespace}}.svg?style=flat-square)](https://travis-ci.org/{{author}}/{{namespace}})
7
+ - [![Dependencies](http://img.shields.io/gemnasium/{{author}}/{{namespace}}.svg?style=flat-square)](https://gemnasium.com/{{author}}/{{namespace}})
8
+ - [![Tags](http://img.shields.io/github/tag/{{author}}/{{namespace}}.svg?style=flat-square)](http://github.com/{{author}}/{{namespace}}/tags)
9
+ - [![Releases](http://img.shields.io/github/release/{{author}}/{{namespace}}.svg?style=flat-square)](http://github.com/{{author}}/{{namespace}}/releases)
10
+ - [![Issues](http://img.shields.io/github/issues/{{author}}/{{namespace}}.svg?style=flat-square)](http://github.com/{{author}}/{{namespace}}/issues)
11
+ - [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](http://opensource.org/licenses/MIT)
12
+ - [![Version](http://img.shields.io/badge/version-1.0.0-blue.svg?style=flat-square)](http://github.com/{{author}}/{{namespace}})
13
+
14
+
15
+ A sample HTTP HATEOS JSON API project.
16
+
17
+
18
+ middleware
19
+ ==========
20
+
21
+ All of the middleware used:
22
+
23
+ - rack-protection, for protecting against common attack vectors
24
+ - rack-authentication_bearer, for parsing the bearer token
25
+ - rack-accept_setter, for storing an accept string
26
+ - rack-content_length_setter, for determining and storing the content-length
27
+ - rack-chuncker, for handling (automatically) body chunking
28
+ - rack-log, for storing a global logger
29
+ - rack-runtime, for storing the runtime
30
+ - rack-dispatch, for handling routing
31
+ - rack-body_serializer, for serializing the body of responses
32
+ - rack-body_deserializer, for deserializing inputs in requests
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require "rspec/core/rake_task"
4
+
5
+ desc "Run all the tests in spec"
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ desc "Default: run tests"
9
+ task default: :spec
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby -wKU
2
+ # encoding: utf-8
3
+
4
+ require File.expand_path(File.join("..", "lib", "{{namespace}}"), __FILE__)
5
+ require File.expand_path(File.join("..", "lib", "{{namespace}}", "server"), __FILE__)
6
+
7
+ Shogun::Database.new(logger: {{namespace_module}}.logger)
8
+ {{namespace_module}}::Server.new(rack: self, logger: {{namespace_module}}.logger)
@@ -0,0 +1,167 @@
1
+ #!/usr/bin/env puma
2
+
3
+ require "envied"
4
+ require "dotenv"
5
+
6
+ Dotenv.load
7
+ ENVied.require
8
+
9
+ # The directory to operate out of.
10
+ #
11
+ # The default is the current directory.
12
+ #
13
+ # directory '/u/apps/lolcat'
14
+
15
+ # Use an object or block as the rack application. This allows the
16
+ # config file to be the application itself.
17
+ #
18
+ # app do |env|
19
+ # puts env
20
+ #
21
+ # body = 'Hello, World!'
22
+ #
23
+ # [200, { 'Content-Type' => 'text/plain', 'Content-Length' => body.length.to_s }, [body]]
24
+ # end
25
+
26
+ # Load “path” as a rackup file.
27
+ #
28
+ # The default is “config.ru”.
29
+ #
30
+ # rackup '/u/apps/lolcat/config.ru'
31
+
32
+ # Set the environment in which the rack's app will run. The value must be a string.
33
+ #
34
+ # The default is “development”.
35
+ #
36
+ environment(ENV["RACK_ENV"])
37
+
38
+ # Daemonize the server into the background. Highly suggest that
39
+ # this be combined with “pidfile” and “stdout_redirect”.
40
+ #
41
+ # The default is “false”.
42
+ #
43
+ # daemonize
44
+ # daemonize false
45
+
46
+ # Store the pid of the server in the file at “path”.
47
+ #
48
+ # pidfile '/u/apps/lolcat/tmp/pids/puma.pid'
49
+
50
+ # Use “path” as the file to store the server info state. This is
51
+ # used by “pumactl” to query and control the server.
52
+ #
53
+ # state_path '/u/apps/lolcat/tmp/pids/puma.state'
54
+
55
+ # Redirect STDOUT and STDERR to files specified. The 3rd parameter
56
+ # (“append”) specifies whether the output is appended, the default is
57
+ # “false”.
58
+ #
59
+ # stdout_redirect '/u/apps/lolcat/log/stdout', '/u/apps/lolcat/log/stderr'
60
+ # stdout_redirect '/u/apps/lolcat/log/stdout', '/u/apps/lolcat/log/stderr', true
61
+
62
+ # Disable request logging.
63
+ #
64
+ # The default is “false”.
65
+ #
66
+ quiet
67
+
68
+ # Configure “min” to be the minimum number of threads to use to answer
69
+ # requests and “max” the maximum.
70
+ #
71
+ # The default is “0, 16”.
72
+ #
73
+ threads(Integer(ENV["PUMA_THREADS_MIN"]), Integer(ENV["PUMA_THREADS_MAX"]))
74
+
75
+ # Bind the server to “url”. “tcp://”, “unix://” and “ssl://” are the only
76
+ # accepted protocols.
77
+ #
78
+ # The default is “tcp://0.0.0.0:9292”.
79
+ #
80
+ # bind 'tcp://0.0.0.0:9292'
81
+ # bind 'unix:///var/run/puma.sock'
82
+ # bind 'unix:///var/run/puma.sock?umask=0777'
83
+ # bind 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
84
+
85
+ # Instead of “bind 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'” you
86
+ # can also use the “ssl_bind” option.
87
+ #
88
+ # ssl_bind '127.0.0.1', '9292', { key: path_to_key, cert: path_to_cert }
89
+
90
+ # Code to run before doing a restart. This code should
91
+ # close log files, database connections, etc.
92
+ #
93
+ # This can be called multiple times to add code each time.
94
+ #
95
+ on_restart do
96
+ require "./lib/{{namespace}}"
97
+ Shogun::Database.connection.disconnect! and {{namespace_module}}.logger.debug { "Closed database connection." }
98
+ {{namespace_module}}.logger.close
99
+ end
100
+
101
+ # Command to use to restart puma. This should be just how to
102
+ # load puma itself (ie. 'ruby -Ilib bin/puma'), not the arguments
103
+ # to puma, as those are the same as the original process.
104
+ #
105
+ # restart_command '/u/app/lolcat/bin/restart_puma'
106
+
107
+ # === Cluster mode ===
108
+
109
+ # How many worker processes to run.
110
+ #
111
+ # The default is “0”.
112
+ #
113
+ workers(Integer(ENV["PUMA_WORKERS"] || 0))
114
+
115
+ # Code to run when a worker boots to setup the process before booting
116
+ # the app.
117
+ #
118
+ # This can be called multiple times to add hooks.
119
+ #
120
+ on_worker_boot do
121
+ require "./lib/{{namespace}}"
122
+ Shogun::Database.new(logger: {{namespace_module}}.logger)
123
+ end
124
+
125
+ # Code to run when a worker boots to setup the process after booting
126
+ # the app.
127
+ #
128
+ # This can be called multiple times to add hooks.
129
+ #
130
+ # after_worker_boot do
131
+ #
132
+ # end
133
+
134
+ # Allow workers to reload bundler context when master process is issued
135
+ # a USR1 signal. This allows proper reloading of gems while the master
136
+ # is preserved across a phased-restart. (incompatible with preload_app)
137
+ # (off by default)
138
+
139
+ # prune_bundler
140
+
141
+ # Preload the application before starting the workers; this conflicts with
142
+ # phased restart feature. (off by default)
143
+
144
+ # preload_app!
145
+
146
+ # Additional text to display in process listing
147
+ #
148
+ tag(ENV["APPLICATION_NAME"])
149
+
150
+ # Change the default timeout of workers
151
+ #
152
+ worker_timeout(Integer(ENV["PUMA_WORKER_TIMEOUT"] || 60))
153
+
154
+ # === Puma control rack application ===
155
+
156
+ # Start the puma control rack application on “url”. This application can
157
+ # be communicated with to control the main server. Additionally, you can
158
+ # provide an authentication token, so all requests to the control server
159
+ # will need to include that token as a query parameter. This allows for
160
+ # simple authentication.
161
+ #
162
+ # Check out https://github.com/puma/puma/blob/master/lib/puma/app/status.rb
163
+ # to see what the app has available.
164
+ #
165
+ # activate_control_app 'unix:///var/run/pumactl.sock'
166
+ # activate_control_app 'unix:///var/run/pumactl.sock', { auth_token: '12345' }
167
+ # activate_control_app 'unix:///var/run/pumactl.sock', { no_token: true }
@@ -0,0 +1,39 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+
10
+ # Ignore all bundler caching
11
+ /vendor/cache
12
+ /vendor/ruby
13
+
14
+ # Ignore the default SQLite database.
15
+ /db/*.sqlite3*
16
+ /db/*.sql
17
+
18
+ # Ignore all logfiles and tempfiles.
19
+ /log/*.log
20
+ /tmp
21
+
22
+ # Ignore environment file
23
+ /.ruby-env
24
+ /.env
25
+
26
+ # Ignore application configuration
27
+ /config/application.yml
28
+
29
+ # Ignoring the compiled assets
30
+ /public/assets
31
+ /public/uploads
32
+
33
+ # Ignore documentation directory
34
+ /doc
35
+
36
+ # Ignoring provisioning files
37
+ /cookbooks
38
+ /.vagrant
39
+ /*.paw
@@ -0,0 +1,29 @@
1
+ require "logger"
2
+ require "scrawl"
3
+ require "bcrypt"
4
+ require "pg"
5
+ require "active_record"
6
+ require "moneta"
7
+ require "adamantium"
8
+ require "memoizable"
9
+ require "shogun"
10
+ require "envied"
11
+ require "dotenv"
12
+
13
+ Dotenv.load
14
+ ENVied.require
15
+
16
+ module {{namespace_module}}
17
+ require_relative "{{namespace}}/errors"
18
+ require_relative "{{namespace}}/accounts"
19
+ require_relative "{{namespace}}/sessions"
20
+
21
+ def self.logger(io: STDOUT, level: ::Logger.const_get(ENV["APPLICATION_LOG_LEVEL"]))
22
+ @logger ||= ::Logger.new(STDOUT).tap do |log|
23
+ log.level = level
24
+ log.formatter = ->(level, stamp, name, message) do
25
+ Scrawl.new(level: level, time: stamp.to_datetime.rfc3339, name: name, message: message.strip).inspect + "\n"
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ module {{namespace_module}}
2
+ module Accounts
3
+ NAMESPACE = "accounts"
4
+
5
+ require_relative "accounts/create"
6
+ require_relative "accounts/destroy"
7
+ require_relative "accounts/endpoint"
8
+ require_relative "accounts/list"
9
+ require_relative "accounts/model"
10
+ require_relative "accounts/null"
11
+ require_relative "accounts/presenter"
12
+ require_relative "accounts/show"
13
+ require_relative "accounts/update"
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ module {{namespace_module}}
2
+ module Accounts
3
+ module Create
4
+ require_relative "create/control"
5
+ require_relative "create/denormalizer"
6
+ require_relative "create/normalizer"
7
+ require_relative "create/validator"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,27 @@
1
+ module {{namespace_module}}
2
+ module Accounts
3
+ module Create
4
+ class Control
5
+ include Shogun::Control
6
+ include Accounts
7
+
8
+ def initialize(payload:)
9
+ @normalizer = Normalizer.new(raw: payload.to_hash)
10
+ @validator = Validator.new(data: @normalizer)
11
+
12
+ if @validator.valid?
13
+ @model = Model.create(@normalizer.to_hash)
14
+
15
+ @presenter = Presenter.new(resource: @model)
16
+ @denormalizer = Denormalizer.new(object: @presenter)
17
+ @status = OK
18
+ else
19
+ @presenters = Shogun::Presenters.new(resources: @validator.invalids, cast: Errors::Presenter)
20
+ @denormalizer = Errors::Denormalizer.new(object: @presenters)
21
+ @status = UNPROCESSABLE_ENTITY
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,35 @@
1
+ module {{namespace_module}}
2
+ module Accounts
3
+ module Create
4
+ class Denormalizer
5
+ include Shogun::Denormalizer
6
+ include Accounts
7
+
8
+ MAPPING = {
9
+ "id" => "id",
10
+ "signature" => "signature",
11
+ "username" => "username",
12
+ "email" => "email",
13
+ "name" => "name",
14
+ "created_at" => "created_at",
15
+ "destroyed_at" => "destroyed_at",
16
+ "updated_at" => "updated_at",
17
+ "href" => "href"
18
+ }
19
+
20
+ def initialize(object:)
21
+ @object = object
22
+ @meta = object.meta
23
+ @links = object.links
24
+ @linked = object.linked
25
+ end
26
+
27
+ private def document
28
+ mapping.inject({}) do |hash, (field, name)|
29
+ hash.merge(field => @object.public_send(name))
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end