hyper-mesh 0.5.2 → 0.5.3

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.
Files changed (203) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +34 -0
  3. data/README.md +10 -11
  4. data/docs/activerecord_api.md +55 -39
  5. data/docs/authorization-policies.md +62 -19
  6. data/docs/client_side_scoping.md +1 -1
  7. data/docs/word_game.md +26 -0
  8. data/examples/action-cable-production-mode/.gitignore +21 -0
  9. data/examples/action-cable-production-mode/Gemfile +57 -0
  10. data/examples/action-cable-production-mode/Gemfile.lock +231 -0
  11. data/examples/action-cable-production-mode/README.md +24 -0
  12. data/examples/action-cable-production-mode/Rakefile +6 -0
  13. data/examples/action-cable-production-mode/app/assets/config/manifest.js +3 -0
  14. data/examples/action-cable-production-mode/app/assets/images/.keep +0 -0
  15. data/examples/action-cable-production-mode/app/assets/javascripts/application.js +20 -0
  16. data/examples/action-cable-production-mode/app/assets/javascripts/cable.js +13 -0
  17. data/examples/action-cable-production-mode/app/assets/javascripts/channels/.keep +0 -0
  18. data/examples/action-cable-production-mode/app/assets/stylesheets/application.css +15 -0
  19. data/examples/action-cable-production-mode/app/channels/application_cable/channel.rb +4 -0
  20. data/examples/action-cable-production-mode/app/channels/application_cable/connection.rb +4 -0
  21. data/examples/action-cable-production-mode/app/controllers/application_controller.rb +3 -0
  22. data/examples/action-cable-production-mode/app/controllers/test_controller.rb +5 -0
  23. data/examples/action-cable-production-mode/app/models/models.rb +2 -0
  24. data/examples/action-cable-production-mode/app/models/public/application_record.rb +3 -0
  25. data/examples/action-cable-production-mode/app/models/public/word.rb +2 -0
  26. data/examples/action-cable-production-mode/app/policies/application_policy.rb +14 -0
  27. data/examples/action-cable-production-mode/app/views/components.rb +16 -0
  28. data/examples/action-cable-production-mode/app/views/components/app.rb +18 -0
  29. data/examples/action-cable-production-mode/app/views/layouts/application.html.erb +14 -0
  30. data/examples/action-cable-production-mode/bin/bundle +3 -0
  31. data/examples/action-cable-production-mode/bin/rails +9 -0
  32. data/examples/action-cable-production-mode/bin/rake +9 -0
  33. data/examples/action-cable-production-mode/bin/setup +34 -0
  34. data/examples/action-cable-production-mode/bin/spring +16 -0
  35. data/examples/action-cable-production-mode/bin/update +29 -0
  36. data/examples/action-cable-production-mode/config.ru +5 -0
  37. data/examples/action-cable-production-mode/config/application.rb +18 -0
  38. data/examples/action-cable-production-mode/config/boot.rb +3 -0
  39. data/examples/action-cable-production-mode/config/cable.yml +9 -0
  40. data/examples/action-cable-production-mode/config/database.yml +25 -0
  41. data/examples/action-cable-production-mode/config/environment.rb +5 -0
  42. data/examples/action-cable-production-mode/config/environments/development.rb +56 -0
  43. data/examples/action-cable-production-mode/config/environments/production.rb +89 -0
  44. data/examples/action-cable-production-mode/config/environments/test.rb +42 -0
  45. data/examples/action-cable-production-mode/config/initializers/application_controller_renderer.rb +6 -0
  46. data/examples/action-cable-production-mode/config/initializers/assets.rb +11 -0
  47. data/examples/action-cable-production-mode/config/initializers/backtrace_silencers.rb +7 -0
  48. data/examples/action-cable-production-mode/config/initializers/cookies_serializer.rb +5 -0
  49. data/examples/action-cable-production-mode/config/initializers/filter_parameter_logging.rb +4 -0
  50. data/examples/action-cable-production-mode/config/initializers/hyper_mesh.rb +4 -0
  51. data/examples/action-cable-production-mode/config/initializers/inflections.rb +16 -0
  52. data/examples/action-cable-production-mode/config/initializers/mime_types.rb +4 -0
  53. data/examples/action-cable-production-mode/config/initializers/new_framework_defaults.rb +24 -0
  54. data/examples/action-cable-production-mode/config/initializers/session_store.rb +3 -0
  55. data/examples/action-cable-production-mode/config/initializers/wrap_parameters.rb +14 -0
  56. data/examples/action-cable-production-mode/config/locales/en.yml +23 -0
  57. data/examples/action-cable-production-mode/config/puma.rb +47 -0
  58. data/examples/action-cable-production-mode/config/routes.rb +5 -0
  59. data/examples/action-cable-production-mode/config/secrets.yml +22 -0
  60. data/examples/action-cable-production-mode/config/spring.rb +6 -0
  61. data/examples/action-cable-production-mode/db/migrate/20161114213840_create_words.rb +9 -0
  62. data/examples/action-cable-production-mode/db/schema.rb +34 -0
  63. data/examples/action-cable-production-mode/db/seeds.rb +7 -0
  64. data/examples/action-cable-production-mode/lib/assets/.keep +0 -0
  65. data/examples/action-cable-production-mode/lib/tasks/.keep +0 -0
  66. data/examples/action-cable-production-mode/log/.keep +0 -0
  67. data/examples/action-cable-production-mode/public/404.html +67 -0
  68. data/examples/action-cable-production-mode/public/422.html +67 -0
  69. data/examples/action-cable-production-mode/public/500.html +66 -0
  70. data/examples/action-cable-production-mode/public/apple-touch-icon-precomposed.png +0 -0
  71. data/examples/action-cable-production-mode/public/apple-touch-icon.png +0 -0
  72. data/examples/action-cable-production-mode/public/assets/.sprockets-manifest-3e9abd3ee8ba47c39a55b61ae37ed9e1.json +1 -0
  73. data/examples/action-cable-production-mode/public/assets/application-90043e04e9e784054fd08159fa7aafe5e23d3ffb31584b1bea1e47043c9cfb5a.js +50 -0
  74. data/examples/action-cable-production-mode/public/assets/application-90043e04e9e784054fd08159fa7aafe5e23d3ffb31584b1bea1e47043c9cfb5a.js.gz +0 -0
  75. data/examples/action-cable-production-mode/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css +0 -0
  76. data/examples/action-cable-production-mode/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css.gz +0 -0
  77. data/examples/action-cable-production-mode/public/favicon.ico +0 -0
  78. data/examples/action-cable-production-mode/public/robots.txt +5 -0
  79. data/examples/action-cable-production-mode/test/controllers/.keep +0 -0
  80. data/examples/action-cable-production-mode/test/fixtures/.keep +0 -0
  81. data/examples/action-cable-production-mode/test/fixtures/files/.keep +0 -0
  82. data/examples/action-cable-production-mode/test/fixtures/words.yml +7 -0
  83. data/examples/action-cable-production-mode/test/helpers/.keep +0 -0
  84. data/examples/action-cable-production-mode/test/integration/.keep +0 -0
  85. data/examples/action-cable-production-mode/test/mailers/.keep +0 -0
  86. data/examples/action-cable-production-mode/test/models/.keep +0 -0
  87. data/examples/action-cable-production-mode/test/models/word_test.rb +7 -0
  88. data/examples/action-cable-production-mode/test/test_helper.rb +10 -0
  89. data/examples/action-cable-production-mode/tmp/.keep +0 -0
  90. data/examples/action-cable-production-mode/vendor/assets/javascripts/.keep +0 -0
  91. data/examples/action-cable-production-mode/vendor/assets/stylesheets/.keep +0 -0
  92. data/examples/action-cable/app/views/layouts/application.html.erb +1 -1
  93. data/examples/pusher-fake/app/views/layouts/application.html.erb +1 -1
  94. data/examples/pusher/app/views/layouts/application.html.erb +1 -1
  95. data/examples/simple-poller/app/views/layouts/application.html.erb +1 -1
  96. data/examples/word-game/.gitignore +21 -0
  97. data/examples/word-game/Gemfile +57 -0
  98. data/examples/word-game/Gemfile.lock +241 -0
  99. data/examples/word-game/README.md +24 -0
  100. data/examples/word-game/Rakefile +6 -0
  101. data/examples/word-game/app/assets/config/manifest.js +3 -0
  102. data/examples/word-game/app/assets/images/.keep +0 -0
  103. data/examples/word-game/app/assets/javascripts/application.js +20 -0
  104. data/examples/word-game/app/assets/javascripts/cable.js +13 -0
  105. data/examples/word-game/app/assets/javascripts/channels/.keep +0 -0
  106. data/examples/word-game/app/assets/stylesheets/application.css +15 -0
  107. data/examples/word-game/app/channels/application_cable/channel.rb +4 -0
  108. data/examples/word-game/app/channels/application_cable/connection.rb +4 -0
  109. data/examples/word-game/app/controllers/application_controller.rb +3 -0
  110. data/examples/word-game/app/controllers/concerns/.keep +0 -0
  111. data/examples/word-game/app/helpers/application_helper.rb +2 -0
  112. data/examples/word-game/app/jobs/application_job.rb +2 -0
  113. data/examples/word-game/app/mailers/application_mailer.rb +4 -0
  114. data/examples/word-game/app/models/application_record.rb +3 -0
  115. data/examples/word-game/app/models/concerns/.keep +0 -0
  116. data/examples/word-game/app/models/models.rb +2 -0
  117. data/examples/word-game/app/models/public/.keep +0 -0
  118. data/examples/word-game/app/policies/application_policy.rb +14 -0
  119. data/examples/word-game/app/views/components.rb +16 -0
  120. data/examples/word-game/app/views/components/.keep +0 -0
  121. data/examples/word-game/app/views/layouts/application.html.erb +14 -0
  122. data/examples/{action-cable → word-game}/app/views/layouts/mailer.html.erb +0 -0
  123. data/examples/{action-cable → word-game}/app/views/layouts/mailer.text.erb +0 -0
  124. data/examples/word-game/bin/bundle +3 -0
  125. data/examples/word-game/bin/rails +9 -0
  126. data/examples/word-game/bin/rake +9 -0
  127. data/examples/word-game/bin/setup +34 -0
  128. data/examples/word-game/bin/spring +16 -0
  129. data/examples/word-game/bin/update +29 -0
  130. data/examples/word-game/config.ru +5 -0
  131. data/examples/word-game/config/application.rb +20 -0
  132. data/examples/word-game/config/boot.rb +3 -0
  133. data/examples/word-game/config/cable.yml +9 -0
  134. data/examples/word-game/config/database.yml +25 -0
  135. data/examples/word-game/config/environment.rb +5 -0
  136. data/examples/word-game/config/environments/development.rb +56 -0
  137. data/examples/word-game/config/environments/production.rb +86 -0
  138. data/examples/word-game/config/environments/test.rb +42 -0
  139. data/examples/word-game/config/initializers/application_controller_renderer.rb +6 -0
  140. data/examples/word-game/config/initializers/assets.rb +11 -0
  141. data/examples/word-game/config/initializers/backtrace_silencers.rb +7 -0
  142. data/examples/word-game/config/initializers/cookies_serializer.rb +5 -0
  143. data/examples/word-game/config/initializers/filter_parameter_logging.rb +4 -0
  144. data/examples/word-game/config/initializers/hyper_mesh.rb +4 -0
  145. data/examples/word-game/config/initializers/inflections.rb +16 -0
  146. data/examples/word-game/config/initializers/mime_types.rb +4 -0
  147. data/examples/word-game/config/initializers/new_framework_defaults.rb +24 -0
  148. data/examples/word-game/config/initializers/session_store.rb +3 -0
  149. data/examples/word-game/config/initializers/wrap_parameters.rb +14 -0
  150. data/examples/word-game/config/locales/en.yml +23 -0
  151. data/examples/word-game/config/puma.rb +47 -0
  152. data/examples/word-game/config/routes.rb +4 -0
  153. data/examples/word-game/config/secrets.yml +22 -0
  154. data/examples/word-game/config/spring.rb +6 -0
  155. data/examples/word-game/db/seeds.rb +7 -0
  156. data/examples/word-game/lib/assets/.keep +0 -0
  157. data/examples/word-game/lib/tasks/.keep +0 -0
  158. data/examples/word-game/log/.keep +0 -0
  159. data/examples/word-game/public/404.html +67 -0
  160. data/examples/word-game/public/422.html +67 -0
  161. data/examples/word-game/public/500.html +66 -0
  162. data/examples/word-game/public/apple-touch-icon-precomposed.png +0 -0
  163. data/examples/word-game/public/apple-touch-icon.png +0 -0
  164. data/examples/word-game/public/favicon.ico +0 -0
  165. data/examples/word-game/public/robots.txt +5 -0
  166. data/examples/word-game/test/controllers/.keep +0 -0
  167. data/examples/word-game/test/fixtures/.keep +0 -0
  168. data/examples/word-game/test/fixtures/files/.keep +0 -0
  169. data/examples/word-game/test/helpers/.keep +0 -0
  170. data/examples/word-game/test/integration/.keep +0 -0
  171. data/examples/word-game/test/mailers/.keep +0 -0
  172. data/examples/word-game/test/models/.keep +0 -0
  173. data/examples/word-game/test/test_helper.rb +10 -0
  174. data/examples/word-game/tmp/.keep +0 -0
  175. data/examples/word-game/vendor/assets/javascripts/.keep +0 -0
  176. data/examples/word-game/vendor/assets/stylesheets/.keep +0 -0
  177. data/lib/active_record_base.rb +20 -1
  178. data/lib/hyper-mesh.rb +1 -0
  179. data/lib/hypermesh/version.rb +1 -1
  180. data/lib/kernel/itself.rb +5 -0
  181. data/lib/reactive_record/active_record/class_methods.rb +87 -11
  182. data/lib/reactive_record/active_record/instance_methods.rb +4 -2
  183. data/lib/reactive_record/active_record/reactive_record/collection.rb +9 -12
  184. data/lib/reactive_record/active_record/reactive_record/isomorphic_base.rb +52 -52
  185. data/lib/reactive_record/active_record/reactive_record/while_loading.rb +2 -3
  186. data/lib/reactive_record/scope_description.rb +8 -3
  187. data/lib/synchromesh/client_drivers.rb +1 -9
  188. data/lib/synchromesh/connection.rb +2 -2
  189. data/lib/synchromesh/synchromesh.rb +4 -4
  190. data/spec/reactive_record/auto_load_itself_spec.rb +24 -0
  191. data/spec/reactive_record/finder_method_spec.rb +67 -0
  192. data/spec/reactive_record/save_while_loading_spec.rb +44 -0
  193. data/spec/reactive_record/update_associations_spec.rb +0 -1
  194. data/spec/reactive_record/update_scopes_spec.rb +1 -1
  195. data/spec/spec_helper.rb +5 -0
  196. data/spec/synchromesh/examples/random_examples.rb +33 -0
  197. metadata +176 -10
  198. data/examples/pusher-fake/app/views/layouts/mailer.html.erb +0 -13
  199. data/examples/pusher-fake/app/views/layouts/mailer.text.erb +0 -1
  200. data/examples/pusher/app/views/layouts/mailer.html.erb +0 -13
  201. data/examples/pusher/app/views/layouts/mailer.text.erb +0 -1
  202. data/examples/simple-poller/app/views/layouts/mailer.html.erb +0 -13
  203. data/examples/simple-poller/app/views/layouts/mailer.text.erb +0 -1
