heks 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +34 -0
  4. data/lib/generators/heks/active_record_model/active_record_model_generator.rb +10 -0
  5. data/lib/generators/heks/database_adapter/database_adapter_generator.rb +12 -0
  6. data/lib/generators/heks/database_repository/database_repository_generator.rb +12 -0
  7. data/lib/generators/heks/memory_repository/memory_repository_generator.rb +12 -0
  8. data/lib/generators/heks/model/model_generator.rb +17 -0
  9. data/lib/generators/heks/resource/resource_generator.rb +18 -0
  10. data/lib/generators/heks/templates/active_record_model.rb.erb +4 -0
  11. data/lib/generators/heks/templates/active_record_model_spec.rb.erb +0 -0
  12. data/lib/generators/heks/templates/database_adapter.rb.erb +36 -0
  13. data/lib/generators/heks/templates/database_adapter_spec.rb.erb +0 -0
  14. data/lib/generators/heks/templates/database_repository.rb.erb +54 -0
  15. data/lib/generators/heks/templates/database_repository_spec.rb.erb +0 -0
  16. data/lib/generators/heks/templates/memory_repository.rb.erb +40 -0
  17. data/lib/generators/heks/templates/memory_repository_spec.rb.erb +0 -0
  18. data/lib/generators/heks/templates/model.rb.erb +13 -0
  19. data/lib/generators/heks/templates/model_spec.rb.erb +6 -0
  20. data/lib/generators/heks/templates/repository_adapter_spec.rb.erb +6 -0
  21. data/lib/generators/heks/templates/repository_database_spec.rb.erb +5 -0
  22. data/lib/generators/heks/templates/repository_memory_spec.rb.erb +31 -0
  23. data/lib/generators/heks/templates/use_case.rb.erb +22 -0
  24. data/lib/generators/heks/templates/use_case_spec.rb.erb +20 -0
  25. data/lib/generators/heks/use_case/USAGE +8 -0
  26. data/lib/generators/heks/use_case/use_case_generator.rb +16 -0
  27. data/lib/heks.rb +4 -0
  28. data/lib/heks/action_controller/base.rb +11 -0
  29. data/lib/heks/driver.rb +18 -0
  30. data/lib/heks/version.rb +3 -0
  31. data/lib/tasks/heks_tasks.rake +4 -0
  32. data/test/dummy/README.rdoc +28 -0
  33. data/test/dummy/Rakefile +6 -0
  34. data/test/dummy/app/assets/javascripts/application.js +13 -0
  35. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  36. data/test/dummy/app/controllers/application_controller.rb +5 -0
  37. data/test/dummy/app/helpers/application_helper.rb +2 -0
  38. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  39. data/test/dummy/bin/bundle +3 -0
  40. data/test/dummy/bin/rails +4 -0
  41. data/test/dummy/bin/rake +4 -0
  42. data/test/dummy/bin/setup +29 -0
  43. data/test/dummy/config.ru +4 -0
  44. data/test/dummy/config/application.rb +26 -0
  45. data/test/dummy/config/boot.rb +5 -0
  46. data/test/dummy/config/database.yml +25 -0
  47. data/test/dummy/config/environment.rb +5 -0
  48. data/test/dummy/config/environments/development.rb +41 -0
  49. data/test/dummy/config/environments/production.rb +79 -0
  50. data/test/dummy/config/environments/test.rb +42 -0
  51. data/test/dummy/config/initializers/assets.rb +11 -0
  52. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  53. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  54. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  55. data/test/dummy/config/initializers/inflections.rb +16 -0
  56. data/test/dummy/config/initializers/mime_types.rb +4 -0
  57. data/test/dummy/config/initializers/session_store.rb +3 -0
  58. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  59. data/test/dummy/config/locales/en.yml +23 -0
  60. data/test/dummy/config/routes.rb +56 -0
  61. data/test/dummy/config/secrets.yml +22 -0
  62. data/test/dummy/public/404.html +67 -0
  63. data/test/dummy/public/422.html +67 -0
  64. data/test/dummy/public/500.html +66 -0
  65. data/test/dummy/public/favicon.ico +0 -0
  66. data/test/heks_test.rb +7 -0
  67. data/test/test_helper.rb +20 -0
  68. metadata +180 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b61adf8a4a3c2e92351abafe7e6100bdc3560b56
