hyper-model 1.0.alpha1.6 → 1.0.alpha1.7

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
  SHA256:
3
- metadata.gz: b2f63052beefadb742e008e12976afe889105a0cdbd864ea49902654eb82be51
4
- data.tar.gz: 2bdf35fb8b4ccd7fd00144be9ba52d8a133797e47825b91cf6acae8dc0673043
3
+ metadata.gz: d85eab56099328a86bb19e2911f16bd1b5b9a6e98a79d7c912898dce7775e876
4
+ data.tar.gz: cf0f2c03f22c84710e76e5177f8f54f8847c9e1e671f3c5aab38b8c77abbfc8f
5
5
  SHA512:
6
- metadata.gz: 2e7481f8e04d3d464507d7c25c20b3dc55167dd6b8cb368f28113e9f52b4ba95815611b8f4fe740d207860f1bc60cdb4ddcdafb996d83ddf2d51afb8cc397fb5
7
- data.tar.gz: e0e5fb04e304496c3d0ef8353a9ed0bd36a303257e3f062d9ed61e75b4af8d1ded8ed18defd37e7e44dd79b618b221d129287a39d9e331bb20b9cc648c668124
6
+ metadata.gz: 8095f00d457423d733f0d1f8ea0118a47b5084b282bc224b9a3a7b90e8ea9321487e849932b48a4f2fe0d75ee1047033150da036019cdc7be0556d7fe3d71eb2
7
+ data.tar.gz: b734954d84ae3b363a9fceff250b0a49a4062ec5d893a96197d4c9cd9f6ccb3adbdd90d8f41f325a51faffaef08c7b976217005fdd3b85c98e9fd219575dd1ec
data/hyper-model.gemspec CHANGED
@@ -52,7 +52,7 @@ Gem::Specification.new do |spec|
52
52
  spec.add_development_dependency 'rspec-rails'
53
53
  spec.add_development_dependency 'rspec-steps', '~> 2.1.1'
54
54
  spec.add_development_dependency 'rspec-wait'
55
- spec.add_development_dependency 'rubocop', '~> 0.51.0'
55
+ spec.add_development_dependency 'rubocop' #, '~> 0.51.0'
56
56
  spec.add_development_dependency 'shoulda'
57
57
  spec.add_development_dependency 'shoulda-matchers'
58
58
  spec.add_development_dependency 'spring-commands-rspec', '~> 1.0.4'
@@ -14,7 +14,7 @@ module ActiveRecord
14
14
  else
15
15
  { server: args[0] }
16
16
  end
17
- return opts if opts && opts[:server].respond_to?(:call)
17
+ return opts if opts[:server].respond_to?(:call) || RUBY_ENGINE == 'opal'
18
18
  raise 'must provide either a proc as the first arg or by the '\
19
19
  '`:server` option to scope and default_scope methods'
20
20
  end
@@ -392,6 +392,10 @@ module ActiveRecord
392
392
  nil
393
393
  end
394
394
  end
395
+
396
+ scope :__hyperstack_internal_where_hash_scope, ->(*args) { where(*args) }
397
+
398
+ scope :__hyperstack_internal_where_sql_scope, ->(*args) { where(*args) }
395
399
  end
396
400
  end
397
401
 
@@ -1,6 +1,7 @@
1
1
  # Add pluck to enumerable... its already done for us in rails 5+
2
2
  module Enumerable
3
- def pluck(key)
4
- map { |element| element[key] }
3
+ def pluck(*keys)
4
+ map { |element| keys.map { |key| element[key] } }
5
+ .flatten(keys.count > 1 ? 0 : 1)
5
6
  end
6
7
  end unless Enumerable.method_defined? :pluck
@@ -1,3 +1,3 @@
1
1
  module HyperModel
2
- VERSION = '1.0.alpha1.6'
2
+ VERSION = '1.0.alpha1.7'
3
3
  end
@@ -10,6 +10,21 @@ module ActiveRecord
10
10
  finder_method :__hyperstack_internal_scoped_last
11
11
  scope :__hyperstack_internal_scoped_last_n, ->(n) { last(n) }
12
12
 