File without changes
@@ -0,0 +1,5 @@
1
+ # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2
+ #
3
+ # To ban all spiders from the entire site uncomment the next two lines:
4
+ # User-agent: *
5
+ # Disallow: /
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,10 @@
1
+ ENV['RAILS_ENV'] ||= 'test'
2
+ require File.expand_path('../../config/environment', __FILE__)
3
+ require 'rails/test_help'
4
+
5
+ class ActiveSupport::TestCase
6
+ # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
7
+ fixtures :all
8
+
9
+ # Add more helper methods to be used by all tests here...
10
+ end
File without changes
@@ -20,7 +20,6 @@ module ActiveRecord
20
20
  end
21
21
 
22
22
  alias pre_synchromesh_scope scope
23
- alias pre_synchromesh_default_scope default_scope
24
23
 
25
24
  def do_not_synchronize
26
25
  @do_not_synchronize = true
@@ -32,6 +31,8 @@ module ActiveRecord
32
31
 
33
32
  if RUBY_ENGINE != 'opal'
34
33
 
34
+ alias pre_synchromesh_default_scope default_scope
35
+
35
36
  def scope(name, *args, &block)
36
37
  opts = _synchromesh_scope_args_check(args)
37
38
  pre_synchromesh_scope(name, opts[:server], &block)
