hexx 1.0.2 → 1.1.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
  SHA1:
3
- metadata.gz: febc0a987a8672901a8caeaec404c683655389e1
4
- data.tar.gz: 1b3ca68ec29fa8ed414710375ac82032fe4d03b1
3
+ metadata.gz: 5c91a43fe5d06b1d017e5361a82e3c6ea6fa6a82
4
+ data.tar.gz: 117f0a4bbe5433c6735d964fe1e180fda9b5a257
5
5
  SHA512:
6
- metadata.gz: 618886945f8920eee3d647fe52580d286150557e211a54b19827f0cdd4bd02ef5c6593fd7d321b632482a4941f99ee8c5f33f7d31805e9a5260317e3a7ca95fd
7
- data.tar.gz: 9ff2b732cacba20c559343f11f5e7f4dba3483c3631a9a1c53fc1974893ac49de0353701f558dec29b378757e76ad1d2d4f7cc68d214f8693af43c41b53d67fa
6
+ metadata.gz: 2e3dd4e4d761336d330861d7ec3e48a51941c5ae8400edc3f325d390deaee1549946b78e398287d1b0b2897a8bf2e1753f5bdf3afc890d57433fcf78c6d597ce
7
+ data.tar.gz: 72eedbc4ba915c1865096d77a195cbc4e96e912b57fad709cf47d3bc115cf47c00ab58e0e8a6f7a6e5deb07bceabfe835fa4f23686c54e0236e67dfd56a16691
@@ -29,6 +29,22 @@ module Hexx
29
29
  )
30
30
  end
31
31
 
32
+ def create_responder_controller_spec
33
+ template(
34
+ "responder_controller_spec.erb",
35
+ "spec/controllers/#{api_path}/responder_controller_spec.rb",
36
+ skip: true
37
+ )
38
+ end
39
+
40
+ def create_responder_controller
41
+ template(
42
+ "responder_controller.erb",
43
+ "app/controllers/#{api_path}/responder_controller.rb",
44
+ skip: true
45
+ )
46
+ end
47
+
32
48
  def create_controller_spec
