hyper-mesh 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +59 -204
  3. data/config/routes.rb +1 -1
  4. data/docs/action_cable_quickstart.md +13 -36
  5. data/docs/configuration_details.md +62 -0
  6. data/docs/pusher_faker_quickstart.md +28 -0
  7. data/docs/pusher_quickstart.md +17 -0
  8. data/docs/simple_poller_quickstart.md +5 -0
  9. data/examples/words/Gemfile +4 -3
  10. data/examples/words/Gemfile.lock +33 -32
  11. data/examples/words/app/views/components.rb +4 -2
  12. data/examples/words/config/initializers/hyper_mesh.rb +14 -0
  13. data/examples/words/config/routes.rb +1 -1
  14. data/hyper-mesh-0.4.0.gem +0 -0
  15. data/lib/hyper-mesh.rb +2 -1
  16. data/lib/hypermesh/version.rb +1 -1
  17. data/lib/reactive_record/active_record/public_columns_hash.rb +2 -2
  18. data/lib/reactive_record/active_record/reactive_record/isomorphic_base.rb +1 -1
  19. data/lib/reactive_record/engine.rb +2 -4
  20. data/lib/reactive_record/permissions.rb +30 -7
  21. data/lib/synchromesh/client_drivers.rb +3 -5
  22. data/lib/synchromesh/connection.rb +34 -8
  23. data/lib/synchromesh/synchromesh.rb +11 -7
  24. data/lib/synchromesh/synchromesh_controller.rb +9 -1
  25. data/path_release_steps.md +9 -0
  26. data/reactive_record_test_app/Gemfile +2 -1
  27. data/reactive_record_test_app/Gemfile.lock +6 -6
  28. data/reactive_record_test_app/config/application.rb +0 -1
  29. data/reactive_record_test_app/config/initializers/hyper_mesh_legacy_behavior.rb +5 -0
  30. data/reactive_record_test_app/config/routes.rb +3 -3
  31. data/spec/reactive_record/edge_cases_spec.rb +1 -1
  32. data/spec/reactive_record/many_to_many_spec.rb +1 -1
  33. data/spec/reactive_record/revert_spec.rb +1 -0
  34. data/spec/reactive_record/update_associations_spec.rb +1 -0
  35. data/spec/reactive_record/update_scopes_spec.rb +1 -0
  36. data/spec/synchromesh/crud_access_regulation/broadcast_controls_access_spec.rb +0 -6
  37. data/spec/synchromesh/crud_access_regulation/model_policies_spec.rb +8 -6
  38. data/spec/synchromesh/integration/has_many_through_spec.rb +0 -4
  39. data/spec/test_app/config/routes.rb +1 -1
  40. data/work-in-progress-drinking.png +0 -0
  41. metadata +8 -4
  42. data/examples/words/config/initializers/synchromesh.rb +0 -5
  43. data/lib/synchromesh/reactive_record/permission_patches.rb +0 -43
@@ -244,8 +244,8 @@ module HyperMesh
244
244
  prerender_footer do |controller|
245
245
  if defined?(PusherFake)
246
246
  path = ::Rails.application.routes.routes.detect do |route|
247
- route.app == ReactiveRecord::Engine ||
248
- (route.app.respond_to?(:app) && route.app.app == ReactiveRecord::Engine)
247
+ route.app == HyperMesh::Engine ||
248
+ (route.app.respond_to?(:app) && route.app.app == HyperMesh::Engine)
249
249
  end.path.spec