@@ -46,6 +47,15 @@ module ActiveRecord
46
47
  define_method name, &block
47
48
  end
48
49
 
50
+ def finder_method(name, &block)
51
+ singleton_class.send(:define_method, "_#{name}") do |*args|
52
+ [block.call(*args)]
53
+ end
54
+ singleton_class.send(:define_method, name) do |*args|
55
+ block.call(*args)
56
+ end
57
+ end
58
+
49
59
  else
50
60
 
51
61
  alias pre_synchromesh_method_missing method_missing
@@ -103,6 +113,15 @@ module ActiveRecord
103
113
  .new(self, nil, nil, self, 'unscoped')
104
114
  .extend(ReactiveRecord::UnscopedCollection)
105
115
  end
116
+
117
+ def finder_method(name)
118
+ ReactiveRecord::ScopeDescription.new(self, "_#{name}", {})
119
+ [name, "#{name}!"].each do |method|
120
+ singleton_class.send(:define_method, method) do |*vargs|
121
+ all.apply_scope("_#{method}", *vargs).first
122
+ end
123
+ end
124
+ end
106
125
  end
107
126
  end
108
127
 
@@ -15,6 +15,7 @@ if RUBY_ENGINE == 'opal'
15
15
  require 'active_support'
16
16
  require 'time'
