disco-railties 0.5.0.rc4 → 0.5.0.rc5

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: 363cbe23952c7e14f9fe448bd13d7cad3fbe9a0f
4
- data.tar.gz: 81451efafd0ef2b0d6cb0d2bae3b2dd611550101
3
+ metadata.gz: 6fa0988a2fd462ab708c12e956cd372b4859cf72
4
+ data.tar.gz: fafb6fb6db76a307a10f6a6cef30ae8a3f4350c9
5
5
  SHA512:
6
- metadata.gz: a40e0e8afb54f6c4292e95ba17d812c327535f838bd96c506ae53e6df910a0d12cd2bbe019c1aa3a5da2dd597e433a25330b486079f96e94a916c932872886db
7
- data.tar.gz: f80339d1425e6c52d8870e2ef8fd128daff32326e799c92ef3b5903d548b3d758723759d042a99c47c5cf014b192beef417f1c29a75c1aef506a874aa7fb1615
6
+ metadata.gz: cdb9a57f8daff86b729189a86f871f793091010b573469e7eb308e8a3204fe709c3e9815f2a6645e283f03e79e7e7687fedcd275df277f5d1f599353f85f6aa3
7
+ data.tar.gz: 206b953d09f884b9ca24a0fab684e121d9659eae5b7de12079ccd4fc56ce54c0cbce79b3a17d3275c94e1cf82b48f8e998c28cc1d841ccae7af67a62697db901
@@ -7,8 +7,21 @@ Example:
7
7
  This will create:
8
8
  bin/disco
9
9
  app/controllers/event_source_controller.rb
10
- a route for this controller
10
+ app/controllers/concerns/event_source.rb
11
+ app/helpers/event_source_helper.rb
12
+ app/assets/javascripts/event_source.js
13
+ app/assets/stylesheets/event_source.css
11
14
  config/initializers/build_validations_registry.rb
12
15
  config/initializers/create_domain.rb
16
+ config/initializers/event_source_server.rb
13
17
  config/disco.yml
18
+ app/commands/
19
+ app/events/
20
+ app/projections/
21
+ app/validations/
22
+ domain/command_processors/domain/
23
+ domain/models/domain/
24
+ domain/projections/domain/
25
+ domain/validations/domain/
26
+ adds event_source route
14
27
  adds rails-disco to your gemfile
@@ -15,6 +15,10 @@ gem 'puma'\n" unless behavior == :revoke
15
15
  def app
16
16
  super
17
17
  copy_file 'app/controllers/event_source_controller.rb'
18
+ copy_file 'app/controllers/concerns/event_source.rb'
19
+ copy_file 'app/helpers/event_source_helper.rb'
20
+ copy_file 'app/assets/javascripts/event_source.js'
21
+ copy_file 'app/assets/stylesheets/event_source.css'
18
22
  keep_file 'app/commands'
19
23
  keep_file 'app/events'
20
24
  keep_file 'app/projections'
@@ -71,7 +75,7 @@ gem 'puma'\n" unless behavior == :revoke
71
75
 
72
76
  def add_event_source_route
73
77
  return if behavior == :revoke
74
- route "get 'event_source/:projection/:event' => 'event_source#projected'"
78
+ route "get 'event_source/:projection/:event' => 'event_source#projected', as: 'event_source'"
75
79
  end
76
80
 
77
81
  def enable_rake_tasks
