hexx 0.0.1

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 (75) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +45 -0
  3. data/CHANGELOG.rdoc +1 -0
  4. data/LICENSE.rdoc +21 -0
  5. data/README.rdoc +235 -0
  6. data/Rakefile +31 -0
  7. data/bin/hexx +54 -0
  8. data/lib/generators/base.rb +59 -0
  9. data/lib/generators/controller/controller.rb +87 -0
  10. data/lib/generators/controller/templates/controller.erb +18 -0
  11. data/lib/generators/controller/templates/controller_action.erb +8 -0
  12. data/lib/generators/controller/templates/controller_action_spec.erb +28 -0
  13. data/lib/generators/controller/templates/controller_spec.erb +52 -0
  14. data/lib/generators/controller/templates/routing_action_spec.erb +10 -0
  15. data/lib/generators/controller/templates/routing_spec.erb +10 -0
  16. data/lib/generators/dependency/dependency.rb +34 -0
  17. data/lib/generators/dependency/templates/dependency_setting.erb +4 -0
  18. data/lib/generators/dependency/templates/dependency_setting_spec.erb +34 -0
  19. data/lib/generators/dependency/templates/module_spec.erb +22 -0
  20. data/lib/generators/domain/domain.rb +24 -0
  21. data/lib/generators/domain/templates/spec.erb +84 -0
  22. data/lib/generators/install/install.rb +115 -0
  23. data/lib/generators/install/templates/CHANGELOG.erb +1 -0
  24. data/lib/generators/install/templates/Gemfile.erb +5 -0
  25. data/lib/generators/install/templates/LICENSE.erb +21 -0
  26. data/lib/generators/install/templates/README.erb +55 -0
  27. data/lib/generators/install/templates/Rakefile.erb +34 -0
  28. data/lib/generators/install/templates/bin/rails.erb +11 -0
  29. data/lib/generators/install/templates/config/routes.erb +6 -0
  30. data/lib/generators/install/templates/gemspec.erb +29 -0
  31. data/lib/generators/install/templates/lib/engine.erb +12 -0
  32. data/lib/generators/install/templates/lib/lib.erb +10 -0
  33. data/lib/generators/install/templates/lib/version.erb +4 -0
  34. data/lib/generators/install/templates/spec/coveralls.erb +4 -0
  35. data/lib/generators/install/templates/spec/database_cleaner.erb +27 -0
  36. data/lib/generators/install/templates/spec/factory_girl.erb +6 -0
  37. data/lib/generators/install/templates/spec/factory_girl_rails.erb +1 -0
  38. data/lib/generators/install/templates/spec/focus.erb +5 -0
  39. data/lib/generators/install/templates/spec/garbage_collection.erb +11 -0
  40. data/lib/generators/install/templates/spec/i18n.erb +1 -0
  41. data/lib/generators/install/templates/spec/migrations.erb +3 -0
  42. data/lib/generators/install/templates/spec/rails.erb +6 -0
  43. data/lib/generators/install/templates/spec/random_order.erb +4 -0
  44. data/lib/generators/install/templates/spec/rspec.erb +5 -0
  45. data/lib/generators/install/templates/spec/spec_helper.erb +12 -0
  46. data/lib/generators/install/templates/spec/timecop.erb +1 -0
  47. data/lib/generators/request/request.rb +52 -0
  48. data/lib/generators/request/templates/request_spec.erb +73 -0
  49. data/lib/generators/use_case/templates/use_case.erb +29 -0
  50. data/lib/generators/use_case/templates/use_case_spec.erb +77 -0
  51. data/lib/generators/use_case/use_case.rb +31 -0
  52. data/lib/hexx.rb +2 -0
  53. data/lib/hexx/exceptions/not_found_error.rb +12 -0
  54. data/lib/hexx/exceptions/record_invalid.rb +12 -0
  55. data/lib/hexx/exceptions/runtime_error.rb +24 -0
  56. data/lib/hexx/exceptions/use_case_invalid.rb +12 -0
  57. data/lib/hexx/models.rb +82 -0
  58. data/lib/hexx/settings.rb +47 -0
  59. data/lib/hexx/use_case.rb +228 -0
  60. data/lib/hexx/version.rb +4 -0
  61. data/spec/hexx/exceptions/not_found_error_spec.rb +27 -0
  62. data/spec/hexx/exceptions/record_invalid_spec.rb +27 -0
  63. data/spec/hexx/exceptions/runtime_error_spec.rb +61 -0
  64. data/spec/hexx/exceptions/use_case_invalid_spec.rb +27 -0
  65. data/spec/hexx/models_spec.rb +64 -0
  66. data/spec/hexx/settings_spec.rb +51 -0
  67. data/spec/hexx/use_case_spec.rb +262 -0
  68. data/spec/spec_helper.rb +3 -0
  69. data/spec/support/initializers/coveralls.rb +3 -0
  70. data/spec/support/initializers/focus.rb +5 -0
  71. data/spec/support/initializers/garbage_collection.rb +11 -0
  72. data/spec/support/initializers/i18n.rb +1 -0
  73. data/spec/support/initializers/random_order.rb +4 -0
  74. data/spec/support/initializers/rspec.rb +5 -0
  75. metadata +236 -0