17
17
  require 'date'
18
+ require 'kernel/itself' unless Object.instance_methods.include?(:itself)
18
19
  require "reactive_record/active_record/error"
19
20
  require "reactive_record/server_data_cache"
20
21
  require "reactive_record/active_record/reactive_record/while_loading"
@@ -1,3 +1,3 @@
1
1
  module Hypermesh
2
- VERSION = '0.5.2'
2
+ VERSION = '0.5.3'
3
3
  end
@@ -0,0 +1,5 @@
1
+ module Kernel
2
+ def itself
3
+ self
4
+ end
5
+ end
@@ -53,10 +53,95 @@ module ActiveRecord
53
53
  # when we implement schema validation we should also implement value checking
54
54
  end
55
55
 
56
+ # ignore any of these methods if they get called on the client. This list should be trimmed down to include only
57
+ # methods to be called as "macros" such as :after_create, etc...
58
+ SERVER_METHODS = [
59
+ :attribute_type_decorations, :defined_enums, :_validators, :timestamped_migrations, :lock_optimistically, :lock_optimistically=,
60
+ :local_stored_attributes=, :lock_optimistically?, :attribute_aliases?, :attribute_method_matchers?, :defined_enums?,
61
+ :has_many_without_reactive_record_add_changed_method, :has_many_with_reactive_record_add_changed_method,
62
+ :belongs_to_without_reactive_record_add_changed_method, :belongs_to_with_reactive_record_add_changed_method,
63
+ :cache_timestamp_format, :composed_of_with_reactive_record_add_changed_method, :schema_format, :schema_format=,
64
+ :error_on_ignored_order_or_limit, :error_on_ignored_order_or_limit=, :timestamped_migrations=, :dump_schema_after_migration,
65
+ :dump_schema_after_migration=, :dump_schemas, :dump_schemas=, :warn_on_records_fetched_greater_than=,
66
+ :belongs_to_required_by_default, :default_connection_handler, :connection_handler=, :default_connection_handler=,
67
+ :skip_time_zone_conversion_for_attributes, :skip_time_zone_conversion_for_attributes=, :time_zone_aware_types,
68
+ :time_zone_aware_types=, :protected_environments, :skip_time_zone_conversion_for_attributes?, :time_zone_aware_types?,
69
+ :partial_writes, :partial_writes=, :composed_of_without_reactive_record_add_changed_method, :logger, :partial_writes?,
70
+ :after_initialize, :record_timestamps, :record_timestamps=, :after_find, :after_touch, :before_save, :around_save,
71
+ :belongs_to_required_by_default=, :default_connection_handler?, :before_create, :around_create, :before_update, :around_update,
72
+ :after_save, :before_destroy, :around_destroy, :after_create, :after_destroy, :after_update, :_validation_callbacks,
73
+ :_validation_callbacks?, :_validation_callbacks=, :_initialize_callbacks, :_initialize_callbacks?, :_initialize_callbacks=,
74
+ :_find_callbacks, :_find_callbacks?, :_find_callbacks=, :_touch_callbacks, :_touch_callbacks?, :_touch_callbacks=, :_save_callbacks,
75
+ :_save_callbacks?, :_save_callbacks=, :_create_callbacks, :_create_callbacks?, :_create_callbacks=, :_update_callbacks,
76
+ :_update_callbacks?, :_update_callbacks=, :_destroy_callbacks, :_destroy_callbacks?, :_destroy_callbacks=, :record_timestamps?,
77
+ :_synchromesh_scope_args_check, :pre_synchromesh_scope, :pre_synchromesh_default_scope, :do_not_synchronize, :do_not_synchronize?,
78
+ :logger=, :maintain_test_schema, :maintain_test_schema=, :scope, :time_zone_aware_attributes, :time_zone_aware_attributes=,
79
+ :default_timezone, :default_timezone=, :_attr_readonly, :warn_on_records_fetched_greater_than, :configurations, :configurations=,
80
+ :_attr_readonly?, :table_name_prefix=, :table_name_suffix=, :schema_migrations_table_name=, :internal_metadata_table_name,
81
+ :internal_metadata_table_name=, :primary_key_prefix_type, :_attr_readonly=, :pluralize_table_names=, :protected_environments=,
82
+ :ignored_columns=, :ignored_columns, :index_nested_attribute_errors, :index_nested_attribute_errors=, :primary_key_prefix_type=,
83
+ :table_name_prefix?, :table_name_suffix?, :schema_migrations_table_name?, :internal_metadata_table_name?, :protected_environments?,
84
+ :pluralize_table_names?, :ignored_columns?, :store_full_sti_class, :store_full_sti_class=, :nested_attributes_options,
85
+ :nested_attributes_options=, :store_full_sti_class?, :default_scopes, :default_scope_override, :default_scopes=, :default_scope_override=,
86
+ :nested_attributes_options?, :cache_timestamp_format=, :cache_timestamp_format?, :reactive_record_association_keys, :_validators=,
87
+ :has_many, :belongs_to, :composed_of, :belongs_to_without_reactive_record_add_is_method, :_rollback_callbacks, :_commit_callbacks,
88
+ :_before_commit_callbacks, :attribute_type_decorations=, :_commit_callbacks=, :_commit_callbacks?, :_before_commit_callbacks?,
89
+ :_before_commit_callbacks=, :_rollback_callbacks=, :_before_commit_without_transaction_enrollment_callbacks?,
90
+ :_before_commit_without_transaction_enrollment_callbacks=, :_commit_without_transaction_enrollment_callbacks,
91
+ :_commit_without_transaction_enrollment_callbacks?, :_commit_without_transaction_enrollment_callbacks=, :_rollback_callbacks?,
92
+ :_rollback_without_transaction_enrollment_callbacks?, :_rollback_without_transaction_enrollment_callbacks=,
93
+ :_rollback_without_transaction_enrollment_callbacks, :_before_commit_without_transaction_enrollment_callbacks, :aggregate_reflections,
94
+ :_reflections=, :aggregate_reflections=, :pluralize_table_names, :public_columns_hash, :attributes_to_define_after_schema_loads,
95
+ :attributes_to_define_after_schema_loads=, :table_name_suffix, :schema_migrations_table_name, :attribute_aliases,
96
+ :attribute_method_matchers, :connection_handler, :attribute_aliases=, :attribute_method_matchers=, :_validate_callbacks,
97
+ :_validate_callbacks?, :_validate_callbacks=, :_validators?, :_reflections?, :aggregate_reflections?, :include_root_in_json,
98
+ :_reflections, :include_root_in_json=, :include_root_in_json?, :local_stored_attributes, :default_scope, :table_name_prefix,
99
+ :attributes_to_define_after_schema_loads?, :attribute_type_decorations?, :defined_enums=, :suppress, :has_secure_token,
100
+ :generate_unique_secure_token, :store, :store_accessor, :_store_accessors_module, :stored_attributes, :reflect_on_aggregation,
101
+ :reflect_on_all_aggregations, :_reflect_on_association, :reflect_on_all_associations, :clear_reflections_cache, :reflections,
102
+ :reflect_on_association, :reflect_on_all_autosave_associations, :no_touching, :transaction, :after_commit, :after_rollback, :before_commit,
103
+ :before_commit_without_transaction_enrollment, :after_create_commit, :after_update_commit, :after_destroy_commit,
104
+ :after_commit_without_transaction_enrollment, :after_rollback_without_transaction_enrollment, :raise_in_transactional_callbacks,
105
+ :raise_in_transactional_callbacks=, :accepts_nested_attributes_for, :has_secure_password, :has_one, :has_and_belongs_to_many,
106
+ :before_validation, :after_validation, :serialize, :primary_key, :dangerous_attribute_method?, :get_primary_key, :quoted_primary_key,
107
+ :define_method_attribute, :reset_primary_key, :primary_key=, :define_method_attribute=, :attribute_names, :initialize_generated_modules,
108
+ :column_for_attribute, :define_attribute_methods, :undefine_attribute_methods, :instance_method_already_implemented?, :method_defined_within?,
109
+ :dangerous_class_method?, :class_method_defined_within?, :attribute_method?, :has_attribute?, :generated_attribute_methods,
110
+ :attribute_method_prefix, :attribute_method_suffix, :attribute_method_affix, :attribute_alias?, :attribute_alias, :define_attribute_method,
111
+ :update_counters, :locking_enabled?, :locking_column, :locking_column=, :reset_locking_column, :decorate_attribute_type,
112
+ :decorate_matching_attribute_types, :attribute, :define_attribute, :reset_counters, :increment_counter, :decrement_counter,
113
+ :validates_absence_of, :validates_length_of, :validates_size_of, :validates_presence_of, :validates_associated, :validates_uniqueness_of,
114
+ :validates_acceptance_of, :validates_confirmation_of, :validates_exclusion_of, :validates_format_of, :validates_inclusion_of,
115
+ :validates_numericality_of, :define_callbacks, :normalize_callback_params, :__update_callbacks, :get_callbacks, :set_callback,
116
+ :set_callbacks, :skip_callback, :reset_callbacks, :deprecated_false_terminator, :define_model_callbacks, :validate, :validators,
117
+ :validates_each, :validates_with, :clear_validators!, :validators_on, :validates, :_validates_default_keys, :_parse_validates_options,
118
+ :validates!, :_to_partial_path, :sanitize, :sanitize_sql, :sanitize_conditions, :quote_value, :sanitize_sql_for_conditions, :sanitize_sql_array,
119
+ :sanitize_sql_for_assignment, :sanitize_sql_hash_for_assignment, :sanitize_sql_for_order, :expand_hash_conditions_for_aggregates, :sanitize_sql_like,
120
+ :replace_named_bind_variables, :replace_bind_variables, :raise_if_bind_arity_mismatch, :replace_bind_variable, :quote_bound_value, :all,
121
+ :default_scoped, :valid_scope_name?, :scope_attributes?, :before_remove_const, :ignore_default_scope?, :unscoped, :build_default_scope,
122
+ :evaluate_default_scope, :ignore_default_scope=, :current_scope, :current_scope=, :scope_attributes, :base_class, :abstract_class?,
123
+ :finder_needs_type_condition?, :sti_name, :descends_from_active_record?, :abstract_class, :compute_type, :abstract_class=, :table_name, :columns,
124
+ :table_exists?, :columns_hash, :column_names, :attribute_types, :prefetch_primary_key?, :sequence_name, :quoted_table_name, :_default_attributes,
125
+ :type_for_attribute, :inheritance_column, :attributes_builder, :inheritance_column=, :reset_table_name, :table_name=, :reset_column_information,
126
+ :full_table_name_prefix, :full_table_name_suffix, :reset_sequence_name, :sequence_name=, :next_sequence_value, :column_defaults, :content_columns,
127
+ :readonly_attributes, :attr_readonly, :create, :create!, :instantiate, :find, :type_caster, :arel_table, :find_by, :find_by!, :initialize_find_by_cache,
128
+ :generated_association_methods, :arel_engine, :arel_attribute, :predicate_builder, :collection_cache_key, :relation_delegate_class,
129
+ :initialize_relation_delegate_cache, :enum, :collecting_queries_for_explain, :exec_explain, :i18n_scope, :lookup_ancestors, :human_attribute_name,
130
+ :references, :uniq, :maximum, :none, :exists?, :second, :limit, :order, :eager_load, :update, :delete_all, :destroy, :ids, :many?, :pluck, :third,
131
+ :delete, :fourth, :fifth, :forty_two, :second_to_last, :third_to_last, :preload, :sum, :take!, :first!, :last!, :second!, :offset, :select, :fourth!,
132
+ :third!, :third_to_last!, :fifth!, :where, :first_or_create, :second_to_last!, :forty_two!, :first, :having, :any?, :one?, :none?, :find_or_create_by,
133
+ :from, :first_or_create!, :first_or_initialize, :except, :find_or_create_by!, :find_or_initialize_by, :includes, :destroy_all, :update_all, :or,
134
+ :find_in_batches, :take, :joins, :find_each, :last, :in_batches, :reorder, :group, :left_joins, :left_outer_joins, :rewhere, :readonly, :create_with,
135
+ :distinct, :unscope, :calculate, :average, :count_by_sql, :minimum, :lock, :find_by_sql, :count, :cache, :uncached, :connection, :connection_pool,
136
+ :establish_connection, :connected?, :clear_cache!, :clear_reloadable_connections!, :connection_id, :connection_config, :clear_all_connections!,
137
+ :remove_connection, :connection_specification_name, :connection_specification_name=, :retrieve_connection, :connection_id=, :clear_active_connections!,
138
+ :sqlite3_connection, :direct_descendants, :benchmark, :model_name
139
+ ]
140
+
56
141
  def method_missing(name, *args, &block)
