potassium 1.2.2 → 1.2.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bcdad6cfdd3e777734516b13ef96ea0b82fa9248
4
- data.tar.gz: 175a6c80dd6d5b9b23966ae5141025d585249bd2
3
+ metadata.gz: 7fd59590a454f141e47a7b05b95fc2d5f65b1090
4
+ data.tar.gz: b11f7656978a084f13d54b9c106fd7a7505ffbf7
5
5
  SHA512:
6
- metadata.gz: a19c13e40895153c58d8d8d5c9a3b80311219b9af995059d5ac98deb25167d9152acc8abaa470ffaf7fd062613a8c384b568c883939a206319a8036c47010991
7
- data.tar.gz: 37644a3e7167d7e43d0f310d05dccf9705304a09d121d04880d2dd6b4f1458d76900019bbd87fade6106018ae00947dd86df210e31c5feeb4a0a8ae3bd0d8216
6
+ metadata.gz: 813d08a035604474ff85f3c7e5bcd927dd3f29ac5425b021c64680b1cd301bed27cd4574164ddb8895eeba79b5693ebbf548d4273a3d0203c92d7e488b6657ab
7
+ data.tar.gz: a821c3bd515630a6d284b5578bc3a252bb6a47830e9ed49ac3e7b9f0f8b1bb572f1214363bfd80b39a1ad4be7d1ee60f6bbcd7f3fafdc241d514dc00d45750bb
data/.editorconfig ADDED
@@ -0,0 +1,24 @@
1
+ # EditorConfig helps developers define and maintain consistent
2
+ # coding styles between different editors and IDEs
3
+ # editorconfig.org
4
+
5
+ root = true
6
+
7
+ [*]
8
+
9
+ # Change these settings to your own preference
10
+ indent_style = space
11
+ indent_size = 2
12
+
13
+ # We recommend you to keep these unchanged
14
+ end_of_line = lf
15
+ charset = utf-8
16
+ trim_trailing_whitespace = true
17
+ insert_final_newline = true
18
+
19
+ [*.js]
20
+ indent_style = space
21
+ indent_size = 2
22
+
23
+ [*.md]
24
+ trim_trailing_whitespace = false
data/CHANGELOG.md CHANGED
@@ -32,5 +32,17 @@ Refactor:
32
32
 
33
33
  ## 1.2.2
34
34
 
35
- Fix:
35
+ Bugfixes:
36
36
  - Multiple changes to make it work correctly within rubygems.
37
+
38
+ ## 1.2.3
39
+
40
+ Bugfixes:
41
+ - Fix database name to use when dashes are present.
42
+
43
+ Features:
44
+ - Added optional API support that includes the following:
45
+ - A concern that offer standard responses to common errors.
46
+ - Versionist Support.
47
+ - `simple_token_authentication`, `active_model_serializers` and `responders` gem.
48
+ - A default responder for API common behavior.
@@ -1,4 +1,4 @@
1
- DB_NAME=<%= @app_name.downcase %>
1
+ DB_NAME=<%= get(:underscorized_app_name) %>
2
2
  DB_USER=root
3
3
  DB_PASSWORD=
4
4
  DEFAULT_EMAIL_ADDRESS=