@@ -0,0 +1,19 @@
1
+ $(function () {
2
+ var event_source = $('.event-source[data-href]');
3
+ if (event_source.length==1 && typeof(EventSource)!=='undefined') {
4
+ var source = new EventSource(event_source.data('href'));
5
+ source.addEventListener('projected', function (e) {
6
+ window.location.reload();
7
+ });
8
+ source.addEventListener('exception', function (e) {
9
+ var d = $.parseJSON(e.data);
10
+ $('body').prepend(
11
+ $('<div class="alert alert-projection">').append(
12
+ $('<div class="message">').text(d['error']),
13
+ $('<div class="backtrace">').text(d['backtrace'].join('\n'))
14
+ )
15
+ );
16
+ source.close();
17
+ });
18
+ }
19
+ });
@@ -0,0 +1,4 @@
1
+
2
+ .alert-projection { border: solid 2px #f44; padding: 4px; }
3
+ .alert-projection .message { font-size: 200%; color: #f44; }
4
+ .alert-projection .backtrace { white-space: pre; }
@@ -0,0 +1,16 @@
1
+ module EventSource
2
+ extend ActiveSupport::Concern
3
+ EVENT_ID_KEY = :event_id
4
+
5
+ included do
6
+ helper_method :read_and_clear_event_id
7
+ end
8
+
9
+ def read_and_clear_event_id
10
+ session.delete EVENT_ID_KEY
11
+ end
12
+
13
+ def store_event_id(event_id)
14
+ session[EVENT_ID_KEY] = event_id
15
+ end
16
+ end
@@ -5,10 +5,12 @@ class EventSourceController < ApplicationController
5
5
  response.headers['Content-Type'] = 'text/event-stream'
6
6
  sse = ActiveEvent::SSE.new(response.stream)
7
7
  ActiveEvent::EventSourceServer.after_event_projection event_id, projection do
8
- sse.write(nil, event: 'projected')
8
+ sse.event('projected')
9
9
  end
10
10
  rescue IOError
11
- # ignored
11
+ # ignore disconnect
12
+ rescue ActiveEvent::ProjectionException => e
13
+ sse.event('exception', {error: e.message, backtrace: e.backtrace})
12
14
  ensure
13
15
  sse.close
14
16
  end
@@ -0,0 +1,11 @@
1
+ module EventSourceHelper
2
+ def event_source(projection)
3
+ ActiveEvent::EventSourceServer.projection_status(projection)
4
+ event_id = read_and_clear_event_id
5
+ if event_id
6
+ content_tag(:div, '',
7
+ class: 'event-source',
8
+ data: {href: event_source_path(projection: projection, event: event_id)})
9
+ end
10
+ end
11
+ end
@@ -35,12 +35,7 @@ module Disco
35
35
 
36
36
  hook_for :scaffold_controller, in: :disco, require: true do |hook|
37
37
  invoke hook
38
- add_event_stream_to_views
39
- end
40
-
41
- def copy_event_stream_client
42
- # ensure if app was created before this was default
43
- copy_file '_eventstream.js.erb', 'app/views/application/eventstream/_eventstream.js.erb', verbose: false, skip: true
38
+ add_event_source_to_views
44
39
  end
45
40
 
46
41
  protected
@@ -62,9 +57,9 @@ module Disco
62
57
  opts
63
58
  end
64
59
 
65
- def add_event_stream_to_views
60
+ def add_event_source_to_views
66
61
  return if behavior == :revoke
67
- include_text = "<%= javascript_tag render partial: 'application/eventstream/eventstream', formats: [:js], locals: {event_id: @event_id, projection: '#{class_name}Projection'} %>\n"
62
+ include_text = "<%= event_source('#{class_name}Projection') %>\n"
68
63
  prepend_to_file File.join('app/views', class_path, plural_file_name, 'index.html.erb'), include_text
69
64
  prepend_to_file File.join('app/views', class_path, plural_file_name, 'show.html.erb'), include_text
70
65
  end
@@ -4,14 +4,14 @@ require_dependency '<%= namespaced_file_path %>/application_controller'
4
4
  <% end -%>
5
5
  <% module_namespacing do -%>
6
6
  class <%= controller_class_name %>Controller < ApplicationController
7
- before_action :set_event_id, only: [:index, :show]
7
+ include EventSource
8
8
 
9
9
  def index
10
10
  @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
11
11
  end
12
12
 
13
13
  def show
14
- @<%= singular_table_name %> = <%= orm_class.find(class_name, 'params[:id]') %>
14
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, 'id_param') %>
15
15
  end
16
16
 
17
17
  def new
@@ -19,12 +19,12 @@ class <%= controller_class_name %>Controller < ApplicationController
19
19
  end
20
20
 
21
21
  def edit
22
- @<%= singular_table_name %> = <%= command_class_name('update') %>Command.new <%= orm_class.find(class_name, 'params[:id]') %>.attributes
22
+ @<%= singular_table_name %> = <%= command_class_name('update') %>Command.new <%= orm_class.find(class_name, 'id_param') %>.attributes
23
23
  end
24
24
 
25
25
  def create
26
26
  @<%= singular_table_name %> = <%= command_class_name('create') %>Command.new <%= singular_table_name %>_params
27
- if @<%= singular_table_name %>.valid? && (session[:tmp_event_id] = Domain.run_command(@<%= singular_table_name %>))
27
+ if store_event_id Domain.run_command(@<%= singular_table_name %>)
28
28
  redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %>
29
29
  else
30
30
  render action: 'new'
@@ -32,8 +32,8 @@ class <%= controller_class_name %>Controller < ApplicationController
32
32
  end
33
33
 
34
34
  def update
35
- @<%= singular_table_name %> = <%= command_class_name('update') %>Command.new <%= singular_table_name %>_params.merge(id: params[:id])
36
- if @<%= singular_table_name %>.valid? && (session[:tmp_event_id] = Domain.run_command(@<%= singular_table_name %>))
35
+ @<%= singular_table_name %> = <%= command_class_name('update') %>Command.new <%= singular_table_name %>_params.merge(id: id_param)
36
+ if store_event_id Domain.run_command(@<%= singular_table_name %>)
37
37
  redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %>
38
38
  else
39
39
  render action: 'edit'
@@ -41,12 +41,11 @@ class <%= controller_class_name %>Controller < ApplicationController
41
41
  end
42
42
 
43
43
  def destroy
44
- delete_<%= singular_table_name %> = <%= command_class_name('delete') %>Command.new(id: params[:id])
45
- session[:tmp_event_id] = event_id = Domain.run_command(delete_<%= singular_table_name %>)
46
- if event_id
44
+ delete_<%= singular_table_name %> = <%= command_class_name('delete') %>Command.new(id: id_param)
45
+ if store_event_id Domain.run_command(delete_<%= singular_table_name %>)
47
46
  redirect_to <%= index_helper %>_url, notice: <%= "'#{human_name} was successfully destroyed.'" %>
48
47
  else
49
- redirect_to <%= singular_table_name %>_url(id: params[:id]), alert: <%= "'#{human_name} could not be deleted.'" %>
48
+ redirect_to <%= singular_table_name %>_url(id: id_param), alert: <%= "'#{human_name} could not be deleted.'" %>
50
49
  end
51
50
  end
52
51
 
@@ -60,9 +59,8 @@ class <%= controller_class_name %>Controller < ApplicationController
60
59
  <%- end -%>
61
60
  end
62
61
 
63
- def set_event_id
64
- @event_id = session[:tmp_event_id]
65
- session[:tmp_event_id] = nil
62
+ def id_param
63
+ params.require(:id).to_i
66
64
  end
67
65
  end
68
66
  <% end -%>
@@ -3,7 +3,7 @@ module RailsDisco
3
3
  MAJOR = 0
4
4
  MINOR = 5
5
5
  TINY = 0
6
- PRE = "rc4"
6
+ PRE = "rc5"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: disco-railties
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.rc4
4
+ version: 0.5.0.rc5
5
5
  platform: ruby
6
6
  authors:
7
7
  - HicknHack Software
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-22 00:00:00.000000000 Z
11
+ date: 2014-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_event
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.0.rc4
19
+ version: 0.5.0.rc5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.5.0.rc4
26
+ version: 0.5.0.rc5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: active_domain
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.5.0.rc4
33
+ version: 0.5.0.rc5
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.5.0.rc4
40
+ version: 0.5.0.rc5
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: active_projection
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 0.5.0.rc4
47
+ version: 0.5.0.rc5
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 0.5.0.rc4
54
+ version: 0.5.0.rc5
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rails
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -74,67 +74,71 @@ executables:
74
74
  extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
+ - MIT-LICENSE
78
+ - Rakefile
79
+ - bin/disco
80
+ - bin/drails
77
81
  - lib/disco/app_disco_loader.rb
78
82
  - lib/disco/cli.rb
83
+ - lib/disco/commands.rb
79
84
  - lib/disco/commands/application.rb
80
85
  - lib/disco/commands/destroy.rb
81
86
  - lib/disco/commands/domainserver.rb
82
87
  - lib/disco/commands/generate.rb
83
88
  - lib/disco/commands/projectionserver.rb
84
89
  - lib/disco/commands/server.rb
85
- - lib/disco/commands.rb
86
90
  - lib/disco/generators.rb
87
91
  - lib/disco/server/domain_server.rb
88
92
  - lib/disco/server/projection_servers.rb
93
+ - lib/generators/disco/app/USAGE
89
94
  - lib/generators/disco/app/app_generator.rb
95
+ - lib/generators/disco/app/templates/app/assets/javascripts/event_source.js
96
+ - lib/generators/disco/app/templates/app/assets/stylesheets/event_source.css
97
+ - lib/generators/disco/app/templates/app/controllers/concerns/event_source.rb
90
98
  - lib/generators/disco/app/templates/app/controllers/event_source_controller.rb
99
+ - lib/generators/disco/app/templates/app/helpers/event_source_helper.rb
91
100
  - lib/generators/disco/app/templates/bin/disco
92
101
  - lib/generators/disco/app/templates/config/disco.yml
93
102
  - lib/generators/disco/app/templates/config/initializers/build_validations_registry.rb
94
103
  - lib/generators/disco/app/templates/config/initializers/create_domain.rb
95
104
  - lib/generators/disco/app/templates/config/initializers/event_source_server.rb
96
105
  - lib/generators/disco/app/templates/db/seeds.rb
97
- - lib/generators/disco/app/USAGE
106
+ - lib/generators/disco/command/USAGE
98
107
  - lib/generators/disco/command/command_generator.rb
99
108
  - lib/generators/disco/command/templates/command.rb.erb
100
109
  - lib/generators/disco/command/templates/event.rb.erb
101
- - lib/generators/disco/command/USAGE
110
+ - lib/generators/disco/command_processor/USAGE
102
111
  - lib/generators/disco/command_processor/command_processor_generator.rb
103
112
  - lib/generators/disco/command_processor/templates/command_processor.rb.erb
104
- - lib/generators/disco/command_processor/USAGE
105
113
  - lib/generators/disco/domain.rb
106
114
  - lib/generators/disco/event_name.rb
115
+ - lib/generators/disco/migration/USAGE
107
116
  - lib/generators/disco/migration/migration_generator.rb
108
117
  - lib/generators/disco/migration/templates/create_table_migration.rb
109
- - lib/generators/disco/migration/USAGE
118
+ - lib/generators/disco/model/USAGE
110
119
  - lib/generators/disco/model/model_generator.rb
111
120
  - lib/generators/disco/model/templates/domain_model.rb.erb
112
121
  - lib/generators/disco/model/templates/model.rb.erb
113
- - lib/generators/disco/model/USAGE
114
122
  - lib/generators/disco/processor_name.rb
123
+ - lib/generators/disco/projection/USAGE
115
124
  - lib/generators/disco/projection/projection_generator.rb
116
125
  - lib/generators/disco/projection/templates/domain_projection.rb
117
126
  - lib/generators/disco/projection/templates/domain_projection_test.rb
118
127
  - lib/generators/disco/projection/templates/projection.rb
119
128
  - lib/generators/disco/projection/templates/projection_test.rb
120
- - lib/generators/disco/projection/USAGE
129
+ - lib/generators/disco/scaffold/USAGE
121
130
  - lib/generators/disco/scaffold/scaffold_generator.rb
122
131
  - lib/generators/disco/scaffold/templates/_eventstream.js.erb
123
- - lib/generators/disco/scaffold/USAGE
132
+ - lib/generators/disco/scaffold_controller/USAGE
124
133
  - lib/generators/disco/scaffold_controller/scaffold_controller_generator.rb
125
134
  - lib/generators/disco/scaffold_controller/templates/controller.rb
126
135
  - lib/generators/disco/scaffold_controller/templates/controller_test.rb
127
- - lib/generators/disco/scaffold_controller/USAGE
128
136
  - lib/generators/disco/use_domain_option.rb
129
137
  - lib/rails-disco/railtie.rb
130
138
  - lib/rails-disco/tasks.rb
131
139
  - lib/rails-disco/version.rb
132
140
  - lib/tasks/db.rake
133
141
  - lib/tasks/split.rake
134
- - Rakefile
135
- - MIT-LICENSE
136
- - bin/disco
137
- - bin/drails
138
142
  homepage: https://github.com/hicknhack-software/rails-disco
139
143
  licenses:
140
144
  - MIT
@@ -155,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
159
  version: 1.3.1
156
160
  requirements: []
157
161
  rubyforge_project:
158
- rubygems_version: 2.1.11
162
+ rubygems_version: 2.2.2
159
163
  signing_key:
160
164
  specification_version: 4
161
165
  summary: Tools for working with Rails Disco