57
142
  if args.count == 1 && name =~ /^find_by_/ && !block
58
143
  find_by(name.gsub(/^find_by_/, "") => args[0])
59
- else
144
+ elsif !SERVER_METHODS.include?(name)
60
145
  raise "#{self.name}.#{name}(#{args}) (called class method missing)"
61
146
  end
62
147
  end
@@ -109,7 +194,7 @@ module ActiveRecord
109
194
  name = args.first
110
195
  define_method(name) { @backing_record.reactive_get!(name, nil) }
111
196
  define_method("#{name}=") do |val|
112
- @backing_record.reactive_set!(name, backing_record.convert(name, val))
197
+ @backing_record.reactive_set!(name, backing_record.convert(name, val).itself)
113
198
  end
114
199
  opts = (args.count > 1 and args.last.is_a? Hash) ? args.last : {}
115
200
  Associations::AssociationReflection.new(self, macro, name, opts)
@@ -160,15 +245,6 @@ module ActiveRecord
160
245
  end
161
246
  end
162
247
 
163
- [
164
- "table_name=", "before_validation", "with_options", "validates_presence_of", "validates_format_of",
165
- "accepts_nested_attributes_for", "before_create", "after_create", "before_save", "after_save", "before_destroy", "where", "validate",
166
- "attr_protected", "validates_numericality_of", "default_scope", "has_attached_file", "attr_accessible",
167
- "serialize"
168
- ].each do |method|
169
- define_method(method.to_s) { |*args, &block| }
170
- end
171
-
172
248
  def _react_param_conversion(param, opt = nil)