@@ -0,0 +1,87 @@
1
+ require_relative "../base"
2
+
3
+ module Hexx
4
+ module Generators
5
+
6
+ # Scaffolds rails controller action and a corresponding route spec.
7
+ class Controller < Base
8
+
9
+ argument :route
10
+ argument :usecase
11
+
12
+ def self.source_root
13
+ super __FILE__
14
+ end
15
+
16
+ def create_routing_spec
17
+ template(
18
+ "routing_spec.erb",
19
+ "spec/routing/#{ api_path }/#{ file_name }_routing_spec.rb",
20
+ skip: true
21
+ )
22
+ end
23
+
24
+ def add_route_spec
25
+ inject_template_into_file(
26
+ "routing_action_spec.erb",
27
+ "spec/routing/#{ api_path }/#{ file_name }_routing_spec.rb",
28
+ before: " end\nend"
29
+ )
30
+ end
31
+
32
+ def create_controller_spec
33
+ template(
34
+ "controller_spec.erb",
35
+ "spec/controllers/#{ api_path }/#{ file_name }_controller_spec.rb",
36
+ skip: true
37
+ )
38
+ end
39
+
40
+ def add_controller_action_spec
41
+ inject_template_into_file(
42
+ "controller_action_spec.erb",
43
+ "spec/controllers/#{ api_path }/#{ file_name }_controller_spec.rb",
44
+ after: "describe \"action\" do"
45
+ )
46
+ end
47
+
48
+ def create_controller
49
+ template(
50
+ "controller.erb",
51
+ "app/controllers/#{ api_path }/#{ file_name }_controller.rb",
52
+ skip: true
53
+ )
54
+ end
55
+
56
+ def add_controller_action
57
+ inject_template_into_file(
58
+ "controller_action.erb",
59
+ "app/controllers/#{ api_path }/#{ file_name }_controller.rb",
60
+ after: " < ActionController"
61
+ )
62
+ end
63
+
64
+ private
65
+
66
+ def action_type
67
+ @action_type ||= super route
68
+ end
69
+
70
+ def action_name
71
+ @action_name ||= super route
72
+ end
73
+
74
+ def use_case
75
+ @use_case ||= usecase.camel_case
76
+ end
77
+
78
+ def use_case_file
79
+ @use_case_file ||= usecase.snake_case
80
+ end
81
+
82
+ def api_path
83
+ "#{ gem_name }/api/v1"
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,18 @@
1
+ module <%= module_name %>
2
+ module Api
3
+ module V1
4
+
5
+ # TODO: add a description
6
+ controller <%= class_name %>Controller < ActionController
7
+
8
+ # def not_found(messages)
9
+ # render json: { success: false, messages: messages }, status: 404
10
+ # end
11
+
12
+ # def error(messages)
13
+ # render json: { success: false, messages: messages }, status: 422
14
+ # end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+
2
+
3
+ # TODO: add a description
4
+ # def <%= action_name %>
5
+ # use_case = <%= use_case %>.new params.permit(:something)
6
+ # use_case.subscribe self
7
+ # use_case.run
8
+ # end
@@ -0,0 +1,28 @@
1
+
2
+
3
+ # describe "#<%= action_name %>" do
4
+ #
5
+ # let!(:params) { { "something" => something } }
6
+ # let!(:use_case_class) { <%= use_case %> }
7
+ #
8
+ # before { allow(use_case_class).to receive(:new) { use_case } }
9
+ # after { <%= action_type %> :<%= action_name %>, params }
10
+ #
11
+ # it "initializes a proper use case with allowed parameters" do
12
+ # expect(use_case_class).to receive(:new) do |options|
13
+ # expect(options).to eq params.
14
+ # slice %w(something)
15
+ # end
16
+ # end
17
+ #
18
+ # it "listens to use case notifications" do
19
+ # expect(use_case).to receive(:subscribe) do |listener|
20
+ # expect(listener).to eq controller
21
+ # end
22
+ # end
23
+ #
24
+ # it "runs the case after all subscribtion" do
25
+ # expect(use_case).to receive(:subscribe).exactly(1).times.order
26
+ # expect(use_case).to receive(:run).order
27
+ # end
28
+ # end
@@ -0,0 +1,52 @@
1
+ require "spec_helper"
2
+
3
+ module <%= module_name %>
4
+ module Api
5
+ module V1
6
+ describe <%= class_name %>Controller
7
+ # Add this string if your project is a Rails Engine, not the Application
8
+ # routes { <%= module_name %>::Engine.routes }
9
+
10
+ # let!(:use_case) { double "use_case" }
11
+ # before do
12
+ # allow(use_case).to receive(:run){ controller.render inline: "" }
13
+ # end
14
+
15
+ describe "action" do
16
+ end
17
+
18
+ describe "listener" do
19
+
20
+ # let!(:messages) { ["message"] }
21
+ # let!(:item) { { id: 1, name: "name" } }
22
+
23
+ # describe "#not_found" do
24
+ #
25
+ # it "renders a correct json" do
26
+ # expect(controller).to receive(:render) do |options|
27
+ # expect(options[:json]).to eq {
28
+ # something: something
29
+ # }
30
+ # expect(options[:status]).to eq 404
31
+ # end
32
+ # controller.not_found(messages)
33
+ # end
34
+ # end
35
+
36
+ # describe "#error" do
37
+ #
38
+ # it "renders a correct json" do
39
+ # expect(controller).to receive(:render) do |options|
40
+ # expect(options[:json]).to eq {
41
+ # something: something
42
+ # }
43
+ # expect(options[:status]).to eq 422
44
+ # end
45
+ # controller.error(messages)
46
+ # end
47
+ # end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,10 @@
1
+
2
+ # describe "#<%= action_name %>" do
3
+ #
4
+ # let!(:action) {{ controller: "<%= gem_name %>/#{ root }", action: "<%= action_name %>" }}
5
+ #
6
+ # it "is routable in a json format" do
7
+ # action[:format] = "json"
8
+ # expect(<%= action_type %>: "/#{ root }/something").to route_to action
9
+ # end
10
+ # end
@@ -0,0 +1,10 @@
1
+ require "spec_helper"
2
+
3
+ module <%= module_name %>
4
+ describe "<%= file_name %>" do
5
+ # Add this line if your project is a Rails engine, not the application:
6
+ # routes { <%= module_name %>::Engine.routes }
7
+
8
+ # let!(:root) { "api/v1/<%= file_name %>" }
9
+ end
10
+ end
@@ -0,0 +1,34 @@
1
+ require_relative "../base"
2
+
3
+ module Hexx
4
+ module Generators
5
+
6
+ # Project scaffolder
7
+ class Dependency < Base
8
+
9
+ def self.source_root
10
+ super __FILE__
11
+ end
12
+
13
+ def add_spec
14
+ template "module_spec.erb", "spec/#{ gem_name }_spec.rb", skip: true
15
+ end
16
+
17
+ def insert_setting_spec
18
+ inject_template_into_file(
19
+ "dependency_setting_spec.erb",
20
+ "spec/#{ gem_name }_spec.rb",
21
+ before: "\nend"
22
+ )
23
+ end
24
+
25
+ def insert_setting
26
+ inject_template_into_file(
27
+ "dependency_setting.erb",
28
+ "lib/#{ gem_name }.rb",
29
+ before: "\nend"
30
+ )
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,4 @@
1
+
2
+
3
+ # TODO: describe <%= file_name %>
4
+ depends_on :<%= file_name %>
@@ -0,0 +1,34 @@
1
+
2
+
3
+ # describe ".<%= file_name %>_name" do
4
+ #
5
+ # it "is public" do
6
+ # expect(subject).to respond_to(:<%= file_name %>_name).with(0).arguments
7
+ # end
8
+ # end
9
+
10
+ # describe ".<%= file_name %>" do
11
+ #
12
+ # it "is public" do
13
+ # expect(subject).to respond_to(:<%= file_name %>).with(0).arguments
14
+ # end
15
+ # end
16
+
17
+ # describe ".<%= file_name %>_name=" do
18
+ #
19
+ # after { subject.<%= file_name %>_name = nil }
20
+ #
21
+ # it "is public" do
22
+ # expect(subject).to respond_to(:<%= file_name %>_name=).with(1).argument
23
+ # end
24
+ #
25
+ # it "sets a <%= file_name %>_name" do
26
+ # expect { subject.<%= file_name %>_name = "TestClass" }
27
+ # .to change { subject.<%= file_name %>_name }.from(nil).to "TestClass"
28
+ # end
29
+ #
30
+ # it "sets a <%= file_name %>" do
31
+ # expect { subject.<%= file_name %>_name = "TestClass" }
32
+ # .to change { subject.<%= file_name %> }.from(nil).to TestClass
33
+ # end
34
+ # end
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+
3
+ describe <%= module_name %> do
4
+
5
+ before { class TestClass; end }
6
+ after { Object.send :remove_const, :TestClass }
7
+
8
+ let!(:subject) { <%= module_name %> }
9
+
10
+ # describe ".configure" do
11
+ #
12
+ # it "is public" do
13
+ # expect(subject).to respond_to(:configure).with(0).arguments
14
+ # end
15
+ #
16
+ # it "sends module to a block" do
17
+ # subject.configure do |c|
18
+ # expect(c).to eq subject
19
+ # end
20
+ # end
21
+ # end
22
+ end
@@ -0,0 +1,24 @@
1
+ require_relative "../base"
2
+
3
+ module Hexx
4
+ module Generators
5
+
6
+ # Use case scaffolder.
7
+ class Domain < Base
8
+
9
+ def self.source_root
10
+ super __FILE__
11
+ end
12
+
13
+ def add_spec
14
+ template "spec.erb", "spec/#{ domain_path }/#{ file_name }_spec.rb"
15
+ end
16
+
17
+ private
18
+
19
+ def domain_path
20
+ "domain/#{ gem_name }"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,84 @@
1
+ require "spec_helper"
2
+
3
+ module <%= module_name %>
4
+ describe "<%= class_name %>" do
5
+
6
+ # ==========================================================================
7
+ # Prepare environment
8
+ # ==========================================================================
9
+
10
+ # before do
11
+ # # Timecop.travel Time.now - 100
12
+ # # prepare initial values
13
+ # # Timecop.return
14
+ # end
15
+
16
+ # before { Timecop.freeze }
17
+ # after { Timecop.return }
18
+
19
+ # ==========================================================================
20
+ # Prepare variables
21
+ # ==========================================================================
22
+
23
+ # let!(:params) { { something: something } }
24
+ # let!(:listener) { double "listener" }
25
+
26
+ # let!(:expected_result) do
27
+ # OpenStruct.new(
28
+ # something: something
29
+ # ).inspect
30
+ # end
31
+
32
+ # ==========================================================================
33
+ # Run tests
34
+ # ==========================================================================
35
+
36
+ # context "with valid params" do
37
+
38
+ # let!(:use_case) { <%= class_name %>.new params }
39
+
40
+ # it "returns something" do
41
+ # expect(use_case.run.inspect).to eq expected_result
42
+ # end
43
+
44
+ # it "notifies listeners" do
45
+ # use_case.subscribe listener
46
+ # expect(listener).to receive(:something) do |item|
47
+ # expect(item.inspect).to eq expected_result
48
+ # end
49
+ # use_case.run
50
+ # end
51
+
52
+ # it "changes something" do
53
+ # expect { use_case.run }
54
+ # .to change { something }
55
+ # .from(something)
56
+ # .to(something)
57
+ # end
58
+ # end
59
+
60
+ # context "with invalid params" do
61
+
62
+ # before { params[:something] = something }
63
+ # let!(:use_case) { <%= class_name %>.new params }
64
+
65
+ # it "returns nil" do
66
+ # expect(use_case.run).to be_nil
67
+ # end
68
+
69
+ # it "notifies listeners" do
70
+ # use_case.subscribe listener
71
+ # expect(listener).to receive(:error) do |message|
72
+ # expect(message).not_to be_blank
73
+ # end
74
+ # use_case.run
75
+ # end
76
+
77
+ # it "doesn't change something" do
78
+ # expect { use_case.run }
79
+ # .not_to change { something }
80
+ # .from something
81
+ # end
82
+ # end
83
+ end
84
+ end
@@ -0,0 +1,115 @@
1
+ require "thor"
2
+ require "extlib"
3
+
4
+ module Hexx
5
+ module Generators
6
+
7
+ # Project scaffolder
8
+ class Install < Thor::Group
9
+ include Thor::Actions
10
+
11
+ def self.source_root
12
+ root = File.dirname File.expand_path(__FILE__)
13
+ @source_root ||= File.join(root, "templates")
14
+ end
15
+
16
+ argument :name
17
+
18
+ def remove_app
19
+ run "rm app -f -r"
20
+ end
21
+
22
+ def update_bin
23
+ template "bin/rails.erb", "bin/rails", force: true
24
+ end
25
+
26
+ def update_config
27
+ template "config/routes.erb", "config/routes.rb", force: true
28
+ run "mkdir config/locales"
29
+ end
30
+
31
+ def update_lib
32
+ template "lib/lib.erb", "lib/#{ gem_name }.rb", force: true
33
+ %w(engine version).each do |name|
34
+ template(
35
+ "lib/#{ name }.erb",
36
+ "lib/#{ gem_name }/#{ name }.rb",
37
+ force: true
38
+ )
39
+ end
40
+ end
41
+
42
+ def add_spec_helper
43
+ template(
44
+ "spec/spec_helper.erb",
45
+ "spec/spec_helper.rb",
46
+ force: true
47
+ )
48
+ end
49
+
50
+ def add_spec_initializers
51
+ run "mkdir spec/support"
52
+ run "mkdir #{ supports }"
53
+ initializers.each do |name|
54
+ template(
55
+ "spec/#{ name }.erb",
56
+ "#{ supports }/#{ name }.rb",
57
+ force: true
58
+ )
59
+ end
60
+ end
61
+
62
+ def add_services
63
+ template ".coveralls.erb", ".coveralls.yml", force: true
64
+ template ".gitignore.erb", ".gitignore", force: true
65
+ template ".rspec.erb", ".rspec", force: true
66
+ template ".rubocop.erb", ".rubocop.yml", force: true
67
+ template ".travis.erb", ".travis.yml", force: true
68
+ template "Rakefile.erb", "Rakefile", force: true
69
+ end
70
+
71
+ def add_docs
72
+ template "CHANGELOG.erb", "CHANGELOG.rdoc", force: true
73
+ run "rm MIT-LICENSE -f -r"
74
+ template "LICENSE.erb", "LICENSE.rdoc", force: true
75
+ template "README.erb", "README.rdoc", force: true
76
+ end
77
+
78
+ def update_settings
79
+ template "Gemfile.erb", "Gemfile", force: true
80
+ template(
81
+ "gemspec.erb",
82
+ "#{ gem_name }.gemspec",
83
+ force: true
84
+ )
85
+ end
86
+
87
+ def run_docs
88
+ run "subl README.rdoc" \
89
+ " lib/#{ gem_name }.rb" \
90
+ " #{ gem_name }.gemspec"
91
+ end
92
+
93
+ private
94
+
95
+ def gem_name
96
+ @gem_name ||= name.snake_case
97
+ end
98
+
99
+ def module_name
100
+ @module_name ||= name.camel_case
101
+ end
102
+
103
+ def supports
104
+ "spec/support/initializers"
105
+ end
106
+
107
+ def initializers
108
+ %w(
109
+ coveralls database_cleaner factory_girl factory_girl_rails focus
110
+ garbage_collection i18n migrations rails random_order rspec timecop
111
+ )
112
+ end
113
+ end
114
+ end
115
+ end