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.
- checksums.yaml +7 -0
- data/.rubocop.yml +45 -0
- data/CHANGELOG.rdoc +1 -0
- data/LICENSE.rdoc +21 -0
- data/README.rdoc +235 -0
- data/Rakefile +31 -0
- data/bin/hexx +54 -0
- data/lib/generators/base.rb +59 -0
- data/lib/generators/controller/controller.rb +87 -0
- data/lib/generators/controller/templates/controller.erb +18 -0
- data/lib/generators/controller/templates/controller_action.erb +8 -0
- data/lib/generators/controller/templates/controller_action_spec.erb +28 -0
- data/lib/generators/controller/templates/controller_spec.erb +52 -0
- data/lib/generators/controller/templates/routing_action_spec.erb +10 -0
- data/lib/generators/controller/templates/routing_spec.erb +10 -0
- data/lib/generators/dependency/dependency.rb +34 -0
- data/lib/generators/dependency/templates/dependency_setting.erb +4 -0
- data/lib/generators/dependency/templates/dependency_setting_spec.erb +34 -0
- data/lib/generators/dependency/templates/module_spec.erb +22 -0
- data/lib/generators/domain/domain.rb +24 -0
- data/lib/generators/domain/templates/spec.erb +84 -0
- data/lib/generators/install/install.rb +115 -0
- data/lib/generators/install/templates/CHANGELOG.erb +1 -0
- data/lib/generators/install/templates/Gemfile.erb +5 -0
- data/lib/generators/install/templates/LICENSE.erb +21 -0
- data/lib/generators/install/templates/README.erb +55 -0
- data/lib/generators/install/templates/Rakefile.erb +34 -0
- data/lib/generators/install/templates/bin/rails.erb +11 -0
- data/lib/generators/install/templates/config/routes.erb +6 -0
- data/lib/generators/install/templates/gemspec.erb +29 -0
- data/lib/generators/install/templates/lib/engine.erb +12 -0
- data/lib/generators/install/templates/lib/lib.erb +10 -0
- data/lib/generators/install/templates/lib/version.erb +4 -0
- data/lib/generators/install/templates/spec/coveralls.erb +4 -0
- data/lib/generators/install/templates/spec/database_cleaner.erb +27 -0
- data/lib/generators/install/templates/spec/factory_girl.erb +6 -0
- data/lib/generators/install/templates/spec/factory_girl_rails.erb +1 -0
- data/lib/generators/install/templates/spec/focus.erb +5 -0
- data/lib/generators/install/templates/spec/garbage_collection.erb +11 -0
- data/lib/generators/install/templates/spec/i18n.erb +1 -0
- data/lib/generators/install/templates/spec/migrations.erb +3 -0
- data/lib/generators/install/templates/spec/rails.erb +6 -0
- data/lib/generators/install/templates/spec/random_order.erb +4 -0
- data/lib/generators/install/templates/spec/rspec.erb +5 -0
- data/lib/generators/install/templates/spec/spec_helper.erb +12 -0
- data/lib/generators/install/templates/spec/timecop.erb +1 -0
- data/lib/generators/request/request.rb +52 -0
- data/lib/generators/request/templates/request_spec.erb +73 -0
- data/lib/generators/use_case/templates/use_case.erb +29 -0
- data/lib/generators/use_case/templates/use_case_spec.erb +77 -0
- data/lib/generators/use_case/use_case.rb +31 -0
- data/lib/hexx.rb +2 -0
- data/lib/hexx/exceptions/not_found_error.rb +12 -0
- data/lib/hexx/exceptions/record_invalid.rb +12 -0
- data/lib/hexx/exceptions/runtime_error.rb +24 -0
- data/lib/hexx/exceptions/use_case_invalid.rb +12 -0
- data/lib/hexx/models.rb +82 -0
- data/lib/hexx/settings.rb +47 -0
- data/lib/hexx/use_case.rb +228 -0
- data/lib/hexx/version.rb +4 -0
- data/spec/hexx/exceptions/not_found_error_spec.rb +27 -0
- data/spec/hexx/exceptions/record_invalid_spec.rb +27 -0
- data/spec/hexx/exceptions/runtime_error_spec.rb +61 -0
- data/spec/hexx/exceptions/use_case_invalid_spec.rb +27 -0
- data/spec/hexx/models_spec.rb +64 -0
- data/spec/hexx/settings_spec.rb +51 -0
- data/spec/hexx/use_case_spec.rb +262 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/initializers/coveralls.rb +3 -0
- data/spec/support/initializers/focus.rb +5 -0
- data/spec/support/initializers/garbage_collection.rb +11 -0
- data/spec/support/initializers/i18n.rb +1 -0
- data/spec/support/initializers/random_order.rb +4 -0
- data/spec/support/initializers/rspec.rb +5 -0
- metadata +236 -0
@@ -0,0 +1 @@
|
|
1
|
+
= CHANGELOG
|
@@ -0,0 +1,21 @@
|
|
1
|
+
= The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2014 Andrew Kozin, https://github.com/nepalez
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all 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,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
@@ -0,0 +1,55 @@
|
|
1
|
+
= <%= module_name %>
|
2
|
+
|
3
|
+
{<img src="http://img.shields.io/travis/nepalez/<%= gem_name %>.svg?style=flat" alt="Bild Status" />}[https://travis-ci.org/nepalez/<%= gem_name %>]
|
4
|
+
{<img src="http://img.shields.io/codeclimate/github/nepalez/<%= gem_name %>.svg?style=flat" alt="Code Metrics" />}[https://codeclimate.com/github/nepalez/<%= gem_name %>]
|
5
|
+
{<img src="http://img.shields.io/gemnasium/nepalez/<%= gem_name %>.svg?style=flat" alt="Dependency Status" />}[https://gemnasium.com/nepalez/<%= gem_name %>]
|
6
|
+
{<img src="http://img.shields.io/coveralls/nepalez/<%= gem_name %>.svg?style=flat" alt="Coverage Status" />}[https://coveralls.io/r/nepalez/<%= gem_name %>]
|
7
|
+
{<img src="http://img.shields.io/badge/license-MIT-blue.svg?style=flat" alt="License" />}[https://github.com/nepalez/<%= gem_name %>/blob/master/LICENSE.rdoc]
|
8
|
+
|
9
|
+
== About
|
10
|
+
|
11
|
+
TODO: Write a gem description
|
12
|
+
|
13
|
+
=== UseCases
|
14
|
+
|
15
|
+
<tt><%= model_name %>::DoSomething</tt>::
|
16
|
+
TODO: describe a use case.
|
17
|
+
|
18
|
+
=== Models
|
19
|
+
|
20
|
+
<tt><%= model_name %>::Something</tt>::
|
21
|
+
TODO: describe a model.
|
22
|
+
|
23
|
+
=== Dependencies
|
24
|
+
|
25
|
+
<tt><%= model_name %>.get_something_name</tt>::
|
26
|
+
TODO: describe a dependency.
|
27
|
+
|
28
|
+
== Installation
|
29
|
+
|
30
|
+
Add this line to your application's Gemfile:
|
31
|
+
|
32
|
+
gem "<%= gem_name %>"
|
33
|
+
|
34
|
+
And then execute:
|
35
|
+
|
36
|
+
$ bundle
|
37
|
+
|
38
|
+
Or install it yourself as:
|
39
|
+
|
40
|
+
$ gem install <%= gem_name %>
|
41
|
+
|
42
|
+
Then run from a command line:
|
43
|
+
|
44
|
+
$ rails g users:install
|
45
|
+
|
46
|
+
This will create a <tt>config/initializers/<%= gem_name %>.rb</tt> with module settings.
|
47
|
+
Review the file and change default values.
|
48
|
+
|
49
|
+
== Contributing
|
50
|
+
|
51
|
+
1. Fork it ( https://github.com/nepalez/<%= gem_name %>/fork )
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create a new Pull Request
|
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require "bundler/setup"
|
3
|
+
rescue LoadError
|
4
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
5
|
+
end
|
6
|
+
|
7
|
+
begin
|
8
|
+
require "rdoc/task"
|
9
|
+
rescue LoadError
|
10
|
+
require "rdoc/rdoc"
|
11
|
+
require "rake/rdoctask"
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = "rdoc"
|
17
|
+
rdoc.title = "<%= module_name %>"
|
18
|
+
rdoc.options << "--line-numbers"
|
19
|
+
rdoc.rdoc_files.include "README.rdoc"
|
20
|
+
rdoc.rdoc_files.include "lib/**/*.rb"
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path "../spec/dummy/Rakefile", __FILE__
|
24
|
+
load "rails/tasks/engine.rake"
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
28
|
+
require "bundler/gem_tasks"
|
29
|
+
require "rspec/core/rake_task"
|
30
|
+
|
31
|
+
RSpec::Core::RakeTask.new :spec
|
32
|
+
task :default do
|
33
|
+
sh "bundle exec rspec spec"
|
34
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
ENGINE_ROOT = File.expand_path "../..", __FILE__
|
4
|
+
ENGINE_PATH = File.expand_path "../../lib/<%= gem_name %>/engine", __FILE__
|
5
|
+
|
6
|
+
# Set up gems listed in the Gemfile.
|
7
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path "../../Gemfile", __FILE__
|
8
|
+
require "bundler/setup" if File.exist? ENV["BUNDLE_GEMFILE"]
|
9
|
+
|
10
|
+
require "rails/all"
|
11
|
+
require "rails/engine/commands"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "<%= gem_name %>/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "<%= gem_name %>"
|
6
|
+
s.version = <%= module_name %>::VERSION
|
7
|
+
s.author = "Andrew Kozin"
|
8
|
+
s.email = "andrew.kozin@gmail.com"
|
9
|
+
s.homepage = "https://github.com/nepalez/<%= gem_name %>"
|
10
|
+
s.summary = "TODO: Summary of <%= module_name %>."
|
11
|
+
s.description = "TODO: Description of <%= module_name %>."
|
12
|
+
s.license = "MIT"
|
13
|
+
s.platform = Gem::Platform::RUBY
|
14
|
+
s.required_ruby_version = "~> 2.1"
|
15
|
+
|
16
|
+
s.files = Dir["{app,config,db,lib}/**/*"]
|
17
|
+
s.test_files = Dir["spec/**/*", "Rakefile", ".rubocop.yml"]
|
18
|
+
s.extra_rdoc_files = Dir["CHANGELOG.rdoc", "LICENSE.rdoc", "README.rdoc"]
|
19
|
+
|
20
|
+
s.add_runtime_dependency "hexx"
|
21
|
+
s.add_runtime_dependency "rails"
|
22
|
+
|
23
|
+
s.add_development_dependency "database_cleaner"
|
24
|
+
s.add_development_dependency "factory_girl_rails"
|
25
|
+
s.add_development_dependency "rspec-rails"
|
26
|
+
s.add_development_dependency "rubocop"
|
27
|
+
s.add_development_dependency "sqlite3"
|
28
|
+
s.add_development_dependency "timecop"
|
29
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module <%= module_name %>
|
2
|
+
|
3
|
+
# Rails Engine settings
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
isolate_namespace <%= module_name %>
|
6
|
+
|
7
|
+
config.generators do |g|
|
8
|
+
g.test_framework :rspec, fixture: true, view_specs: true
|
9
|
+
g.fixture_replacement :factory_girl, dir: "spec/factories"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "database_cleaner"
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
|
5
|
+
# stop wrapping each of test examples within a transaction
|
6
|
+
config.use_transactional_fixtures = false
|
7
|
+
|
8
|
+
config.before :suite do
|
9
|
+
DatabaseCleaner.clean_with :truncation
|
10
|
+
end
|
11
|
+
|
12
|
+
config.before :each do
|
13
|
+
DatabaseCleaner.strategy = :transaction
|
14
|
+
end
|
15
|
+
|
16
|
+
config.before :each, js: true do
|
17
|
+
DatabaseCleaner.strategy = :truncation
|
18
|
+
end
|
19
|
+
|
20
|
+
config.before :each do
|
21
|
+
DatabaseCleaner.start
|
22
|
+
end
|
23
|
+
|
24
|
+
config.after :each do
|
25
|
+
DatabaseCleaner.clean
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "factory_girl_rails"
|
@@ -0,0 +1 @@
|
|
1
|
+
I18n.enforce_available_locales = false
|
@@ -0,0 +1,12 @@
|
|
1
|
+
ENV["RAILS_ENV"] ||= "test"
|
2
|
+
|
3
|
+
root = File.dirname File.dirname(__FILE__)
|
4
|
+
|
5
|
+
# Application files
|
6
|
+
require File.expand_path("../dummy/config/environment", __FILE__)
|
7
|
+
|
8
|
+
# Support files and Rspec settings
|
9
|
+
Dir[File.join(root, "spec/support/**/*.rb")].each { |file| require file }
|
10
|
+
|
11
|
+
# Factories
|
12
|
+
Dir[File.join(root, "spec/factories/**/*.rb")].each { |file| require file }
|
@@ -0,0 +1 @@
|
|
1
|
+
require "timecop"
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require_relative "../base"
|
2
|
+
|
3
|
+
module Hexx
|
4
|
+
module Generators
|
5
|
+
|
6
|
+
# Request spec (acceptance test) scaffolder.
|
7
|
+
class Request < Base
|
8
|
+
|
9
|
+
def self.source_root
|
10
|
+
super __FILE__
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_request_spec
|
14
|
+
template(
|
15
|
+
"request_spec.erb",
|
16
|
+
"spec/#{ requests_path }/#{ action_type }_#{ short_name }_spec.rb"
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# path where params changed to 1: "items/1"
|
23
|
+
def escaped_name
|
24
|
+
@escaped_name ||= full_name.gsub(/\{.+\}/, "1")
|
25
|
+
end
|
26
|
+
|
27
|
+
# underscore path: "items_id"
|
28
|
+
def short_name
|
29
|
+
@short_name ||= full_name.gsub(/[\/|\{|\}]+/, "_").gsub(/\_$/, "")
|
30
|
+
end
|
31
|
+
|
32
|
+
# full_path: "items/{id}"
|
33
|
+
def full_name
|
34
|
+
@full_name ||= parts[1]
|
35
|
+
end
|
36
|
+
|
37
|
+
# type of action: "get"
|
38
|
+
def action_type
|
39
|
+
@action_type ||= parts[0]
|
40
|
+
end
|
41
|
+
|
42
|
+
# path from the request: get:items/{id} => ["get", "items/{id}"]
|
43
|
+
def parts
|
44
|
+
@parts ||= name.split(":").map(&:downcase)
|
45
|
+
end
|
46
|
+
|
47
|
+
def requests_path
|
48
|
+
"requests/#{ gem_name }/api/v1"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module <%= module_name %>
|
4
|
+
describe "<%= action_type.upcase %> api/v1/<%= full_name %>" do
|
5
|
+
|
6
|
+
# ==========================================================================
|
7
|
+
# Prepare environment
|
8
|
+
# ==========================================================================
|
9
|
+
|
10
|
+
# before { Timecop.freeze }
|
11
|
+
# after { Timecop.return }
|
12
|
+
|
13
|
+
# ==========================================================================
|
14
|
+
# Prepare variables
|
15
|
+
# ==========================================================================
|
16
|
+
|
17
|
+
# let!(:params) { { something: something } }
|
18
|
+
|
19
|
+
# def call_request(params)
|
20
|
+
# <%= action_type %> "<%= gem_name %>/api/v1/<%= escaped_name %>", params
|
21
|
+
# end
|
22
|
+
|
23
|
+
# def check_results
|
24
|
+
# get "something", something: something
|
25
|
+
# end
|
26
|
+
|
27
|
+
# ==========================================================================
|
28
|
+
# Run tests
|
29
|
+
# ==========================================================================
|
30
|
+
|
31
|
+
# context "with proper params" do
|
32
|
+
|
33
|
+
# before { call_request params }
|
34
|
+
|
35
|
+
# it "receives a proper json response" do
|
36
|
+
# expect(response).to be_success
|
37
|
+
|
38
|
+
# json = JSON.parse(response.body)
|
39
|
+
# expect(json["success"]).to eq true
|
40
|
+
# expect(json["messages"]).not_to be_blank
|
41
|
+
# expect(json["data"]).to eq(
|
42
|
+
# "something" => something,
|
43
|
+
# )
|
44
|
+
# end
|
45
|
+
|
46
|
+
# it "changes something" do
|
47
|
+
# check_results
|
48
|
+
# json = JSON.parse(response.body)
|
49
|
+
# expect(json["data"]).to eq(something)
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
|
53
|
+
# context "with invalid params" do
|
54
|
+
#
|
55
|
+
# before { params[:something] = something }
|
56
|
+
# before { call_request params }
|
57
|
+
|
58
|
+
# it "receives a proper json response" do
|
59
|
+
# expect(response).not_to be_success
|
60
|
+
|
61
|
+
# json = JSON.parse(response.body)
|
62
|
+
# expect(json["success"]).to eq false
|
63
|
+
# expect(json["messages"]).not_to be_blank
|
64
|
+
# end
|
65
|
+
|
66
|
+
# it "doesn't change something" do
|
67
|
+
# check_results
|
68
|
+
# json = JSON.parse(response.body)
|
69
|
+
# expect(json["data"]).to eq(something)
|
70
|
+
# end
|
71
|
+
# end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module <%= module_name %>
|
2
|
+
|
3
|
+
# TODO: add a description
|
4
|
+
class <%= class_name %> < Hexx::UseCase
|
5
|
+
|
6
|
+
# Allow necessary parameters here:
|
7
|
+
# allow_params :some_parameter, :another_one
|
8
|
+
|
9
|
+
# Add case-specific validations
|
10
|
+
# validates :some_attribute, presence: true
|
11
|
+
|
12
|
+
def run!
|
13
|
+
validate!
|
14
|
+
# describe other rules here
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# Define virtual attributes to validate
|
20
|
+
# def some_attribute
|
21
|
+
# @some_attribute ||= params["some_param"]
|
22
|
+
# end
|
23
|
+
|
24
|
+
# Define custom validations
|
25
|
+
# def something_valid?
|
26
|
+
# errors.add :some_attribute, :some_key
|
27
|
+
# end
|
28
|
+
end
|
29
|
+
end
|