250
250
  pusher_fake_js = PusherFake.javascript(
251
251
  auth: { headers: { 'X-CSRF-Token' => controller.send(:form_authenticity_token) } },
@@ -277,14 +277,12 @@ module HyperMesh
277
277
  end
278
278
 
279
279
  isomorphic_method(:get_public_columns_hash) do |f|
280
- f.when_on_client { @opts[:public_columns_hash] || {} }
280
+ f.when_on_client { opts[:public_columns_hash] || {} }
281
281
  f.send_to_server
282
282
  f.when_on_server { ActiveRecord::Base.public_columns_hash }
283
283
  end
284
284
 
285
285
  def self.public_columns_hash
286
- # return {} unless @opts && @opts[:public_columns_hash]
287
- # @opts[:public_columns_hash]
288
286
  @public_columns_hash ||= get_public_columns_hash
289
287
  end
290
288
 
@@ -1,6 +1,30 @@
1
1
  module HyperMesh
2
+ module AutoCreate
3
+ def needs_init?
4
+ return true unless connection.tables.include?(table_name)
5
+ return false if HyperMesh.on_console?
6
+ return true if defined?(Rails::Server)
7
+ return true unless Connection.root_path
8
+ uri = URI("#{Connection.root_path}server_up")
9
+ http = Net::HTTP.new(uri.host, uri.port)
10
+ request = Net::HTTP::Get.new(uri.path)
11
+ if uri.scheme == 'https'
12
+ http.use_ssl = true
13
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
14
+ end
15
+ http.request(request) && return rescue true
16
+ end
17
+
18
+ def create_table(*args, &block)
19
+ connection.create_table(table_name, *args, &block) if needs_init?
20
+ end
21
+ end
22
+
2
23
  class Connection < ActiveRecord::Base
3
24
  class QueuedMessage < ActiveRecord::Base
25
+
26
+ extend AutoCreate
27
+
4
28
  self.table_name = 'synchromesh_queued_messages'
5
29
 
6
30
  do_not_synchronize
@@ -29,17 +53,17 @@ module HyperMesh
29
53
  end
30
54
  end
31
55
 
56
+ extend AutoCreate
57
+
32
58
  def self.build_tables
33
- # unless connection.tables.include? 'synchromesh_connections'
34
- connection.create_table(:synchromesh_connections, force: true) do |t|
59
+ create_table(force: true) do |t|
35
60
  t.string :channel
36
61
  t.string :session
37
62
  t.datetime :created_at
38
63
  t.datetime :expires_at
39
64
  t.datetime :refresh_at
40
65
  end
41
- # unless connection.tables.include? 'synchromesh_queued_messages'
42
- connection.create_table(:synchromesh_queued_messages, force: true) do |t|
66
+ QueuedMessage.create_table(force: true) do |t|
43
67
  t.text :data
44
68
  t.integer :connection_id
45
69
  end
@@ -80,16 +104,16 @@ module HyperMesh
80
104
  attr_accessor :transport
81
105
 
82
106
  def active
83
- expired.delete_all
84
- refresh_connections if needs_refresh?
107
+ unless HyperMesh.on_console?
108
+ expired.delete_all
109
+ refresh_connections if needs_refresh?
110
+ end
85
111
  all.pluck(:channel).uniq
86
112
  end
87
113
 
88
114
  def open(channel, session = nil, root_path = nil)
89
115
  self.root_path = root_path
90
116
  find_or_create_by(channel: channel, session: session)
91
- rescue Exception => e
92
- binding.pry
93
117
  end
94
118
 
95
119
  def send_to_channel(channel, data)
@@ -128,6 +152,8 @@ module HyperMesh
128
152
 
129
153
  def root_path
130
154
  QueuedMessage.root_path
155
+ rescue
156
+ nil
131
157
  end
132
158
 
133
159
  def refresh_connections
@@ -5,18 +5,24 @@ module HyperMesh
5
5
 
6
6
  extend Configuration
7
7
 
8
+ def self.initialize_policies
9
+ config_reset unless @config_reset_called
10
+ end
11
+
8
12
  def self.config_reset
9
- load File.join(File.dirname(__FILE__), 'reactive_record', 'permission_patches.rb')
13
+ @config_reset_called = true
10
14
  Object.send(:remove_const, :Application) if @fake_application_defined
11
15
  policy = begin
12
16
  Object.const_get 'ApplicationPolicy'
13
17
  rescue Exception => e
14
- raise e unless e.is_a?(NameError) && e.message == "uninitialized constant ApplicationPolicy"
18
+ #raise e unless e.is_a?(NameError) && e.message == "uninitialized constant ApplicationPolicy"
19
+ rescue LoadError
15
20
  end
16
21
  application = begin
17
22
  Object.const_get('Application')
23
+ rescue LoadError
18
24
  rescue Exception => e
19
- raise e unless e.is_a?(NameError) && e.message == "uninitialized constant Application"
25
+ #raise e unless e.is_a?(NameError) && e.message == "uninitialized constant Application"
20
26
  end if policy
21
27
  if policy && !application
22
28
  Object.const_set 'Application', Class.new
@@ -93,9 +99,7 @@ module HyperMesh
93
99
  end
94
100
 
95
101
  def self.on_console?
96
- defined?(Rails::Console) #&& transport == :action_cable &&
97
- #defined?(ActionCable::Server::Base) &&
98
- #ActionCable::Server::Base.config.cable['adapter'] == 'async'
102
+ defined?(Rails::Console)
99
103
  end
100
104
 
101
105
  def self.send_to_server(channel, data)
@@ -105,7 +109,7 @@ module HyperMesh
105
109
  uri = URI("#{Connection.root_path}console_update")
106
110
  http = Net::HTTP.new(uri.host, uri.port)
107
111
  request = Net::HTTP::Post.new(uri.path, 'Content-Type' => 'application/json')
108
- if uri.scheme = 'https'
112
+ if uri.scheme == 'https'
109
113
  http.use_ssl = true
110
114
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
111
115
  end
@@ -1,5 +1,6 @@
1
1
  module ReactiveRecord
2
- Engine.routes.append do
2
+ ::HyperMesh::Engine.routes.append do
3
+ HyperMesh.initialize_policies
3
4
 
4
5
  module ::WebConsole
5
6
  class Middleware
@@ -30,6 +31,7 @@ module ReactiveRecord
30
31
  end if defined?(::Rails::Rack::Logger)
31
32
 
32
33
  class HyperMeshController < ::ApplicationController
34
+
33
35
  protect_from_forgery except: [:console_update]
34
36
 
35
37
  def client_id
@@ -134,6 +136,10 @@ module ReactiveRecord
134
136
  head :unauthorized
135
137
  end
136
138
 
139
+ def server_up
140
+ head :no_content
141
+ end
142
+
137
143
  end unless defined? HyperMeshController
138
144
 
139
145
  match 'synchromesh-subscribe/:client_id/:channel',
@@ -150,5 +156,7 @@ module ReactiveRecord
150
156
  to: 'hyper_mesh#debug_console', via: :get
151
157
  match 'console_update',
152
158
  to: 'hyper_mesh#console_update', via: :post
159
+ match 'server_up',
160
+ to: 'hyper_mesh#server_up', via: :get
153
161
  end
154
162
  end
@@ -0,0 +1,9 @@
1
+
2
+ For example assuming you are releasing fix to 0.8.18
3
+
4
+ 1. Checkout 0-8-stable
5
+ 2. Update tests, fix the bug and commit the changes.
6
+ 3. Build & Release to RubyGems (Remember the version in version.rb should already be 0.8.19)
7
+ 4. Create a tag 'v0.8.19' pointing to that commit.
8
+ 5. Bump the version in 0-8-stable to 0.8.20 so it will be ready for the next patch level release.
9
+ 6. Commit the version bump, and do a `git push --tags` so the new tag goes up
@@ -10,6 +10,7 @@ gem 'byebug'
10
10
  gem 'pry-rails'
11
11
  gem 'pry-rescue'
12
12
  gem 'opal-rspec-rails', github: 'opal/opal-rspec-rails'
13
- gem 'hyper-mesh', path: "../.."
13
+ gem 'hyper-mesh', path: "../"
14
14
  gem 'web-console'
15
15
  gem 'hyper-trace'
16
+ gem 'pry'
@@ -8,13 +8,11 @@ GIT
8
8
  opal-rspec (~> 0.5.0)
9
9
 
10
10
  PATH
11
- remote: ../..
11
+ remote: ../
12
12
  specs:
13
- hyper-mesh (0.4.0)
13
+ hyper-mesh (0.5.0)
14
14
  activerecord (>= 0.3.0)
15
15
  hyper-react (>= 0.10.0)
16
- hyper-trace (0.3.1)
17
- opal
18
16
 
19
17
  GEM
20
18
  remote: http://rubygems.org/
@@ -66,7 +64,7 @@ GEM
66
64
  coderay (1.1.1)
67
65
  coffee-script-source (1.10.0)
68
66
  concurrent-ruby (1.0.2)
69
- connection_pool (2.2.0)
67
+ connection_pool (2.2.1)
70
68
  debug_inspector (0.0.2)
71
69
  erubis (2.7.0)
72
70
  execjs (2.7.0)
@@ -77,6 +75,7 @@ GEM
77
75
  opal (>= 0.8.0)
78
76
  opal-activesupport (>= 0.2.0)
79
77
  react-rails
78
+ hyper-trace (0.3.1)
80
79
  i18n (0.7.0)
81
80
  interception (0.5)
82
81
  jquery-cookie-rails (1.3.1.1)
@@ -126,7 +125,7 @@ GEM
126
125
  pry-rescue (1.4.4)
127
126
  interception (>= 0.5)
128
127
  pry
129
- rack (1.6.4)
128
+ rack (1.6.5)
130
129
  rack-test (0.6.3)
131
130
  rack (>= 1.0)
132
131
  rails (4.2.7.1)
@@ -197,6 +196,7 @@ DEPENDENCIES
197
196
  opal (~> 0.9.0)
198
197
  opal-rails
199
198
  opal-rspec-rails!
199
+ pry
200
200
  pry-rails
201
201
  pry-rescue
202
202
  rails
@@ -3,7 +3,6 @@ require File.expand_path('../boot', __FILE__)
3
3
  require 'rails/all'
4
4
 
5
5
  Bundler.require(*Rails.groups)
6
- require 'hyper-mesh'
7
6
 
8
7
  module Dummy
9
8
  class Application < Rails::Application
@@ -0,0 +1,5 @@
1
+ class ActiveRecord::Base
2
+ [:view, :create, :update, :destroy].each do |access|
3
+ define_method("#{access}_permitted?".to_sym) { |attr = nil| true }
4
+ end
5
+ end
@@ -1,7 +1,7 @@
1
1
  Rails.application.routes.draw do
2
-
2
+
3
3
  root :to => "home#index"
4
4
  match 'test', :to => "test#index", via: :get
5
- mount ReactiveRecord::Engine => "/rr"
6
-
5
+ mount HyperMesh::Engine => "/rr"
6
+
7
7
  end
@@ -9,8 +9,8 @@ describe "reactive-record edge cases", js: true do
9
9
  stub_const 'TestApplication', Class.new
10
10
  stub_const 'TestApplicationPolicy', Class.new
11
11
  TestApplicationPolicy.class_eval do
12
+ always_allow_connection
12
13
  regulate_all_broadcasts { |policy| policy.send_all }
13
- allow_change(to: :all, on: [:create, :update, :destroy]) { true }
14
14
  end
15
15
  size_window(:small, :portrait)
16
16
  end
@@ -14,8 +14,8 @@ describe "many to many associations", js: true do
14
14
  stub_const 'TestApplication', Class.new
15
15
  stub_const 'TestApplicationPolicy', Class.new
16
16
  TestApplicationPolicy.class_eval do
17
+ always_allow_connection
17
18
  regulate_all_broadcasts { |policy| policy.send_all }
18
- allow_change(to: :all, on: [:create, :update, :destroy]) { true }
19
19
  end
20
20
  size_window(:small, :portrait)
21
21
  end
@@ -15,6 +15,7 @@ RSpec::Steps.steps "reverting records", js: true do
15
15
  stub_const 'TestApplication', Class.new
16
16
  stub_const 'TestApplicationPolicy', Class.new
17
17
  TestApplicationPolicy.class_eval do
18
+ always_allow_connection
18
19
  regulate_all_broadcasts { |policy| policy.send_all }
19
20
  allow_change(to: :all, on: [:create, :update, :destroy]) { true }
20
21
  end
@@ -15,6 +15,7 @@ RSpec::Steps.steps "updating associations", js: true do
15
15
  stub_const 'TestApplication', Class.new
16
16
  stub_const 'TestApplicationPolicy', Class.new
17
17
  TestApplicationPolicy.class_eval do
18
+ always_allow_connection
18
19
  regulate_all_broadcasts { |policy| policy.send_all }
19
20
  allow_change(to: :all, on: [:create, :update, :destroy]) { true }
20
21
  end
@@ -15,6 +15,7 @@ RSpec::Steps.steps "updating scopes", js: true do
15
15
  stub_const 'TestApplication', Class.new
16
16
  stub_const 'TestApplicationPolicy', Class.new
17
17
  TestApplicationPolicy.class_eval do
18
+ always_allow_connection
18
19
  regulate_all_broadcasts { |policy| policy.send_all }
19
20
  allow_change(to: :all, on: [:create, :update, :destroy]) { true }
20
21
  end
@@ -3,12 +3,6 @@ require 'synchromesh/integration/test_components'
3
3
 
4
4
  describe "regulate access allowed" do
5
5
 
6
- before(:all) do
7
- HyperMesh.configuration do |config|
8
- config.transport = :none
9
- end
10
- end
11
-
12
6
  context "basic tests" do
13
7
  before(:each) do
14
8
  # spec_helper resets the policy system after each test so we have to setup
@@ -3,11 +3,6 @@ require 'synchromesh/integration/test_components'
3
3
 
4
4
  describe "regulate access allowed" do
5
5
 
6
- before(:all) do
7
- HyperMesh.configuration do |config|
8
- config.transport = :none
9
- end
10
- end
11
6
 
12
7
  before(:each) do
13
8
  stub_const 'DummyModel', Class.new(ActiveRecord::Base)
@@ -17,7 +12,14 @@ describe "regulate access allowed" do
17
12
  end
18
13
 
19
14
  after(:each) do
20
- load 'lib/synchromesh/reactive_record/permission_patches.rb'
15
+ class ActiveRecord::Base
16
+ def view_permitted?(attribute)
17
+ HyperMesh::InternalPolicy.accessible_attributes_for(self, acting_user).include? attribute.to_sym
18
+ end
19
+ [:create, :update, :destroy].each do |access|
20
+ define_method("#{access}_permitted?".to_sym) { false }
21
+ end
22
+ end
21
23
  end
22
24
 
23
25
  HyperMesh::InternalClassPolicy::CHANGE_POLICIES.each do |policy|
@@ -158,10 +158,6 @@ RSpec::Steps.steps "has_many through relationships", js: true do
158
158
  end
159
159
 
160
160
  it "can destroy an existing relationship from the server" do
161
- evaluate_ruby do
162
- PhysicianSchedule.hypertrace instrument: :all
163
- ReactiveRecord::Base.hypertrace instrument: :all
164
- end
165
161
  @a1.destroy
166
162
  page.should have_content("Dr. Stop has a total of 1 appointments with: B. Legg")
167
163
  page.should have_content("Dr. Faith has no appointments.")
@@ -1,7 +1,7 @@
1
1
  require 'hyper-mesh'
2
2
 
3
3
  Rails.application.routes.draw do
4
- mount ReactiveRecord::Engine => "/rr"
4
+ mount HyperMesh::Engine => "/rr"
5
5
  # The priority is based upon order of creation: first created -> highest priority.
6
6
  # See how all your routes lay out with "rake routes".
7
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyper-mesh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitch VanDuyn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-11 00:00:00.000000000 Z
11
+ date: 2016-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -600,6 +600,8 @@ files:
600
600
  - docs/action_cable_quickstart.md
601
601
  - docs/authorization-policies.md
602
602
  - docs/client_side_scoping.md
603
+ - docs/configuration_details.md
604
+ - docs/pusher_faker_quickstart.md
603
605
  - docs/pusher_quickstart.md
604
606
  - docs/simple_poller_quickstart.md
605
607
  - docs/todo-example.md
@@ -794,11 +796,11 @@ files:
794
796
  - examples/words/config/initializers/backtrace_silencers.rb
795
797
  - examples/words/config/initializers/cookies_serializer.rb
796
798
  - examples/words/config/initializers/filter_parameter_logging.rb
799
+ - examples/words/config/initializers/hyper_mesh.rb
797
800
  - examples/words/config/initializers/inflections.rb
798
801
  - examples/words/config/initializers/mime_types.rb
799
802
  - examples/words/config/initializers/new_framework_defaults.rb
800
803
  - examples/words/config/initializers/session_store.rb
801
- - examples/words/config/initializers/synchromesh.rb
802
804
  - examples/words/config/initializers/wrap_parameters.rb
803
805
  - examples/words/config/locales/en.yml
804
806
  - examples/words/config/puma.rb
@@ -818,6 +820,7 @@ files:
818
820
  - examples/words/tmp/.keep
819
821
  - examples/words/vendor/assets/javascripts/.keep
820
822
  - examples/words/vendor/assets/stylesheets/.keep
823
+ - hyper-mesh-0.4.0.gem
821
824
  - hyper-mesh.gemspec
822
825
  - lib/active_record_base.rb
823
826
  - lib/enumerable/pluck.rb
@@ -857,7 +860,6 @@ files:
857
860
  - lib/synchromesh/configuration.rb
858
861
  - lib/synchromesh/connection.rb
859
862
  - lib/synchromesh/policy.rb
860
- - lib/synchromesh/reactive_record/permission_patches.rb
861
863
  - lib/synchromesh/synchromesh.rb
862
864
  - lib/synchromesh/synchromesh_controller.rb
863
865
  - logo.jpg
@@ -901,6 +903,7 @@ files:
901
903
  - reactive_record_test_app/config/environments/production.rb
902
904
  - reactive_record_test_app/config/environments/test.rb
903
905
  - reactive_record_test_app/config/initializers/backtrace_silencers.rb
906
+ - reactive_record_test_app/config/initializers/hyper_mesh_legacy_behavior.rb
904
907
  - reactive_record_test_app/config/initializers/inflections.rb
905
908
  - reactive_record_test_app/config/initializers/mime_types.rb
906
909
  - reactive_record_test_app/config/initializers/secret_token.rb
@@ -1049,6 +1052,7 @@ files:
1049
1052
  - spec/test_app/public/favicon.ico
1050
1053
  - spec/vendor/es5-shim.min.js
1051
1054
  - terminal.md
1055
+ - work-in-progress-drinking.png
1052
1056
  homepage: https://github.com/reactive-ruby/hyper-mesh
1053
1057
  licenses:
1054
1058
  - MIT