4
+ data.tar.gz: d9759beb061de2bcd84597727bdebfcc156bc5da
5
+ SHA512:
6
+ metadata.gz: 0afefefc37dee6260111f8747c2ec84cb71fc26d58d6d6eeebe9127099baddc0bad40dc6bf8ca0ed754d8e0be34032d3370842cab19e562352b2f2cff99a1b41
7
+ data.tar.gz: 496affea27df42a2e35551f295e4664b1aaeb80d2c273025c485f3da0981d64188769c3162a7b817083a0d0bc43e709148d3cda778163325efcf695240174f9e
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Chris Young
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -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
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Heks'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,10 @@
1
+ module Heks
2
+ class ActiveRecordModelGenerator < Rails::Generators::NamedBase
3
+ source_root File.expand_path('../../templates', __FILE__)
4
+
5
+ def copy_model_files
6
+ template "active_record_model.rb.erb", "app/hexagon/repository/adapters/ar/data/#{file_name}.rb"
7
+ template "active_record_model_spec.rb.erb", "spec/hexagon/repository/adapters/ar/data/#{file_name}_spec.rb"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ require 'rails/generators/base'
2
+
3
+ module Heks
4
+ class DatabaseAdapterGenerator < Rails::Generators::NamedBase
5
+ source_root File.expand_path('../../templates', __FILE__)
6
+
7
+ def copy_model_files
8
+ template "database_adapter.rb.erb", "app/hexagon/repository/adapters/ar/#{file_name}.rb"
9
+ template "database_adapter_spec.rb.erb", "spec/hexagon/repository/adapters/ar/#{file_name}_spec.rb"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'rails/generators/base'
2
+
3
+ module Heks
4
+ class DatabaseRepositoryGenerator < Rails::Generators::NamedBase
5
+ source_root File.expand_path('../../templates', __FILE__)
6
+
7
+ def copy_model_files
8
+ template "database_repository.rb.erb", "app/hexagon/repository/database/#{file_name}.rb"
9
+ template "database_repository.rb.erb", "spec/hexagon/repository/database/#{file_name}_spec.rb"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'rails/generators/base'
2
+
3
+ module Heks
4
+ class MemoryRepositoryGenerator < Rails::Generators::NamedBase
5
+ source_root File.expand_path('../../templates', __FILE__)
6
+
7
+ def copy_model_files
8
+ template "memory_repository.rb.erb", "app/hexagon/repository/memory/#{file_name}.rb"
9
+ template "memory_repository.rb.erb", "spec/hexagon/repository/memory/#{file_name}_spec.rb"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ require 'rails/generators/base'
2
+
3
+ module Heks
4
+ class ModelGenerator < Rails::Generators::NamedBase
5
+ source_root File.expand_path('../../templates', __FILE__)
6
+ argument :fields, :type => :array
7
+
8
+ def copy_model_files
9
+ template "model.rb.erb", "app/models/#{file_name}.rb"
10
+ template "model_spec.rb.erb", "spec/models/#{file_name}_spec.rb"
11
+ generate "heks:active_record_model", file_name
12
+ generate "heks:memory_repository", file_name
13
+ generate "heks:database_repository", file_name
14
+ generate "heks:database_adapter", file_name
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ require 'rails/generators/base'
2
+
3
+ module Heks
4
+ class ResourceGenerator < Rails::Generators::NamedBase
5
+ source_root File.expand_path('../../templates', __FILE__)
6
+ argument :fields, :type => :array
7
+
8
+ def make_files
9
+ generate "heks:use_case", "list_#{file_name.pluralize}", "#{file_name} list"
10
+ generate "heks:use_case", "create_#{file_name}", "#{file_name} create attributes"
11
+ generate "heks:use_case", "read_#{file_name}", "#{file_name} read id"
12
+ generate "heks:use_case", "update_#{file_name}", "#{file_name} update id attributes"
13
+ generate "heks:use_case", "delete_#{file_name}", "#{file_name} delete id"
14
+ generate "heks:model", file_name, fields.join(" ")
15
+ generate "migration", "create_#{file_name.pluralize}", fields.join(" ")
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ module Repository::Adapters::AR::Data
2
+ class <%= file_name.camelize %> < ActiveRecord::Base
3
+ end
4
+ end
@@ -0,0 +1,36 @@
1
+ module Repository::Adapters::AR
2
+ class <%= file_name.camelize %>
3
+ def initialize(listener)
4
+ @listener = listener
5
+ @data = Repository::Adapters::AR::Data::<%= file_name.camelize %>
6
+ end
7
+
8
+ def read id
9
+ @listener.<%= file_name %>_adapter_read_success(
10
+ ::<%= file_name.camelize %>.new(@data.find(id).attributes))
11
+ end
12
+
13
+ def create(attributes)
14
+ @listener.<%= file_name %>_adapter_create_success(
15
+ ::<%= file_name.camelize %>.new(@data.create(attributes).attributes))
16
+ end
17
+
18
+ def update(id, attributes)
19
+ record = @data.find(id)
20
+ record.update_attributes(attributes)
21
+
22
+ @listener.<%= file_name %>_adapter_update_success(
23
+ ::<%= file_name.camelize %>.new(record.attributes)
24
+ )
25
+ end
26
+
27
+ def list
28
+ @listener.<%= file_name %>_adapter_list_success(@data.all)
29
+ end
30
+
31
+ def all
32
+ @listener.<%= file_name %>_adapter_all_success(
33
+ @data.all.map {|<%= file_name %>| ::<%= file_name.camelize %>.new(<%= file_name %>.attributes)})
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,54 @@
1
+ module Repository
2
+ module Database
3
+ class <%= file_name.camelize %>
4
+ def initialize(listener = nil)
5
+ @listener = listener
6
+ @adapter = Repository::Adapters::AR::<%= file_name.camelize %>.new(self)
7
+ @model = ::<%= file_name.camelize %>
8
+ end
9
+
10
+ def create(attributes)
11
+ @model.new(attributes).tap do |<%= file_name %>|
12
+ return unless <%= file_name %>.valid?
13
+ @adapter.create(<%= file_name %>.attributes)
14
+ end
15
+ end
16
+
17
+ def <%= file_name %>_adapter_create_success(sequence)
18
+ @listener.<%= file_name %>_repository_create_success(sequence)
19
+ end
20
+
21
+ def list
22
+ @listener.<%= file_name %>_repository_list_success(@adapter.list)
23
+ end
24
+
25
+ def count
26
+ @model.count
27
+ end
28
+
29
+ def update(id, attributes)
30
+ @adapter.update(id, attributes)
31
+ end
32
+
33
+ def <%= file_name %>_adapter_update_success(<%= file_name %>)
34
+ @listener.<%= file_name %>_repository_update_success(<%= file_name %>)
35
+ end
36
+
37
+ def first
38
+ @adapter.first
39
+ end
40
+
41
+ def <%= file_name %>_adapter_list_success(sequences)
42
+ @listener.<%= file_name %>_repository_list_success(sequences)
43
+ end
44
+
45
+ def read(id)
46
+ @adapter.read(id)
47
+ end
48
+
49
+ def <%= file_name %>_adapter_read_success(<%= file_name %>)
50
+ @listener.<%= file_name %>_repository_read_success(<%= file_name %>)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,40 @@
1
+ module Repository
2
+ module Memory
3
+ class <%= file_name.camelize %>
4
+ attr_accessor :listener
5
+
6
+ def initialize
7
+ @list = []
8
+ end
9
+
10
+ def find(<%= file_name %>)
11
+ @list.first do |listed_<%= file_name %>|
12
+ <%= file_name %> == listed_<%= file_name %>
13
+ end
14
+ end
15
+
16
+ def all
17
+ @listener.<%= file_name %>_repository_all_success(@list)
18
+ end
19
+
20
+ def create(attributes)
21
+ ::<%= file_name.camelize %>.new(attributes).tap do |<%= file_name %>|
22
+ if <%= file_name %>.valid?
23
+ @list << <%= file_name %>
24
+ @listener.<%= file_name %>_repository_create_success(<%= file_name %>) if @listener
25
+ else
26
+ @listener.<%= file_name %>_repository_create_failure if @listener
27
+ end
28
+ end
29
+ end
30
+
31
+ def count
32
+ @list.count
33
+ end
34
+
35
+ def first
36
+ @list.first
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,13 @@
1
+ class <%= file_name.camelize %>
2
+ include ActiveModel::Model
3
+ attr_accessor :attributes, :id, <%= Hash[*fields.flat_map{|field| field.split(":")}].keys.map{|key| ":#{key}"}.join(", ") %>
4
+
5
+ def initialize(attributes={})
6
+ @attributes = attributes
7
+ super(attributes)
8
+ end
9
+
10
+ def persisted?
11
+ id.present?
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ require 'rails_helper'
2
+
3
+ describe <%= file_name.camelize %> do
4
+ let(:attributes) {{}}
5
+ subject { <%= file_name.camelize %>.new(attributes) }
6
+ end
@@ -0,0 +1,6 @@
1
+ require 'rails_helper'
2
+
3
+ describe Repository::Adapters::AR::<%= repository_name.camelize %> do
4
+ it "needs specs"
5
+ end
6
+
@@ -0,0 +1,5 @@
1
+ require 'rails_helper'
2
+
3
+ describe Repository::Database::<%= repository_name.titleize.camelize %> do
4
+ it "needs specs"
5
+ end
@@ -0,0 +1,31 @@
1
+ require 'rails_helper'
2
+
3
+ describe Repository::Memory::<%= repository_name.camelize %> do
4
+
5
+ subject { described_class.new(listener) }
6
+
7
+ let(:listener) { double('subject_listener', repository_create_<%= repository_name %>_success: nil) }
8
+
9
+ describe '.create' do
10
+ it 'notifies listener of success'
11
+ end
12
+
13
+ describe '.read' do
14
+ it 'notifies listener of success'
15
+ end
16
+
17
+ describe '.update' do
18
+ it 'notifies listener of success'
19
+ end
20
+
21
+ describe '.delete' do
22
+ it 'notifies listener of success'
23
+ end
24
+
25
+ describe '.count' do
26
+ it 'returns a count of <%= repository_name %>' do
27
+ # subject.create()
28
+ # expect(subject.count).to eq 1
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,22 @@
1
+ module UseCase
2
+ class <%= file_name.camelize %>
3
+ attr_accessor :repository_name
4
+
5
+ def initialize(listener, repository=nil)
6
+ @listener = listener
7
+ @repository = (repository || Repository::Memory::<%= file_name.camelize %>).new(self)
8
+ end
9
+
10
+ def <%= file_name.split('_').first %> <%= parameters.join(", ") %>
11
+ @repository.<%= repository_action %> <%= parameters.join(", ") %>
12
+ end
13
+
14
+ def <%= repository_name %>_repository_<%= repository_action %>_success(<%= file_name %>)
15
+ @listener.<%= file_name %>_success(<%= file_name %>)
16
+ end
17
+
18
+ def <%= repository_name %>_repository_<%= repository_action %>_failure
19
+ @listener.<%= file_name %>_failure
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ require 'rails_helper'
2
+
3
+ describe UseCase::<%= file_name.camelize %> do
4
+ describe '<%= file_name.split("_").first %>' do
5
+ subject { described_class.new(listener, Repository::Memory::<%= file_name.titleize %>.new) }
6
+ let (:listener) { double("<%= file_name %> listener", <%= file_name %>_success: nil, <%= file_name %>_failure: nil) }
7
+ let (:repository) { subject.repository }
8
+
9
+ context "With Valid Properties" do
10
+ it 'notifies listener of success' do
11
+ expect(listener).to receive(:<%= file_name %>_success)
12
+ subject.<%= file_name.split("_").first %>()
13
+ end
14
+ end
15
+
16
+ context "With Invalid Properties" do
17
+ it 'notifies the listener of failure'
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate use_case Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,16 @@
1
+ require 'rails/generators/base'
2
+
3
+ module Heks
4
+ class UseCaseGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../../templates', __FILE__)
6
+ argument :file_name, :type => :string
7
+ argument :repository_name, :type => :string
8
+ argument :repository_action, :type => :string
9
+ argument :parameters, :type => :array, :default => []
10
+
11
+ def copy_use_case_file
12
+ template "use_case.rb.erb", "app/heks/use_case/#{file_name}.rb"
13
+ template "use_case_spec.rb.erb", "spec/heks/use_case/#{file_name}_spec.rb"
14
+ end
15
+ end
16
+ end