heks 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/heks/controller/controller_generator.rb +12 -0
- data/lib/generators/heks/model/model_generator.rb +2 -2
- data/lib/generators/heks/resource/resource_generator.rb +1 -0
- data/lib/generators/heks/templates/active_record_model.rb.erb +1 -1
- data/lib/generators/heks/templates/controller.rb.erb +39 -0
- data/lib/generators/heks/use_case/use_case_generator.rb +2 -2
- data/lib/heks/version.rb +1 -1
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/blog_post_controller.rb +40 -0
- data/test/dummy/app/controllers/blog_posts_controller.rb +39 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/hexagon/blog_post.rb +13 -0
- data/test/dummy/app/hexagon/repository/adapters/ar/blog_post.rb +36 -0
- data/test/dummy/app/hexagon/repository/adapters/ar/data/blog_post.rb +4 -0
- data/test/dummy/app/hexagon/repository/database/blog_post.rb +54 -0
- data/test/dummy/app/hexagon/repository/memory/blog_post.rb +40 -0
- data/test/dummy/app/hexagon/use_case/create_blog_post.rb +22 -0
- data/test/dummy/app/hexagon/use_case/delete_blog_post.rb +22 -0
- data/test/dummy/app/hexagon/use_case/list_blog_posts.rb +22 -0
- data/test/dummy/app/hexagon/use_case/read_blog_post.rb +22 -0
- data/test/dummy/app/hexagon/use_case/update_blog_post.rb +22 -0
- data/test/dummy/app/views/blog_posts/_form.html.erb +14 -0
- data/test/dummy/app/views/blog_posts/edit.html.erb +3 -0
- data/test/dummy/app/views/blog_posts/index.html.erb +9 -0
- data/test/dummy/app/views/blog_posts/new.html.erb +3 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20150914062943_create_blog_posts.rb +8 -0
- data/test/dummy/db/schema.rb +21 -0
- data/test/dummy/log/development.log +146 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/spec/heks/use_case/create_blog_post_spec.rb +20 -0
- data/test/dummy/spec/heks/use_case/delete_blog_post_spec.rb +20 -0
- data/test/dummy/spec/heks/use_case/list_blog_posts_spec.rb +20 -0
- data/test/dummy/spec/heks/use_case/read_blog_post_spec.rb +20 -0
- data/test/dummy/spec/heks/use_case/update_blog_post_spec.rb +20 -0
- data/test/dummy/spec/hexagon/blog_post_spec.rb +6 -0
- data/test/dummy/spec/hexagon/repository/adapters/ar/blog_post_spec.rb +0 -0
- data/test/dummy/spec/hexagon/repository/adapters/ar/data/blog_post_spec.rb +0 -0
- data/test/dummy/spec/hexagon/repository/database/blog_post_spec.rb +54 -0
- data/test/dummy/spec/hexagon/repository/memory/blog_post_spec.rb +40 -0
- data/test/dummy/spec/hexagon/use_case/create_blog_post_spec.rb +20 -0
- data/test/dummy/spec/hexagon/use_case/delete_blog_post_spec.rb +20 -0
- data/test/dummy/spec/hexagon/use_case/list_blog_posts_spec.rb +20 -0
- data/test/dummy/spec/hexagon/use_case/read_blog_post_spec.rb +20 -0
- data/test/dummy/spec/hexagon/use_case/update_blog_post_spec.rb +20 -0
- data/test/dummy/spec/models/blog_post_spec.rb +6 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/-vafv4A0l3iJF0-IyX9Uk_oQ-RIKXhPFXitPc3k4mk8.cache +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/0ieeKnMtadPClPcf7n4_-7f9dFAa5EKPn-nhh8g4E_I.cache +1 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/2zkbjbsMYCykYlg-NDKk6Qxz037f7daU6GUhcNJeqcE.cache +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/3GBybT8PfVOH8O33sovCj_2Ii8pPb5azRg64Ly9KztU.cache +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/3fB7XY5WyPu8FySUeyC372vbXJ2Ix4iB1QaNHXbk_BY.cache +1 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/5Lly_CA8DZvPhQV2jDQx-Y6P_y3Ygra9t5jfSlGhHDA.cache +2 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/EHcymtlGKlOMMf7gOs-X2_jpvcBTW92Qeaxu2B5-Wbg.cache +1 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/KtmL5zAwlZVRtKs152rC0myo3x_yBGUZYPZPMWDKtKE.cache +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/OI6uxGcnsKavdWTtwDAasU3wPx8QXhzBgV0X2n1KjMQ.cache +3 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/Pd_F3-yekB-1qnk2jHvfJ4YrXTO8oMkLujPn4EDTuUk.cache +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/SGxtd6iKmB2TMwH-VOx-jVYXh5m_09UjNEOkifPHLL0.cache +1 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/W0Q4-_MN8lFPhBVNNbwOPZB_gohXJmNGQpZF9vOfIg4.cache +1 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/hZi1k6tpxxCGYxRe7zY74ItcOI8gZrREOpGuA8JSpGg.cache +3 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/lnkATOjCZCHuHKbyGUJWM7kjxXcoUuETmbmeNSlVj1g.cache +1 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/pEhaat2KBd5SrT7szC_8R1_6hK17FTpvoRFkmCRSD3M.cache +2 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/tmdN7iRiXSHZsXbratCQqisw3N3js4ua1vCaizt_qpg.cache +1 -0
- data/test/heks_test.rb +7 -0
- data/test/test_helper.rb +20 -0
- metadata +209 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48c97ea7d9421eb5fe570b5caf23df3d5864a0b0
|
4
|
+
data.tar.gz: 02fd4803d8f68dbee4dd3eaa906e79b3eeea49ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 564d2d0e8b66b198343ecf463cc55b6319f8d650d8d6bba2c416163e9da76b70e5ebf7ac4d69aa859018acc325fdeb0998daef6a7b78bc2d1ccff2e74562d723
|
7
|
+
data.tar.gz: afdc402dc7c30d00d64d9957c483014e31486343172a510275dd8bf1d4a1b85142f9e1d4bc658c54d8b307b6ab23b147ce11153ab7864fbcc6590392ca37d79b
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module Heks
|
4
|
+
class ControllerGenerator < Rails::Generators::NamedBase
|
5
|
+
argument :fields, :type => :array
|
6
|
+
source_root File.expand_path('../../templates', __FILE__)
|
7
|
+
|
8
|
+
def copy_model_files
|
9
|
+
template "controller.rb.erb", "app/controllers/#{file_name.pluralize}_controller.rb"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -6,8 +6,8 @@ module Heks
|
|
6
6
|
argument :fields, :type => :array
|
7
7
|
|
8
8
|
def copy_model_files
|
9
|
-
template "model.rb.erb", "app/
|
10
|
-
template "model_spec.rb.erb", "spec/
|
9
|
+
template "model.rb.erb", "app/hexagon/#{file_name}.rb"
|
10
|
+
template "model_spec.rb.erb", "spec/hexagon/#{file_name}_spec.rb"
|
11
11
|
generate "heks:active_record_model", file_name
|
12
12
|
generate "heks:memory_repository", file_name
|
13
13
|
generate "heks:database_repository", file_name
|
@@ -12,6 +12,7 @@ module Heks
|
|
12
12
|
generate "heks:use_case", "update_#{file_name}", "#{file_name} update id attributes"
|
13
13
|
generate "heks:use_case", "delete_#{file_name}", "#{file_name} delete id"
|
14
14
|
generate "heks:model", file_name, fields.join(" ")
|
15
|
+
generate "heks:controller", file_name, fields.join(" ")
|
15
16
|
generate "migration", "create_#{file_name.pluralize}", fields.join(" ")
|
16
17
|
end
|
17
18
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class <%= file_name.pluralize.camelcase %>Controller < ApplicationController
|
2
|
+
before_filter -> { @command_driver = Heks::Driver.new(self) }
|
3
|
+
|
4
|
+
def index
|
5
|
+
@command_driver[:list_<%= file_name.pluralize %>].list
|
6
|
+
end
|
7
|
+
|
8
|
+
def new
|
9
|
+
@<%= file_name %> = <%= file_name.camelcase %>.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
@command_driver[:create_<%= file_name %>].create(<%= file_name %>_attributes)
|
14
|
+
end
|
15
|
+
|
16
|
+
def edit
|
17
|
+
@command_driver[:read_<%= file_name %>].read(params[:id])
|
18
|
+
end
|
19
|
+
|
20
|
+
def update
|
21
|
+
@command_driver[:update_<%= file_name %>].update(params[:id], <%= file_name %>_attributes)
|
22
|
+
end
|
23
|
+
|
24
|
+
def destroy
|
25
|
+
@command_driver[:delete_<%= file_name %>].update(params[:id], <%= file_name %>_attributes)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
listen_for(:list_<%= file_name.pluralize %>_success) { |<%= file_name.pluralize %>| @<%= file_name.pluralize %> = <%= file_name.pluralize %> }
|
31
|
+
listen_for(:create_<%= file_name %>_success) { |<%= file_name %>| redirect_to <%= file_name.pluralize %>_path }
|
32
|
+
listen_for(:update_<%= file_name %>_success) { |<%= file_name %>| redirect_to <%= file_name.pluralize %>_path }
|
33
|
+
listen_for(:read_<%= file_name %>_success) { |<%= file_name %>| @<%= file_name %> = <%= file_name %> }
|
34
|
+
listen_for(:destroy_<%= file_name %>_success){ |<%= file_name %>| redirect_to <%= file_name.pluralize %>_path }
|
35
|
+
|
36
|
+
def <%= file_name %>_attributes
|
37
|
+
params.require(:<%= file_name %>).permit(<%= Hash[*fields.flat_map{|field| field.split(":")}].keys.map{|key| ":#{key}"}.join(", ") %>)
|
38
|
+
end
|
39
|
+
end
|
@@ -9,8 +9,8 @@ module Heks
|
|
9
9
|
argument :parameters, :type => :array, :default => []
|
10
10
|
|
11
11
|
def copy_use_case_file
|
12
|
-
template "use_case.rb.erb", "app/
|
13
|
-
template "use_case_spec.rb.erb", "spec/
|
12
|
+
template "use_case.rb.erb", "app/hexagon/use_case/#{file_name}.rb"
|
13
|
+
template "use_case_spec.rb.erb", "spec/hexagon/use_case/#{file_name}_spec.rb"
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/lib/heks/version.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class BlogPostsController < ApplicationController
|
2
|
+
before_filter -> { @command_driver = Heks::Driver.new(self) }
|
3
|
+
|
4
|
+
def index
|
5
|
+
@command_driver[:list_blog_posts].list
|
6
|
+
end
|
7
|
+
|
8
|
+
def new
|
9
|
+
@blog_post = BlogPost.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
@command_driver[:create_blog_post].create(blog_post_attributes)
|
14
|
+
end
|
15
|
+
|
16
|
+
def edit
|
17
|
+
|
18
|
+
@command_driver[:read_blog_post].read(params[:id])
|
19
|
+
end
|
20
|
+
|
21
|
+
def update
|
22
|
+
@command_driver[:update_blog_post].update(params[:id], blog_post_attributes)
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy
|
26
|
+
@command_driver[:delete_blog_post].update(params[:id], blog_post_attributes)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
listen_for(:list_blog_posts_success) { |blog_posts| @blog_posts = blog_posts }
|
32
|
+
listen_for(:create_blog_post_success) { |blog_post| redirect_to blog_posts_path }
|
33
|
+
listen_for(:update_blog_post_success) { |blog_post| redirect_to blog_posts_path }
|
34
|
+
listen_for(:read_blog_post_success) { |blog_post| @blog_post = blog_post }
|
35
|
+
listen_for(:destroy_blog_post_success){ |blog_post| redirect_to blog_posts_path }
|
36
|
+
|
37
|
+
def blog_post_attributes
|
38
|
+
params.require(:blog_post).permit(:title, :body)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class BlogPostsController < ApplicationController
|
2
|
+
before_filter -> { @command_driver = Heks::Driver.new(self) }
|
3
|
+
|
4
|
+
def index
|
5
|
+
@command_driver[:list_blog_posts].list
|
6
|
+
end
|
7
|
+
|
8
|
+
def new
|
9
|
+
@blog_post = BlogPost.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
@command_driver[:create_blog_post].create(blog_post_attributes)
|
14
|
+
end
|
15
|
+
|
16
|
+
def edit
|
17
|
+
@command_driver[:read_blog_post].read(params[:id])
|
18
|
+
end
|
19
|
+
|
20
|
+
def update
|
21
|
+
@command_driver[:update_blog_post].update(params[:id], blog_post_attributes)
|
22
|
+
end
|
23
|
+
|
24
|
+
def destroy
|
25
|
+
@command_driver[:delete_blog_post].update(params[:id], blog_post_attributes)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
listen_for(:list_blog_posts_success) { |blog_posts| @blog_posts = blog_posts }
|
31
|
+
listen_for(:create_blog_post_success) { |blog_post| redirect_to blog_posts_path }
|
32
|
+
listen_for(:update_blog_post_success) { |blog_post| redirect_to blog_posts_path }
|
33
|
+
listen_for(:read_blog_post_success) { |blog_post| @blog_post = blog_post }
|
34
|
+
listen_for(:destroy_blog_post_success){ |blog_post| redirect_to blog_posts_path }
|
35
|
+
|
36
|
+
def blog_post_attributes
|
37
|
+
params.require(:blog_post).permit(:title, :body)
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Repository::Adapters::AR
|
2
|
+
class BlogPost
|
3
|
+
def initialize(listener)
|
4
|
+
@listener = listener
|
5
|
+
@data = Repository::Adapters::AR::Data::BlogPost
|
6
|
+
end
|
7
|
+
|
8
|
+
def read id
|
9
|
+
@listener.blog_post_adapter_read_success(
|
10
|
+
::BlogPost.new(@data.find(id).attributes))
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(attributes)
|
14
|
+
@listener.blog_post_adapter_create_success(
|
15
|
+
::BlogPost.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.blog_post_adapter_update_success(
|
23
|
+
::BlogPost.new(record.attributes)
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def list
|
28
|
+
@listener.blog_post_adapter_list_success(@data.all)
|
29
|
+
end
|
30
|
+
|
31
|
+
def all
|
32
|
+
@listener.blog_post_adapter_all_success(
|
33
|
+
@data.all.map {|blog_post| ::BlogPost.new(blog_post.attributes)})
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Repository
|
2
|
+
module Database
|
3
|
+
class BlogPost
|
4
|
+
def initialize(listener = nil)
|
5
|
+
@listener = listener
|
6
|
+
@adapter = Repository::Adapters::AR::BlogPost.new(self)
|
7
|
+
@model = ::BlogPost
|
8
|
+
end
|
9
|
+
|
10
|
+
def create(attributes)
|
11
|
+
@model.new(attributes).tap do |blog_post|
|
12
|
+
return unless blog_post.valid?
|
13
|
+
@adapter.create(blog_post.attributes)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def blog_post_adapter_create_success(sequence)
|
18
|
+
@listener.blog_post_repository_create_success(sequence)
|
19
|
+
end
|
20
|
+
|
21
|
+
def list
|
22
|
+
@listener.blog_post_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 blog_post_adapter_update_success(blog_post)
|
34
|
+
@listener.blog_post_repository_update_success(blog_post)
|
35
|
+
end
|
36
|
+
|
37
|
+
def first
|
38
|
+
@adapter.first
|
39
|
+
end
|
40
|
+
|
41
|
+
def blog_post_adapter_list_success(sequences)
|
42
|
+
@listener.blog_post_repository_list_success(sequences)
|
43
|
+
end
|
44
|
+
|
45
|
+
def read(id)
|
46
|
+
@adapter.read(id)
|
47
|
+
end
|
48
|
+
|
49
|
+
def blog_post_adapter_read_success(blog_post)
|
50
|
+
@listener.blog_post_repository_read_success(blog_post)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Repository
|
2
|
+
module Memory
|
3
|
+
class BlogPost
|
4
|
+
attr_accessor :listener
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@list = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def find(blog_post)
|
11
|
+
@list.first do |listed_blog_post|
|
12
|
+
blog_post == listed_blog_post
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def all
|
17
|
+
@listener.blog_post_repository_all_success(@list)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create(attributes)
|
21
|
+
::BlogPost.new(attributes).tap do |blog_post|
|
22
|
+
if blog_post.valid?
|
23
|
+
@list << blog_post
|
24
|
+
@listener.blog_post_repository_create_success(blog_post) if @listener
|
25
|
+
else
|
26
|
+
@listener.blog_post_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,22 @@
|
|
1
|
+
module UseCase
|
2
|
+
class CreateBlogPost
|
3
|
+
attr_accessor :repository_name
|
4
|
+
|
5
|
+
def initialize(listener, repository=nil)
|
6
|
+
@listener = listener
|
7
|
+
@repository = (repository || Repository::Memory::CreateBlogPost).new(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create attributes
|
11
|
+
@repository.create attributes
|
12
|
+
end
|
13
|
+
|
14
|
+
def blog_post_repository_create_success(create_blog_post)
|
15
|
+
@listener.create_blog_post_success(create_blog_post)
|
16
|
+
end
|
17
|
+
|
18
|
+
def blog_post_repository_create_failure
|
19
|
+
@listener.create_blog_post_failure
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module UseCase
|
2
|
+
class DeleteBlogPost
|
3
|
+
attr_accessor :repository_name
|
4
|
+
|
5
|
+
def initialize(listener, repository=nil)
|
6
|
+
@listener = listener
|
7
|
+
@repository = (repository || Repository::Memory::DeleteBlogPost).new(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def delete id
|
11
|
+
@repository.delete id
|
12
|
+
end
|
13
|
+
|
14
|
+
def blog_post_repository_delete_success(delete_blog_post)
|
15
|
+
@listener.delete_blog_post_success(delete_blog_post)
|
16
|
+
end
|
17
|
+
|
18
|
+
def blog_post_repository_delete_failure
|
19
|
+
@listener.delete_blog_post_failure
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module UseCase
|
2
|
+
class ListBlogPosts
|
3
|
+
attr_accessor :repository_name
|
4
|
+
|
5
|
+
def initialize(listener, repository=nil)
|
6
|
+
@listener = listener
|
7
|
+
@repository = (repository || Repository::Memory::ListBlogPosts).new(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def list
|
11
|
+
@repository.list
|
12
|
+
end
|
13
|
+
|
14
|
+
def blog_post_repository_list_success(list_blog_posts)
|
15
|
+
@listener.list_blog_posts_success(list_blog_posts)
|
16
|
+
end
|
17
|
+
|
18
|
+
def blog_post_repository_list_failure
|
19
|
+
@listener.list_blog_posts_failure
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module UseCase
|
2
|
+
class ReadBlogPost
|
3
|
+
attr_accessor :repository_name
|
4
|
+
|
5
|
+
def initialize(listener, repository=nil)
|
6
|
+
@listener = listener
|
7
|
+
@repository = (repository || Repository::Memory::ReadBlogPost).new(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def read id
|
11
|
+
@repository.read id
|
12
|
+
end
|
13
|
+
|
14
|
+
def blog_post_repository_read_success(read_blog_post)
|
15
|
+
@listener.read_blog_post_success(read_blog_post)
|
16
|
+
end
|
17
|
+
|
18
|
+
def blog_post_repository_read_failure
|
19
|
+
@listener.read_blog_post_failure
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module UseCase
|
2
|
+
class UpdateBlogPost
|
3
|
+
attr_accessor :repository_name
|
4
|
+
|
5
|
+
def initialize(listener, repository=nil)
|
6
|
+
@listener = listener
|
7
|
+
@repository = (repository || Repository::Memory::UpdateBlogPost).new(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def update id, attributes
|
11
|
+
@repository.update id, attributes
|
12
|
+
end
|
13
|
+
|
14
|
+
def blog_post_repository_update_success(update_blog_post)
|
15
|
+
@listener.update_blog_post_success(update_blog_post)
|
16
|
+
end
|
17
|
+
|
18
|
+
def blog_post_repository_update_failure
|
19
|
+
@listener.update_blog_post_failure
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
6
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
data/test/dummy/bin/rake
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
# path to your application root.
|
5
|
+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
6
|
+
|
7
|
+
Dir.chdir APP_ROOT do
|
8
|
+
# This script is a starting point to setup your application.
|
9
|
+
# Add necessary setup steps to this file:
|
10
|
+
|
11
|
+
puts "== Installing dependencies =="
|
12
|
+
system "gem install bundler --conservative"
|
13
|
+
system "bundle check || bundle install"
|
14
|
+
|
15
|
+
# puts "\n== Copying sample files =="
|
16
|
+
# unless File.exist?("config/database.yml")
|
17
|
+
# system "cp config/database.yml.sample config/database.yml"
|
18
|
+
# end
|
19
|
+
|
20
|
+
puts "\n== Preparing database =="
|
21
|
+
system "bin/rake db:setup"
|
22
|
+
|
23
|
+
puts "\n== Removing old logs and tempfiles =="
|
24
|
+
system "rm -f log/*"
|
25
|
+
system "rm -rf tmp/cache"
|
26
|
+
|
27
|
+
puts "\n== Restarting application server =="
|
28
|
+
system "touch tmp/restart.txt"
|
29
|
+
end
|