173
249
  param = Native(param)
174
250
  param = JSON.from_object(param.to_n) if param.is_a? Native::Object
@@ -17,10 +17,12 @@ module ActiveRecord
17
17
  # we have to build the backing record first then initialize it so associations work correctly
18
18
  @backing_record = ReactiveRecord::Base.new(self.class, {}, self)
19
19
  @backing_record.instance_eval do
20
+ h = Hash.new
21
+ hash.each { |a, v| h[a] = convert(a, v).itself }
20
22
  self.class.load_data do
21
- hash.each do |attribute, value|
23
+ h.each do |attribute, value|
22
24
  unless attribute == primary_key
23
- reactive_set!(attribute, convert(attribute, value))
25
+ reactive_set!(attribute, value)
24
26
  changed_attributes << attribute
25
27
  end
26
28
  end
@@ -205,18 +205,11 @@ module ReactiveRecord
205
205
  @pre_sync_related_records = nil
206
206
  end
207
207
 
208
- # def in_this_collection(related_records)
209
- # related_records.delete_if do |r|
210
- # # BELOW IS WRONG... its more complicated isn't it...
211
- # if @association.through_association
212
- #
213
- # else
214
- # r.backing_record.attributes[@association.inverse_of] != @owner
215
- # end
216
- # end
217
-
218
208
  def apply_scope(name, *vector)