13
+ def self.where(*args)
14
+ if args[0].is_a? Hash
15
+ # we can compute membership in the scope when the arg is a hash
16
+ __hyperstack_internal_where_hash_scope(args[0])
17
+ else
18
+ # otherwise the scope has to always be computed on the server
19
+ __hyperstack_internal_where_sql_scope(*args)
20
+ end
21
+ end
22
+
23
+ scope :__hyperstack_internal_where_hash_scope,
24
+ client: ->(attrs) { !attrs.detect { |k, v| self[k] != v } }
25
+
26
+ scope :__hyperstack_internal_where_sql_scope
27
+
13
28
  ReactiveRecord::ScopeDescription.new(
14
29
  self, :___hyperstack_internal_scoped_find_by,
15
30
  client: ->(attrs) { !attrs.detect { |attr, value| attributes[attr] != value } }
@@ -6,39 +6,38 @@ module ActiveRecord
6
6
  # adds method to get the HyperMesh public column types
7
7
  # this works because the public folder is currently required to be eager loaded.
8
8
  class Base
9
+ @@hyper_stack_public_columns_hash_mutex = Mutex.new
9
10
  def self.public_columns_hash
10
- return @public_columns_hash if @public_columns_hash && Rails.env.production?
11
- files = []
12
- Hyperstack.public_model_directories.each do |dir|
13
- dir_length = Rails.root.join(dir).to_s.length + 1
14
- Dir.glob(Rails.root.join(dir, '**', '*.rb')).each do |file|
15
- require_dependency(file) # still the file is loaded to make sure for development and test env
16
- files << file[dir_length..-4]
11
+ @@hyper_stack_public_columns_hash_mutex.synchronize do
12
+ return @public_columns_hash if @public_columns_hash && Rails.env.production?
13
+ files = []
14
+ Hyperstack.public_model_directories.each do |dir|
15
+ dir_length = Rails.root.join(dir).to_s.length + 1
16
+ Dir.glob(Rails.root.join(dir, '**', '*.rb')).each do |file|
17
+ require_dependency(file) # still the file is loaded to make sure for development and test env
18
+ files << file[dir_length..-4]
19
+ end
17
20
  end
18
- end
19
- @public_columns_hash = {}
20
- # descendants only works for already loaded models!
21
- descendants.each do |model|
22
- if files.include?(model.name.underscore) && model.name.underscore != 'application_record'
23
- @public_columns_hash[model.name] = model.columns_hash rescue nil # why rescue?
21
+ @public_columns_hash = {}
22
+ # descendants only works for already loaded models!
23
+ descendants.each do |model|
24
+ if files.include?(model.name.underscore) && model.name.underscore != 'application_record'
25
+ @public_columns_hash[model.name] = model.columns_hash rescue nil # why rescue?
26
+ end
24
27
  end
25
- # begin
26
- # @public_columns_hash[model.name] = model.columns_hash if model.table_name
27
- # rescue Exception => e
28
- # binding.pry
29
- # @public_columns_hash = nil
30
- # raise $!, "Could not read 'columns_hash' for #{model}: #{$!}", $!.backtrace
31
- # end if files.include?(model.name.underscore) && model.name.underscore != 'application_record'
28
+ @public_columns_hash
32
29
  end
33
- @public_columns_hash
34
30
  end
35
31
 
32
+ @@hyper_stack_public_columns_hash_as_json_mutex = Mutex.new
36
33
  def self.public_columns_hash_as_json
37
- return @public_columns_hash_json if @public_columns_hash_json && Rails.env.production?
38
- pch = public_columns_hash
39
- return @public_columns_hash_json if @prev_public_columns_hash == pch
40
- @prev_public_columns_hash = pch
41
- @public_columns_hash_json = pch.to_json
34
+ @@hyper_stack_public_columns_hash_as_json_mutex.synchronize do
35
+ return @public_columns_hash_json if @public_columns_hash_json && Rails.env.production?
36
+ pch = public_columns_hash
37
+ return @public_columns_hash_json if @prev_public_columns_hash == pch
38
+ @prev_public_columns_hash = pch
39
+ @public_columns_hash_json = pch.to_json
40
+ end
42
41
  end
43
42
  end
44
43
  end
@@ -677,10 +677,19 @@ To determine this sync_scopes first asks if the record being changed is in the s
677
677
  all.send(method, *args, &block)
678
678
  elsif ScopeDescription.find(@target_klass, method)
679
679
  apply_scope(method, *args)
680
- elsif @target_klass.respond_to?(method) && ScopeDescription.find(@target_klass, "_#{method}")
680
+ elsif !@target_klass.respond_to?(method)
681
+ super
682
+ elsif ScopeDescription.find(@target_klass, "_#{method}")
681
683
  apply_scope("_#{method}", *args).first
682
684
  else
683
- super
685
+ # create a subclass of the original target class that responds to all
686
+ # by returning our collection back
687
+ fake_class = Class.new(@target_klass)
688
+ fake_class.instance_variable_set("@all", self)
689
+ # Opal 0.11 does not handle overridding the original @target_klass
690
+ # with an accessor, so we define the accessor as a method.
691
+ fake_class.define_singleton_method(:all) { @all }
692
+ fake_class.send(method, *args, &block)
684
693
  end
685
694
  end
686
695
 
@@ -1,5 +1,3 @@
1
- require 'json'
2
-
3
1
  module ReactiveRecord
4
2
 
5
3
  class Base
@@ -557,13 +555,21 @@ module ReactiveRecord
557
555
  if !data_loading? && (id || vector)
558
556
  Operations::Destroy.run(model: ar_instance.model_name.to_s, id: id, vector: vector)
559
557
  .then do |response|
560
- Broadcast.to_self ar_instance
558
+ #[reactive_record_id, model.class.name, attributes, messages] model.errors.messages
559
+
560
+ if response[:success]
561
+ @destroyed = true
562
+ Broadcast.to_self ar_instance
563
+ else
564
+ errors! response[:messages]
565
+ end
561
566
  yield response[:success], response[:message] if block
562
567
  promise.resolve response
563
568
  end
564
569
  else
565
570
  destroy_associations
566
571
  # sync_unscoped_collection! # ? should we do this here was NOT being done before hypermesh integration
572
+ @destroyed = true
567
573
  yield true, nil if block
568
574
  promise.resolve(success: true)
569
575
  end
@@ -575,8 +581,6 @@ module ReactiveRecord
575
581
  # sync!
576
582
  # and modify server_data_cache so that it does NOT call destroy
577
583
 
578
- @destroyed = true
579
-
580
584
  promise
581
585
  end
582
586
 
@@ -590,10 +594,9 @@ module ReactiveRecord
590
594
  ServerDataCache.new(acting_user, {})[*vector].value
591
595
  end
592
596
 
593
- record.check_permission_with_acting_user(acting_user, :destroy_permitted?).destroy
594
- { success: true, attributes: {} }
597
+ success = record.check_permission_with_acting_user(acting_user, :destroy_permitted?).destroy
598
+ { success: success, attributes: {}, messages: record.errors.messages }
595
599
  rescue Exception => e
596
- # ReactiveRecord::Pry.rescued(e)
597
600
  { success: false, record: record, message: e }
598
601
  end
599
602
  end
@@ -506,7 +506,7 @@ keys:
506
506
 
507
507
  target.send "#{method}=", value.first
508
508
  elsif value.is_a? Array
509
- target.send("_hyperstack_internal_setter_#{method}", value.first) unless method == target.class.primary_key
509
+ target.send("_hyperstack_internal_setter_#{method}", value.first) unless [target.class.primary_key, :id].include? method
510
510
  elsif value.is_a?(Hash) && value[:id] && value[:id].first && (association = target.class.reflect_on_association(method))
511
511
  # not sure if its necessary to check the id above... is it possible to for the method to be an association but not have an id?
512
512
  klass = value[:model_name] ? Object.const_get(value[:model_name].first) : association.klass
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyper-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.alpha1.6
4
+ version: 1.0.alpha1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitch VanDuyn
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-03-29 00:00:00.000000000 Z
12
+ date: 2021-04-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - '='
47
47
  - !ruby/object:Gem::Version
48
- version: 1.0.alpha1.6
48
+ version: 1.0.alpha1.7
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - '='
54
54
  - !ruby/object:Gem::Version
55
- version: 1.0.alpha1.6
55
+ version: 1.0.alpha1.7
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: bundler
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -101,28 +101,28 @@ dependencies:
101
101
  requirements:
102
102
  - - '='
103
103
  - !ruby/object:Gem::Version
104
- version: 1.0.alpha1.6
104
+ version: 1.0.alpha1.7
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - '='
110
110
  - !ruby/object:Gem::Version
111
- version: 1.0.alpha1.6
111
+ version: 1.0.alpha1.7
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: hyper-trace
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
116
  - - '='
117
117
  - !ruby/object:Gem::Version
118
- version: 1.0.alpha1.6
118
+ version: 1.0.alpha1.7
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
123
  - - '='
124
124
  - !ruby/object:Gem::Version
125
- version: 1.0.alpha1.6
125
+ version: 1.0.alpha1.7
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: mini_racer
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -397,16 +397,16 @@ dependencies:
397
397
  name: rubocop
398
398
  requirement: !ruby/object:Gem::Requirement
399
399
  requirements:
400
- - - "~>"
400
+ - - ">="
401
401
  - !ruby/object:Gem::Version
402
- version: 0.51.0
402
+ version: '0'
403
403
  type: :development
404
404
  prerelease: false
405
405
  version_requirements: !ruby/object:Gem::Requirement
406
406
  requirements:
407
- - - "~>"
407
+ - - ">="
408
408
  - !ruby/object:Gem::Version
409
- version: 0.51.0
409
+ version: '0'
410
410
  - !ruby/object:Gem::Dependency
411
411
  name: shoulda
412
412
  requirement: !ruby/object:Gem::Requirement