@@ -0,0 +1,40 @@
1
+ module ApiErrorConcern
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ rescue_from "Exception" do |exc|
6
+ logger.error exc.message
7
+ logger.error exc.backtrace.join("\n")
8
+ api_respond_error(:internal_server_error, {
9
+ msg: "server_error",
10
+ type: exc.class.to_s,
11
+ detail: exc.message
12
+ })
13
+ end
14
+
15
+ rescue_from "ActiveRecord::RecordNotFound" do |exc|
16
+ api_respond_error(:not_found, {
17
+ msg: "record_not_found",
18
+ detail: exc.message
19
+ })
20
+ end
21
+
22
+ rescue_from "ActiveModel::ForbiddenAttributesError" do |exc|
23
+ api_respond_error(:bad_request, {
24
+ msg: "protected_attributes",
25
+ detail: exc.message
26
+ })
27
+ end
28
+
29
+ rescue_from "ActiveRecord::RecordInvalid" do |exc|
30
+ api_respond_error(:bad_request, {
31
+ msg: "invalid_attributes",
32
+ errors: exc.record.errors
33
+ })
34
+ end
35
+ end
36
+
37
+ def api_respond_error(_status, _error_obj = {})
38
+ render json: _error_obj, status: _status
39
+ end
40
+ end
@@ -0,0 +1,6 @@
1
+ class Api::V1::BaseController < ApplicationController
2
+ include ApiErrorConcern
3
+ self.responder = ApiResponder
4
+
5
+ respond_to :json
6
+ end
@@ -0,0 +1,41 @@
1
+ class ApiResponder < ActionController::Responder
2
+ def respond
3
+ return display_errors if has_errors?
4
+ return head :no_content if delete?
5
+
6
+ display resource, :status_code => status_code
7
+ end
8
+
9
+ private
10
+
11
+ def display(resource, given_options = {})
12
+ controller.render options.merge(given_options).merge({
13
+ :json => serializer.as_json
14
+ })
15
+ end
16
+
17
+ def serializer
18
+ serializer_class = ActiveModel::Serializer.serializer_for(resource)
19
+ if serializer_class.present?
20
+ serializer_class.new(resource, options)
21
+ else
22
+ resource
23
+ end
24
+ end
25
+
26
+ def status_code
27
+ return :created if post?
28
+ return :ok
29
+ end
30
+
31
+ def display_errors
32
+ controller.render({
33
+ :status => :unprocessable_entity,
34
+ :json => { msg: "invalid_attributes", errors: format_errors }
35
+ })
36
+ end
37
+
38
+ def format_errors
39
+ resource.errors.as_json
40
+ end
41
+ end
@@ -0,0 +1,22 @@
1
+ if get(:api_support)
2
+ gather_gem 'versionist'
3
+ gather_gem 'responders'
4
+ gather_gem 'active_model_serializers', '~> 0.9.3'
5
+ gather_gem 'simple_token_authentication', '~> 1.0'
6
+
7
+ after(:gem_install) do
8
+ line = "Rails.application.routes.draw do\n"
9
+ insert_into_file "config/routes.rb", after: line do
10
+ <<-HERE.gsub(/^ {7}/, '')
11
+ scope path: '/api' do
12
+ api_version(:module => "Api::V1", :path => {:value => "v1"}) do
13
+ end
14
+ end
15
+ HERE
16
+ end
17
+
18
+ copy_file 'assets/api/base_controller.rb', 'app/controllers/api/v1/base_controller.rb'
19
+ copy_file 'assets/api/api_error_concern.rb', 'app/controllers/concerns/api_error_concern.rb'
20
+ copy_file 'assets/api/responder.rb', 'app/responders/api_responder.rb'
21
+ end
22
+ end
@@ -0,0 +1,2 @@
1
+ api_support = Ask.confirm "Do you want to enable API support?"
2
+ set(:api_support, api_support)
@@ -19,6 +19,7 @@ run_action(:asking) do
19
19
  eval_file "recipes/asks/admin.rb"
20
20
  eval_file "recipes/asks/pundit.rb"
21
21
  eval_file "recipes/asks/lang.rb"
22
+ eval_file "recipes/asks/api.rb"
22
23
  end
23
24
 
24
25
  run_action(:recipe_loading) do
@@ -38,6 +39,7 @@ run_action(:recipe_loading) do
38
39
  eval_file "recipes/testing.rb"
39
40
  eval_file "recipes/production.rb"
40
41
  eval_file "recipes/git.rb"
42
+ eval_file "recipes/api.rb"
41
43
  end
42
44
 
43
45
  say "Gathered enough information. Applying the template. Wait a minute.", :green
@@ -1,3 +1,3 @@
1
1
  module Potassium
2
- VERSION = "1.2.2"
2
+ VERSION = "1.2.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: potassium
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - juliogarciag
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-05 00:00:00.000000000 Z
11
+ date: 2015-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -88,6 +88,7 @@ executables:
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
+ - .editorconfig
91
92
  - .gitignore
92
93
  - CHANGELOG.md
93
94
  - Gemfile
@@ -107,6 +108,9 @@ files:
107
108
  - lib/potassium/templates/application/assets/active_admin/active_admin.js.coffee
108
109
  - lib/potassium/templates/application/assets/active_admin/init_activeadmin_angular.rb
109
110
  - lib/potassium/templates/application/assets/active_admin/pundit_page_policy.rb
111
+ - lib/potassium/templates/application/assets/api/api_error_concern.rb
112
+ - lib/potassium/templates/application/assets/api/base_controller.rb
113
+ - lib/potassium/templates/application/assets/api/responder.rb
110
114
  - lib/potassium/templates/application/assets/bower.json
111
115
  - lib/potassium/templates/application/assets/config/database_mysql.yml
112
116
  - lib/potassium/templates/application/assets/config/database_postgresql.yml
@@ -122,7 +126,9 @@ files:
122
126
  - lib/potassium/templates/application/helpers/variable-helpers.rb
123
127
  - lib/potassium/templates/application/recipes/admin.rb
124
128
  - lib/potassium/templates/application/recipes/angular_admin.rb
129
+ - lib/potassium/templates/application/recipes/api.rb
125
130
  - lib/potassium/templates/application/recipes/asks/admin.rb
131
+ - lib/potassium/templates/application/recipes/asks/api.rb
126
132
  - lib/potassium/templates/application/recipes/asks/database.rb
127
133
  - lib/potassium/templates/application/recipes/asks/devise.rb
128
134
  - lib/potassium/templates/application/recipes/asks/lang.rb