219
- build_child_scope(ScopeDescription.find(@target_klass, name), *name, *vector)
209
+ description = ScopeDescription.find(@target_klass, name)
210
+ collection = build_child_scope(description, *description.name, *vector)
211
+ collection.reload_from_db if name == "#{description.name}!"
212
+ collection
220
213
  end
221
214
 
222
215
  def child_scopes
@@ -367,6 +360,7 @@ module ReactiveRecord
367
360
  end
368
361
 
369
362
  def push(item)
363
+ item.itself # force get of at least the id
370
364
  if collection
371
365
  self.force_push item
372
366
  else
@@ -486,8 +480,11 @@ module ReactiveRecord
486
480
  def method_missing(method, *args, &block)
487
481
  if [].respond_to? method
488
482
  all.send(method, *args, &block)
489
- elsif @target_klass.respond_to?(method) or (args.count == 1 && method =~ /^find_by_/)
483
+ elsif ScopeDescription.find(@target_klass, method) || (args.count == 1 && method =~ /^find_by_/)
490
484
  apply_scope(method, *args)
485
+ elsif @target_klass.respond_to?(method) && ScopeDescription.find(@target_klass, "_#{method}")
486
+ puts "here we are..."
487
+ apply_scope("_#{method}", *args).first
491
488
  else
492
489
  super
493
490
  end
@@ -226,74 +226,74 @@ module ReactiveRecord
226
226
  end
227
227
 
228
228
  def save(validate, force, &block)
229
-
230
229
  if data_loading?
231
-
232
230
  sync!
233
-
234
231
  elsif force or changed?
232
+ HyperMesh.load do
233
+ ReactiveRecord.loads_pending! unless self.class.pending_fetches.empty?
234
+ end.then { save_to_server(validate, force, &block) }
235
+ #save_to_server(validate, force, &block)
236
+ else
237
+ promise = Promise.new
238
+ yield true, nil, [] if block
239
+ promise.resolve({success: true})
240
+ promise
241
+ end
242
+ end
235
243
 