33
49
  template(
34
50
  "controller_spec.erb",
@@ -41,15 +57,7 @@ module Hexx
41
57
  inject_template_into_file(
42
58
  "controller_action_spec.erb",
43
59
  "spec/controllers/#{api_path}/#{file_name}_controller_spec.rb",
44
- after: "describe \"action\" do"
45
- )
46
- end
47
-
48
- def create_responder
49
- template(
50
- "responder.erb",
51
- "app/controllers/#{api_path}/responder.rb",
52
- skip: true
60
+ before: "\n end"
53
61
  )
54
62
  end
55
63
 
@@ -65,22 +73,19 @@ module Hexx
65
73
  inject_template_into_file(
66
74
  "controller_action.erb",
67
75
  "app/controllers/#{api_path}/#{file_name}_controller.rb",
68
- after: " < Responder"
69
- )
70
- end
71
-
72
- def create_application_layout
73
- create_file(
74
- "app/views/layouts/#{api_path}/application.json.jbuilder",
75
- skip: true
76
+ before: "\n end"
76
77
  )
77
78
  end
78
79
 
79
- def create_view
80
- create_file(
81
- "app/views/#{api_path}/#{file_name}/#{action_name}.json.jbuilder",
82
- skip: true
80
+ def create_views
81
+ dir = "app/views/#{api_path}/#{file_name}"
82
+ run "mkdir #{dir} -p -v"
83
+ template "views_errors.erb", "#{ dir }/errors.json.jbuilder", skip: true
84
+ template(
85
+ "views_messages.erb", "#{ dir }/_messages.json.jbuilder", skip: true
83
86
  )
87
+ create_file "#{ dir }/#{action_name}.json.jbuilder", skip: true
88
+ create_file "#{ dir }/_#{class_name.downcase}.json.jbuilder", skip: true
84
89
  end
85
90
 
86
91
  private
@@ -3,11 +3,7 @@ module <%= module_name %>
3
3
  module V1
4
4
 
5
5
  # TODO: add a description
6
- class <%= class_name %>Controller < Responder
7
-
8
- # ======================================================================
9
- # Inner ports (to be called by use cases)
10
- # ======================================================================
6
+ class <%= class_name %>Controller < ResponderController
11
7
  end
12
8
  end
13
9
  end
@@ -1,5 +1,4 @@
1
1
 
2
-
3
2
  # TODO: add a description
4
3
  # def <%= action_name %>
5
4
  # use_case = <%= use_case %>.new params.permit(:something)
@@ -1,22 +1,21 @@
1
1
 
2
+ # describe "#<%= action_name %>" do
2
3
 
3
- # describe "#<%= action_name %>" do
4
+ # let!(:params) { { "something" => "something", "wrong" => "wrong" } }
4
5
 
5
- # let!(:params) { { "something" => "something", "wrong" => "wrong" } }
6
+ # before { allow(<%= use_case %>).to receive(:new).and_return(use_case) }
7
+ # after { <%= action_type %> :<%= action_name %>, params }
6
8
 
7
- # before { allow(<%= use_case %>).to receive(:new).and_return(use_case) }
8
- # after { <%= action_type %> :<%= action_name %>, params }
9
+ # it "sets use case with proper parameters" do
10
+ # expect(<%= use_case %>).to receive(:new)
11
+ # .with params.slice("something")
12
+ # end
9
13
 
10
- # it "sets use case with proper parameters" do
11
- # expect(<%= use_case %>).to receive(:new)
12
- # .with params.slice("something")
13
- # end
14
+ # it "listens to the case" do
15
+ # expect(controller).to listen_to use_case
16
+ # end
14
17
 
15
- # it "listens to the case" do
16
- # expect(controller).to listen_to use_case
17
- # end
18
-
19
- # it "runs the case after subscribtions" do
20
- # expect(use_case).to run_after_subscriptions
21
- # end
22
- # end
18
+ # it "runs the case after subscribtions" do
19
+ # expect(use_case).to run_after_subscriptions
20
+ # end
21
+ # end
@@ -14,50 +14,6 @@ module <%= module_name %>
14
14
  # allow(use_case).to receive(:subscribe)
15
15
  # allow(use_case).to receive(:run) { controller.render inline: "" }
16
16
  # end
17
-
18
- describe "action" do
19
- end
20
-
21
- describe "responder" do
22
-
23
- # describe "#on_error" do
24
-
25
- # controller(<%= class_name %>Controller) { def index; on_error :messages; end }
26
- # before { get :index, format: :json }
27
-
28
- # it "sets @messages" do
29
- # expect(assigns(:messages)).to eq :messages
30
- # end
31
-
32
- # it "renders 'error'" do
33
- # expect(response)
34
- # .to render_template "<%= gem_name %>/api/v1/shared/error"
35
- # end
36
-
37
- # it "responds with 400" do
38
- # expect(response.status).to eq 400
39
- # end
40
- # end
41
-
42
- # describe "#on_not_found" do
43
-
44
- # controller(<%= class_name %>Controller) { def index; on_not_found :messages; end }
45
- # before { get :index, format: :json }
46
-
47
- # it "sets @messages" do
48
- # expect(assigns(:messages)).to eq :messages
49
- # end
50
-
51
- # it "renders 'error'" do
52
- # expect(response)
53
- # .to render_template "<%= gem_name %>/api/v1/shared/error"
54
- # end
55
-
56
- # it "responds with 404" do
57
- # expect(response.status).to eq 404
58
- # end
59
- # end
60
- end
61
17
  end
62
18
  end
63
19
  end
@@ -0,0 +1,40 @@
1
+ module <%= module_name %>
2
+
3
+ # Namespace for public JSON API.
4
+ module Api
5
+
6
+ # Namespace for API v.1
7
+ module V1
8
+
9
+ # Responds to the client depending of use case result.
10
+ class ResponderController < ApplicationController
11
+
12
+ # # Renders an error messages.
13
+ # #
14
+ # # Params:
15
+ # # +messages+:: a list of messages (<tt>Hexx::Message</tt> objects)
16
+ # # to be shown to a client.
17
+ # #
18
+ # def on_error(messages, status: 400)
19
+ # @messages = messages
20
+ # render "error", status: status
21
+ # end
22
+
23
+ # # Renders an error messages and responds with 404 (Not found).
24
+ # #
25
+ # # Params:
26
+ # # +messages+:: a list of messages (<tt>Hexx::Message</tt> objects)
27
+ # # to be shown to a client.
28
+ # #
29
+ # def on_not_found(messages)
30
+ # on_error messages, status: 404
31
+ # end
32
+
33
+ # # Responds with 304 (Not changed).
34
+ # def on_not_changed
35
+ # render status: 304
36
+ # end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,65 @@
1
+ require "spec_helper"
2
+
3
+ module <%= module_name %>
4
+ module Api
5
+ module V1
6
+ describe ResponderController do
7
+
8
+ # Add this line if your project is a Rails Engine, not the Application
9
+ # routes { <%= module_name %>::Engine.routes }
10
+
11
+ # describe "#on_not_changed" do
12
+
13
+ # controller(<%= class_name %>Controller) do
14
+ # def index; on_not_changed; end
15
+ # end
16
+ # before { get :index, format: :json }
17
+
18
+ # it "responds with 304" do
19
+ # expect(response.status).to eq 304
20
+ # end
21
+ # end
22
+
23
+ # describe "#on_error" do
24
+
25
+ # controller(<%= class_name %>Controller) do
26
+ # def index; on_error :messages; end
27
+ # end
28
+ # before { get :index, format: :json }
29
+
30
+ # it "sets @messages" do
31
+ # expect(assigns(:messages)).to eq :messages
32
+ # end
33
+
34
+ # it "renders 'errors'" do
35
+ # expect(response).to render_template "errors"
36
+ # end
37
+
38
+ # it "responds with 400" do
39
+ # expect(response.status).to eq 400
40
+ # end
41
+ # end
42
+
43
+ # describe "#on_not_found" do
44
+
45
+ # controller(<%= class_name %>Controller) do
46
+ # def index; on_not_found :messages; end
47
+ # end
48
+ # before { get :index, format: :json }
49
+
50
+ # it "sets @messages" do
51
+ # expect(assigns(:messages)).to eq :messages
52
+ # end
53
+
54
+ # it "renders 'errors'" do
55
+ # expect(response).to render_template "errors"
56
+ # end
57
+
58
+ # it "responds with 404" do
59
+ # expect(response.status).to eq 404
60
+ # end
61
+ # end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,3 @@
1
+ json.messages do |json|
2
+ json.partial! "messages", messages: @messages
3
+ end
@@ -0,0 +1,3 @@
1
+ json.array! @messages do |message|
2
+ json.extract! message, :type, :text
3
+ end
@@ -25,7 +25,7 @@ module Hexx
25
25
 
26
26
  def update_config
27
27
  template "config/routes.erb", "config/routes.rb", force: true
28
- run "mkdir config/locales"
28
+ run "mkdir config/locales -p -v"
29
29
  end
30
30
 
31
31
  def update_lib
@@ -39,6 +39,11 @@ module Hexx
39
39
  end
40
40
  end
41
41
 
42
+ def add_tasks
43
+ run "mkdir lib/tasks -p -v"
44
+ template "lib/task", "lib/tasks/install.rb", force: true
45
+ end
46
+
42
47
  def add_spec_helper
43
48
  template(
44
49
  "spec/spec_helper.erb",
@@ -68,7 +73,25 @@ module Hexx
68
73
  end
69
74
 
70
75
  def add_json_schemas_path
71
- run "mkdir spec/examples/json_schemas"
76
+ run "mkdir spec/requests/json_schemas/messages -p -v"
77
+ end
78
+
79
+ def add_get_errors_json_schema
80
+ template(
81
+ "json_schemas/get_errors.erb",
82
+ "spec/requests/json_schemas/get_errors.json",
83
+ force: true
84
+ )
85
+ end
86
+
87
+ def add_messages_json_schemas
88
+ %w(error success).each do |type|
89
+ template(
90
+ "json_schemas/#{ type }.erb",
91
+ "spec/requests/json_schemas/messages/#{ type }.json",
92
+ force: true
93
+ )
94
+ end
72
95
  end
73
96
 
74
97
  def add_services
@@ -29,16 +29,17 @@ require "bundler/gem_tasks"
29
29
  require "rspec/core/rake_task"
30
30
 
31
31
  RSpec::Core::RakeTask.new :spec
32
+
32
33
  task :default do
33
- sh "mkdir spec/dummy/tmp/cache -p -v"
34
- sh "bundle exec rake db:migrate RAILS_ENV=test"
35
- sh "bundle exec rspec spec"
34
+ system "mkdir spec/dummy/tmp/cache -p -v"
35
+ system "bundle exec rake db:migrate RAILS_ENV=test"
36
+ system "bundle exec rspec spec"
36
37
  end
37
38
 
38
- task :full do
39
- sh "coveralls report"
40
- sh "rubocop"
41
- sh "metric_fu"
42
- sh "inch --pedantic"
43
- sh "rails_best_practices"
39
+ task :check do
40
+ system "coveralls report"
41
+ system "rubocop"
42
+ system "metric_fu"
43
+ system "inch --pedantic"
44
+ system "rails_best_practices"
44
45
  end
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.test_files = Dir["spec/**/*", "Rakefile", ".rubocop.yml"]
18
18
  s.extra_rdoc_files = Dir["CHANGELOG.rdoc", "LICENSE.rdoc", "README.rdoc"]
19
19
 
20
- s.add_runtime_dependency "hexx"
20
+ s.add_runtime_dependency "hexx", "~> 1.0.2"
21
21
  s.add_runtime_dependency "jbuilder"
22
22
  s.add_runtime_dependency "rails"
23
23
 
@@ -0,0 +1,14 @@
1
+ // JSON schema for an error message
2
+ {
3
+ "$schema": "http://json-schema.org/draft-04/schema#",
4
+
5
+ "type": "object",
6
+
7
+ "properties": {
8
+ "type": { "type": "string", "enum": ["error"] },
9
+ "text": { "type": "string", "minLength": 1 }
10
+ },
11
+
12
+ "additionalProperties": false,
13
+ "required": ["type", "text"]
14
+ }
@@ -0,0 +1,18 @@
1
+ // JSON schema for getting an error messages
2
+ {
3
+ "$schema": "http://json-schema.org/draft-04/schema#",
4
+
5
+ "type": "object",
6
+
7
+ "properties": {
8
+ "messages": {
9
+ "type": "array",
10
+ "items": { "$ref": "messages/error.json" },
11
+ "minimumUnits": 1,
12
+ "unique": true
13
+ }
14
+ },
15
+
16
+ "additionalProperties": false,
17
+ "required": ["messages"]
18
+ }
@@ -0,0 +1,14 @@
1
+ // JSON schema for an error message
2
+ {
3
+ "$schema": "http://json-schema.org/draft-04/schema#",
4
+
5
+ "type": "object",
6
+
7
+ "properties": {
8
+ "type": { "type": "string", "enum": ["success", "info"] },
9
+ "text": { "type": "string", "minLength": 1 }
10
+ },
11
+
12
+ "additionalProperties": false,
13
+ "required": ["type", "text"]
14
+ }
@@ -0,0 +1,60 @@
1
+ namespace :<%= gem_name %> do
2
+ namespace :install do
3
+
4
+ desc "Initializes the <%= gem_name %> gem to rails engine"
5
+ task default: %w(dependencies migrations routes)
6
+
7
+ desc "Installs the <%= gem_name %> gem dependencies"
8
+ task :dependencies do
9
+ reenable_railties
10
+ system "rake #{ app }uuids:install"
11
+ end
12
+
13
+ desc "Copies migrations from the <%= gem_name %> gem to application"
14
+ task :migrations do
15
+ reenable_railties
16
+ Rake::Task["#{ app }<%= gem_name %>:install:migrations"].invoke
17
+ end
18
+
19
+ desc "Mounts the <%= gem_name %> API routes"
20
+ task :routes do
21
+ insert_into_file(
22
+ "config/routes.rb",
23
+ before: "\nend",
24
+ line: "\n\n mount <%= module_name %>::Engine => \"/<%= gem_name %>\"",
25
+ engine: "<%= module_name %>::Engine"
26
+ ) unless engine?
27
+ end
28
+
29
+ def engine?
30
+ @engine ||= Rake::Task.task_defined?("railties:install:migrations")
31
+ end
32
+
33
+ def app
34
+ @app ||= engine? ? "" : "app:"
35
+ end
36
+
37
+ def reenable_railties
38
+ Rake::Task["#{ app }railties:install:migrations"].reenable
39
+ end
40
+
41
+ def insert_into_file(name, before:, line:, engine:)
42
+ say_with_time "mounting <%= gem_name %>' routes" do
43
+ text = File.read(name)
44
+ return if text[engine]
45
+ File.write name, text.gsub(before, line << before)
46
+ end
47
+ end
48
+
49
+ def say_with_time(text)
50
+ start = current_time
51
+ puts "=== #{ text } #{ "=" * (74 - text.count) }"
52
+ yield
53
+ puts " -> #{ (current_time - start).round(4) }s"
54
+ end
55
+
56
+ def current_time
57
+ Time.new.to_f
58
+ end
59
+ end
60
+ end
@@ -3,7 +3,7 @@ require "json-schema"
3
3
 
4
4
  RSpec::Matchers.define :match_json_schema do |schema|
5
5
  match do |response|
6
- schema_directory = "#{Dir.pwd}/spec/support/examples/json_schemas"
6
+ schema_directory = "#{Dir.pwd}/spec/requests/json_schemas"
7
7
  schema_path = "#{schema_directory}/#{schema}.json"
8
8
  JSON::Validator.validate!(schema_path, response, strict: true)
9
9
  end
data/lib/hexx/version.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  # Core classes to follow hexagonal domain architecture.
2
2
  module Hexx
3
- VERSION = "1.0.2"
3
+
4
+ # Current release.
5
+ VERSION = "1.1.0"
4
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hexx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kozin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-21 00:00:00.000000000 Z
11
+ date: 2014-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -159,9 +159,12 @@ files:
159
159
  - lib/generators/controller/templates/controller_action.erb
160
160
  - lib/generators/controller/templates/controller_action_spec.erb
161
161
  - lib/generators/controller/templates/controller_spec.erb
162
- - lib/generators/controller/templates/responder.erb
162
+ - lib/generators/controller/templates/responder_controller.erb
163
+ - lib/generators/controller/templates/responder_controller_spec.erb
163
164
  - lib/generators/controller/templates/routing_action_spec.erb
164
165
  - lib/generators/controller/templates/routing_spec.erb
166
+ - lib/generators/controller/templates/views_errors.erb
167
+ - lib/generators/controller/templates/views_messages.erb
165
168
  - lib/generators/dependency/dependency.rb
166
169
  - lib/generators/dependency/templates/dependency_setting.erb
167
170
  - lib/generators/dependency/templates/dependency_setting_spec.erb
@@ -182,8 +185,12 @@ files:
182
185
  - lib/generators/install/templates/coveralls.erb
183
186
  - lib/generators/install/templates/gemspec.erb
184
187
  - lib/generators/install/templates/gitignore.erb
188
+ - lib/generators/install/templates/json_schemas/error.erb
189
+ - lib/generators/install/templates/json_schemas/get_errors.erb
190
+ - lib/generators/install/templates/json_schemas/success.erb
185
191
  - lib/generators/install/templates/lib/engine.erb
186
192
  - lib/generators/install/templates/lib/lib.erb
193
+ - lib/generators/install/templates/lib/task.erb
187
194
  - lib/generators/install/templates/lib/version.erb
188
195
  - lib/generators/install/templates/rspec.erb
189
196
  - lib/generators/install/templates/rubocop.erb
@@ -1,23 +0,0 @@
1
- module <%= module_name %>
2
- module Api
3
- module V1
4
-
5
- # Responds to the client depending of use case result.
6
- class Responder < ::ApplicationController
7
-
8
- # def on_error(messages, status: 400)
9
- # @messages = messages
10
- # render template: "<%= gem_name %>/api/v1/shared/error", status: status
11
- # end
12
-
13
- # def on_not_found(messages)
14
- # on_error messages, status: 404
15
- # end
16
-
17
- # def on_not_changed
18
- # render status: 304
19
- # end
20
- end
21
- end
22
- end
23
- end