236
- begin
237
-
238
- models, associations, backing_records = self.class.gather_records([self], force, self)
244
+ def save_to_server(validate, force, &block)
245
+ models, associations, backing_records = self.class.gather_records([self], force, self)
239
246
 
240
- backing_records.each { |id, record| record.saving! }
247
+ backing_records.each { |id, record| record.saving! }
241
248
 
242
- promise = Promise.new
249
+ promise = Promise.new
243
250
 
244
- HTTP.post(`window.ReactiveRecordEnginePath`+"/save",
245
- payload: {
246
- json: {
247
- models: models,
248
- associations: associations,
249
- validate: validate
250
- }.to_json
251
- }
252
- ).then do |response|
253
- begin
254
- response.json[:models] = response.json[:saved_models].collect do |item|
255
- backing_records[item[0]].ar_instance
256
- end
251
+ HTTP.post(`window.ReactiveRecordEnginePath`+"/save",
252
+ payload: {
253
+ json: {
254
+ models: models,
255
+ associations: associations,
256
+ validate: validate
257
+ }.to_json
258
+ }
259
+ ).then do |response|
260
+ begin
261
+ response.json[:models] = response.json[:saved_models].collect do |item|
262
+ backing_records[item[0]].ar_instance
263
+ end
257
264
 
258
- if response.json[:success]
259
- response.json[:saved_models].each do | item |
260
- # was backing_records[item[0]].sync!(item[2])
261
- HyperMesh::LocalSync.after_save backing_records[item[0]].ar_instance, item[2]
262
- end
263
- else
264
- log("Reactive Record Save Failed: #{response.json[:message]}", :error)
265
- response.json[:saved_models].each do | item |
266
- log(" Model: #{item[1]}[#{item[0]}] Attributes: #{item[2]} Errors: #{item[3]}", :error) if item[3]
267
- end
268
- end
265
+ if response.json[:success]
266
+ response.json[:saved_models].each do | item |
267
+ # was backing_records[item[0]].sync!(item[2])
268
+ HyperMesh::LocalSync.after_save backing_records[item[0]].ar_instance, item[2]
269
+ end
270
+ else
271
+ log("Reactive Record Save Failed: #{response.json[:message]}", :error)
272
+ response.json[:saved_models].each do | item |
273
+ log(" Model: #{item[1]}[#{item[0]}] Attributes: #{item[2]} Errors: #{item[3]}", :error) if item[3]
274
+ end
275
+ end
269
276
 
270
- response.json[:saved_models].each do | item |
271
- backing_records[item[0]].sync_unscoped_collection!
272
- backing_records[item[0]].errors! item[3]
273
- end
277
+ response.json[:saved_models].each do | item |
278
+ backing_records[item[0]].sync_unscoped_collection!
279
+ backing_records[item[0]].errors! item[3]
280
+ end
274
281
 
275
- yield response.json[:success], response.json[:message], response.json[:models] if block
276
- promise.resolve response.json
282
+ yield response.json[:success], response.json[:message], response.json[:models] if block
283
+ promise.resolve response.json
277
284
 
278
- backing_records.each { |id, record| record.saved! }
285
+ backing_records.each { |id, record| record.saved! }
279
286
 
280
- rescue Exception => e
281
- log("Exception raised while saving - #{e}", :error)
282
- end
283
- end
284
- promise
285
287
  rescue Exception => e
286
288
  log("Exception raised while saving - #{e}", :error)
287
- yield false, e.message, [] if block
288
- promise.resolve({success: false, message: e.message, models: []})
289
- promise
290
289
  end
291
- else
292
- promise = Promise.new
293
- yield true, nil, [] if block
294
- promise.resolve({success: true})
295
- promise
296
290
  end
291
+ promise
292
+ rescue Exception => e
293
+ log("Exception raised while saving - #{e}", :error)
294
+ yield false, e.message, [] if block
295
+ promise.resolve({success: false, message: e.message, models: []})
296
+ promise
297
297
  end
298
298
 
299
299
  else
@@ -3,7 +3,7 @@ module HyperMesh
3
3
  ReactiveRecord.load &block
4
4
  end
5
5
  end
6
-
6
+
7
7
  module ReactiveRecord
8
8
 
9
9
  # will repeatedly execute the block until it is loaded
@@ -14,7 +14,7 @@ module ReactiveRecord
14
14
  @load_stack ||= []
15
15
  @load_stack << @loads_pending
16
16
  @loads_pending = nil
17
- result = block.call
17
+ result = block.call.itself
18
18
  if @loads_pending
19
19
  @blocks_to_load ||= []
20
20
  @blocks_to_load << [Base.last_fetch_at, promise, block]
@@ -24,7 +24,6 @@ module ReactiveRecord
24
24
  @loads_pending = @load_stack.pop
25
25
  promise
26
26
  rescue Exception => e
27
- debugger
28
27
  React::IsomorphicHelpers.log "ReactiveRecord.load exception raised during initial load: #{e}", :error
29
28
  end
30
29