iknow_view_models 3.2.0 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +13 -0
  3. data/Appraisals +6 -6
  4. data/Rakefile +5 -5
  5. data/gemfiles/rails_5_2.gemfile +5 -5
  6. data/gemfiles/rails_6_0.gemfile +5 -5
  7. data/iknow_view_models.gemspec +40 -39
  8. data/lib/iknow_view_models.rb +9 -7
  9. data/lib/iknow_view_models/version.rb +1 -1
  10. data/lib/view_model.rb +17 -14
  11. data/lib/view_model/access_control.rb +5 -2
  12. data/lib/view_model/access_control/composed.rb +10 -9
  13. data/lib/view_model/access_control/open.rb +2 -0
  14. data/lib/view_model/access_control/read_only.rb +2 -0
  15. data/lib/view_model/access_control/tree.rb +11 -6
  16. data/lib/view_model/access_control_error.rb +4 -1
  17. data/lib/view_model/active_record.rb +12 -11
  18. data/lib/view_model/active_record/association_data.rb +2 -1
  19. data/lib/view_model/active_record/association_manipulation.rb +6 -4
  20. data/lib/view_model/active_record/cache.rb +4 -2
  21. data/lib/view_model/active_record/collection_nested_controller.rb +3 -3
  22. data/lib/view_model/active_record/controller_base.rb +4 -1
  23. data/lib/view_model/active_record/nested_controller_base.rb +1 -0
  24. data/lib/view_model/active_record/update_context.rb +8 -6
  25. data/lib/view_model/active_record/update_data.rb +32 -30
  26. data/lib/view_model/active_record/update_operation.rb +17 -13
  27. data/lib/view_model/active_record/visitor.rb +0 -1
  28. data/lib/view_model/after_transaction_runner.rb +0 -1
  29. data/lib/view_model/callbacks.rb +3 -1
  30. data/lib/view_model/controller.rb +13 -3
  31. data/lib/view_model/deserialization_error.rb +15 -12
  32. data/lib/view_model/error.rb +12 -10
  33. data/lib/view_model/error_view.rb +3 -1
  34. data/lib/view_model/migration/no_path_error.rb +1 -0
  35. data/lib/view_model/migration/one_way_error.rb +1 -0
  36. data/lib/view_model/migration/unspecified_version_error.rb +1 -0
  37. data/lib/view_model/record.rb +11 -13
  38. data/lib/view_model/reference.rb +3 -1
  39. data/lib/view_model/references.rb +8 -5
  40. data/lib/view_model/registry.rb +1 -1
  41. data/lib/view_model/schemas.rb +9 -4
  42. data/lib/view_model/serialization_error.rb +4 -1
  43. data/lib/view_model/serialize_context.rb +4 -4
  44. data/lib/view_model/test_helpers.rb +8 -3
  45. data/lib/view_model/test_helpers/arvm_builder.rb +19 -14
  46. data/lib/view_model/traversal_context.rb +2 -1
  47. data/test/.rubocop.yml +14 -0
  48. data/test/helpers/arvm_test_models.rb +12 -9
  49. data/test/helpers/arvm_test_utilities.rb +5 -3
  50. data/test/helpers/controller_test_helpers.rb +31 -29
  51. data/test/helpers/match_enumerator.rb +1 -0
  52. data/test/helpers/query_logging.rb +2 -1
  53. data/test/helpers/test_access_control.rb +5 -3
  54. data/test/helpers/viewmodel_spec_helpers.rb +21 -20
  55. data/test/unit/view_model/access_control_test.rb +144 -144
  56. data/test/unit/view_model/active_record/alias_test.rb +15 -13
  57. data/test/unit/view_model/active_record/belongs_to_test.rb +40 -39
  58. data/test/unit/view_model/active_record/cache_test.rb +27 -26
  59. data/test/unit/view_model/active_record/cloner_test.rb +67 -63
  60. data/test/unit/view_model/active_record/controller_test.rb +37 -38
  61. data/test/unit/view_model/active_record/counter_test.rb +10 -9
  62. data/test/unit/view_model/active_record/customization_test.rb +59 -58
  63. data/test/unit/view_model/active_record/has_many_test.rb +112 -111
  64. data/test/unit/view_model/active_record/has_many_through_poly_test.rb +15 -14
  65. data/test/unit/view_model/active_record/has_many_through_test.rb +33 -38
  66. data/test/unit/view_model/active_record/has_one_test.rb +37 -36
  67. data/test/unit/view_model/active_record/migration_test.rb +13 -13
  68. data/test/unit/view_model/active_record/namespacing_test.rb +19 -17
  69. data/test/unit/view_model/active_record/poly_test.rb +44 -45
  70. data/test/unit/view_model/active_record/shared_test.rb +30 -28
  71. data/test/unit/view_model/active_record/version_test.rb +9 -7
  72. data/test/unit/view_model/active_record_test.rb +72 -72
  73. data/test/unit/view_model/callbacks_test.rb +19 -15
  74. data/test/unit/view_model/controller_test.rb +4 -2
  75. data/test/unit/view_model/record_test.rb +92 -97
  76. data/test/unit/view_model/traversal_context_test.rb +4 -5
  77. data/test/unit/view_model_test.rb +18 -16
  78. metadata +7 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8031b0e3cf50931cfdc65ee1c530efc4210566f2951ab5d6187f80d75848ac2a
4
- data.tar.gz: bad21c087fff5def9362bd93576e0f9f0aeb8ec8ddc4f5ff6eb6849e879168c7
3
+ metadata.gz: 2fa0ab7a6ce71bd40dbb00eea4f73c33a1c3f442ccf349626154c6bf2974088e
4
+ data.tar.gz: 298c6f0483d477bf48f849ad380c9b7bd6eb7d4a55763ba10d1639c2d2181103
5
5
  SHA512:
6
- metadata.gz: 17edcc7ab94fa8fa3a9b34e209a3d2feebb1c31fc1d3d619c36d3d9f602312e9ff13c1e0bc0974c2df070084b8b3fa7de3a2f7c74c38a3dbd04976ee166854aa
7
- data.tar.gz: e176a0df288c029bea2d083c03492b6a5370e78a4c35164eaadf284b66de9120dfe60eda3dc6bca5e2845b71a865f4996fd17124462d06a70156249fd709a066
6
+ metadata.gz: 54c754abf844d1a4a62124df1476c3870f487b56de1108acabdb0b57acca108581817df170c318cd9d8edd0930314286d498a3d1ba9e8b68ae87a928dbfa73e9
7
+ data.tar.gz: 905754efd90b6176b5f7271b1cd997df974ac35dde9afdbaa7612e4a5ec722c942b1021fb565e693efac6df30aa67205d39b6adc9ba3fa64d0db401ce99d7915
@@ -1,5 +1,18 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.7
3
+ Exclude:
4
+ - Appraisals
5
+ - Gemfile
6
+ - Rakefile
7
+ - 'gemfiles/*'
8
+ - 'nix/gem/**/*'
3
9
 
4
10
  inherit_gem:
5
11
  rubocop-iknow: rubocop.yml
12
+
13
+ Metrics/BlockNesting:
14
+ Enabled: false
15
+ Lint/IneffectiveAccessModifier:
16
+ Enabled: false
17
+ Lint/UselessAccessModifier:
18
+ Enabled: false
data/Appraisals CHANGED
@@ -1,9 +1,9 @@
1
- appraise "rails-5-2" do
2
- gem "activerecord", "~> 5.2.0"
3
- gem "activesupport", "~> 5.2.0"
1
+ appraise 'rails-5-2' do
2
+ gem 'activerecord', '~> 5.2.0'
3
+ gem 'activesupport', '~> 5.2.0'
4
4
  end
5
5
 
6
- appraise "rails-6-0" do
7
- gem "activerecord", "~> 6.0.0"
8
- gem "activesupport", "~> 6.0.0"
6
+ appraise 'rails-6-0' do
7
+ gem 'activerecord', '~> 6.0.0'
8
+ gem 'activesupport', '~> 6.0.0'
9
9
  end
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new do |t|
5
5
  t.libs << 'test'
@@ -8,14 +8,14 @@ Rake::TestTask.new do |t|
8
8
  t.verbose = true
9
9
  end
10
10
 
11
- desc "Open an IRB console with the test helpers"
11
+ desc 'Open an IRB console with the test helpers'
12
12
  task :test_console do
13
13
  ruby %{-r bundler/setup -Ilib -e 'load "test/helpers/arvm_test_models.rb"' -r irb -e 'IRB.start(__FILE__)'}
14
14
  end
15
15
 
16
- desc "Open a Pry console with the test helpers"
16
+ desc 'Open a Pry console with the test helpers'
17
17
  task 'test_console:pry' do
18
- ruby %{-r bundler/setup -Ilib -e 'load "test/helpers/arvm_test_models.rb"' -r pry -e 'Pry.start'}
18
+ ruby %(-r bundler/setup -Ilib -e 'load "test/helpers/arvm_test_models.rb"' -r pry -e 'Pry.start')
19
19
  end
20
20
 
21
21
  task :default => :test
@@ -1,9 +1,9 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
- gem "minitest-ci"
6
- gem "activerecord", "~> 5.2.0"
7
- gem "activesupport", "~> 5.2.0"
5
+ gem 'minitest-ci'
6
+ gem 'activerecord', '~> 5.2.0'
7
+ gem 'activesupport', '~> 5.2.0'
8
8
 
9
- gemspec path: "../"
9
+ gemspec path: '../'
@@ -1,9 +1,9 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
- gem "minitest-ci"
6
- gem "activerecord", "~> 6.0.0"
7
- gem "activesupport", "~> 6.0.0"
5
+ gem 'minitest-ci'
6
+ gem 'activerecord', '~> 6.0.0'
7
+ gem 'activesupport', '~> 6.0.0'
8
8
 
9
- gemspec path: "../"
9
+ gemspec path: '../'
@@ -1,51 +1,52 @@
1
1
  # frozen_string_literal: true
2
- # coding: utf-8
3
2
 
4
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
5
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
5
  require 'iknow_view_models/version'
7
6
 
8
7
  Gem::Specification.new do |spec|
9
- spec.name = "iknow_view_models"
8
+ spec.name = 'iknow_view_models'
10
9
  spec.version = IknowViewModels::VERSION
11
- spec.authors = ["iKnow Team"]
12
- spec.email = ["edge@iknow.jp"]
13
- spec.summary = "ViewModels provide a means of encapsulating a collection of related data and specifying its JSON serialization."
14
- spec.description = ""
15
- spec.homepage = "https://github.com/iknow/cerego_view_models"
16
- spec.license = "MIT"
10
+ spec.authors = ['iKnow Team']
11
+ spec.email = ['edge@iknow.jp']
12
+ spec.summary = 'ViewModels provide a means of encapsulating a collection of related data and specifying its JSON serialization.'
13
+ spec.description = ''
14
+ spec.homepage = 'https://github.com/iknow/cerego_view_models'
15
+ spec.license = 'MIT'
17
16
 
18
17
  spec.files = `git ls-files -z`.split("\x0")
19
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
- spec.require_paths = ["lib"]
22
-
23
- spec.add_dependency "activerecord", ">= 5.0"
24
- spec.add_dependency "activesupport", ">= 5.0"
25
-
26
- spec.add_dependency "acts_as_manual_list"
27
- spec.add_dependency "deep_preloader", ">= 1.0.1"
28
- spec.add_dependency "iknow_cache"
29
- spec.add_dependency "iknow_params", "~> 2.2.0"
30
- spec.add_dependency "safe_values"
31
- spec.add_dependency "keyword_builder"
32
-
33
- spec.add_dependency "concurrent-ruby"
34
- spec.add_dependency "jbuilder"
35
- spec.add_dependency "json_schema"
36
- spec.add_dependency "lazily"
37
- spec.add_dependency "renum"
38
- spec.add_dependency "oj"
39
- spec.add_dependency "rgl"
40
-
41
- spec.add_development_dependency "appraisal"
42
- spec.add_development_dependency "bundler"
43
- spec.add_development_dependency "byebug"
44
- spec.add_development_dependency "method_source"
45
- spec.add_development_dependency "minitest-hooks"
46
- spec.add_development_dependency "pg"
47
- spec.add_development_dependency "pry"
48
- spec.add_development_dependency "rake"
49
- spec.add_development_dependency "rspec-expectations"
50
- spec.add_development_dependency "sqlite3"
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.required_ruby_version = 2.6
23
+
24
+ spec.add_dependency 'activerecord', '>= 5.0'
25
+ spec.add_dependency 'activesupport', '>= 5.0'
26
+
27
+ spec.add_dependency 'acts_as_manual_list'
28
+ spec.add_dependency 'deep_preloader', '>= 1.0.1'
29
+ spec.add_dependency 'iknow_cache'
30
+ spec.add_dependency 'iknow_params', '~> 2.2.0'
31
+ spec.add_dependency 'keyword_builder'
32
+ spec.add_dependency 'safe_values'
33
+
34
+ spec.add_dependency 'concurrent-ruby'
35
+ spec.add_dependency 'jbuilder'
36
+ spec.add_dependency 'json_schema'
37
+ spec.add_dependency 'lazily'
38
+ spec.add_dependency 'oj'
39
+ spec.add_dependency 'renum'
40
+ spec.add_dependency 'rgl'
41
+
42
+ spec.add_development_dependency 'appraisal'
43
+ spec.add_development_dependency 'bundler'
44
+ spec.add_development_dependency 'byebug'
45
+ spec.add_development_dependency 'method_source'
46
+ spec.add_development_dependency 'minitest-hooks'
47
+ spec.add_development_dependency 'pg'
48
+ spec.add_development_dependency 'pry'
49
+ spec.add_development_dependency 'rake'
50
+ spec.add_development_dependency 'rspec-expectations'
51
+ spec.add_development_dependency 'sqlite3'
51
52
  end
@@ -1,10 +1,12 @@
1
- require "iknow_view_models/version"
2
- require "view_model"
3
- require "view_model/controller"
4
- require "view_model/active_record"
5
- require "view_model/active_record/controller"
6
- require "view_model/active_record/singular_nested_controller"
7
- require "view_model/active_record/collection_nested_controller"
1
+ # frozen_string_literal: true
2
+
3
+ require 'iknow_view_models/version'
4
+ require 'view_model'
5
+ require 'view_model/controller'
6
+ require 'view_model/active_record'
7
+ require 'view_model/active_record/controller'
8
+ require 'view_model/active_record/singular_nested_controller'
9
+ require 'view_model/active_record/collection_nested_controller'
8
10
 
9
11
  module IknowViewModels
10
12
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IknowViewModels
4
- VERSION = '3.2.0'
4
+ VERSION = '3.2.1'
5
5
  end
@@ -6,19 +6,19 @@ require 'jbuilder'
6
6
  require 'deep_preloader'
7
7
 
8
8
  class ViewModel
9
- REFERENCE_ATTRIBUTE = "_ref"
10
- ID_ATTRIBUTE = "id"
11
- TYPE_ATTRIBUTE = "_type"
12
- VERSION_ATTRIBUTE = "_version"
13
- NEW_ATTRIBUTE = "_new"
9
+ REFERENCE_ATTRIBUTE = '_ref'
10
+ ID_ATTRIBUTE = 'id'
11
+ TYPE_ATTRIBUTE = '_type'
12
+ VERSION_ATTRIBUTE = '_version'
13
+ NEW_ATTRIBUTE = '_new'
14
14
 
15
15
  # Migrations leave a metadata attribute _migrated on any views that they
16
16
  # alter. This attribute is accessible as metadata when deserializing migrated
17
17
  # input, and is included in the output serialization sent to clients.
18
- MIGRATED_ATTRIBUTE = "_migrated"
18
+ MIGRATED_ATTRIBUTE = '_migrated'
19
19
 
20
20
  Metadata = Struct.new(:id, :view_name, :schema_version, :new, :migrated) do
21
- alias :new? :new
21
+ alias_method :new?, :new
22
22
  end
23
23
 
24
24
  class << self
@@ -28,6 +28,7 @@ class ViewModel
28
28
  attr_writer :view_name
29
29
 
30
30
  def inherited(subclass)
31
+ super
31
32
  subclass.initialize_as_viewmodel
32
33
  end
33
34
 
@@ -43,6 +44,7 @@ class ViewModel
43
44
  # try to auto-detect based on class name
44
45
  match = /(.*)View$/.match(self.name)
45
46
  raise ArgumentError.new("Could not auto-determine ViewModel name from class name '#{self.name}'") if match.nil?
47
+
46
48
  ViewModel::Registry.default_view_name(match[1])
47
49
  end
48
50
  end
@@ -77,6 +79,7 @@ class ViewModel
77
79
  end
78
80
 
79
81
  attr_accessor attr
82
+
80
83
  define_method("deserialize_#{attr}") do |value, references: {}, deserialize_context: self.class.new_deserialize_context|
81
84
  self.public_send("#{attr}=", value)
82
85
  end
@@ -122,7 +125,7 @@ class ViewModel
122
125
  hash.delete(ViewModel::REFERENCE_ATTRIBUTE)
123
126
  end
124
127
 
125
- def is_update_hash?(hash)
128
+ def is_update_hash?(hash) # rubocop:disable Naming/PredicateName
126
129
  ViewModel::Schemas.verify_schema!(ViewModel::Schemas::VIEWMODEL_UPDATE, hash)
127
130
  hash.has_key?(ViewModel::ID_ATTRIBUTE) &&
128
131
  !hash.fetch(ViewModel::ActiveRecord::NEW_ATTRIBUTE, false)
@@ -198,12 +201,12 @@ class ViewModel
198
201
  end
199
202
 
200
203
  member_names.each do |attr|
201
- if view_hash.has_key?(attr)
202
- viewmodel.public_send("deserialize_#{attr}",
203
- view_hash[attr],
204
- references: references,
205
- deserialize_context: deserialize_context)
206
- end
204
+ next unless view_hash.has_key?(attr)
205
+
206
+ viewmodel.public_send("deserialize_#{attr}",
207
+ view_hash[attr],
208
+ references: references,
209
+ deserialize_context: deserialize_context)
207
210
  end
208
211
 
209
212
  deserialize_context.run_callback(ViewModel::Callbacks::Hook::BeforeValidate, viewmodel)
@@ -13,11 +13,12 @@ require 'view_model/access_control_error'
13
13
  class ViewModel::AccessControl
14
14
  Result = Struct.new(:permit, :error) do
15
15
  def initialize(permit, error: nil)
16
- raise ArgumentError.new("Successful AccessControl::Result may not have an error") if permit && error
16
+ raise ArgumentError.new('Successful AccessControl::Result may not have an error') if permit && error
17
+
17
18
  super(permit, error)
18
19
  end
19
20
 
20
- alias :permit? :permit
21
+ alias_method :permit?, :permit
21
22
 
22
23
  # Merge this result with another access control result. Takes a block
23
24
  # returning a result, and returns a combined result for both tests. Access
@@ -129,6 +130,7 @@ class ViewModel::AccessControl
129
130
  if @initial_editability_store.has_key?(view.object_id)
130
131
  raise RuntimeError.new("Access control data already recorded for view #{view.to_reference}")
131
132
  end
133
+
132
134
  @initial_editability_store[view.object_id] = initial_editability
133
135
  end
134
136
 
@@ -136,6 +138,7 @@ class ViewModel::AccessControl
136
138
  unless @initial_editability_store.has_key?(view.object_id)
137
139
  raise RuntimeError.new("No access control data recorded for view #{view.to_reference}")
138
140
  end
141
+
139
142
  @initial_editability_store.delete(view.object_id)
140
143
  end
141
144
 
@@ -8,8 +8,9 @@
8
8
  class ViewModel::AccessControl::Composed < ViewModel::AccessControl
9
9
  ComposedResult = Struct.new(:allow, :veto, :allow_error, :veto_error) do
10
10
  def initialize(allow, veto, allow_error, veto_error)
11
- raise ArgumentError.new("Non-vetoing result may not have a veto error") if veto_error && !veto
12
- raise ArgumentError.new("Allowing result may not have a allow error") if allow_error && allow
11
+ raise ArgumentError.new('Non-vetoing result may not have a veto error') if veto_error && !veto
12
+ raise ArgumentError.new('Allowing result may not have a allow error') if allow_error && allow
13
+
13
14
  super
14
15
  end
15
16
 
@@ -64,7 +65,7 @@ class ViewModel::AccessControl::Composed < ViewModel::AccessControl
64
65
  attr_reader :reasons
65
66
 
66
67
  def initialize(nodes, reasons)
67
- super("Action not permitted because none of the possible conditions were met.", nodes)
68
+ super('Action not permitted because none of the possible conditions were met.', nodes)
68
69
  @reasons = reasons
69
70
  end
70
71
 
@@ -92,7 +93,7 @@ class ViewModel::AccessControl::Composed < ViewModel::AccessControl
92
93
  end
93
94
 
94
95
  def initialize_as_composed_access_control
95
- @included_checkers = []
96
+ @included_checkers = []
96
97
 
97
98
  @edit_valid_ifs = []
98
99
  @edit_valid_unlesses = []
@@ -152,15 +153,16 @@ class ViewModel::AccessControl::Composed < ViewModel::AccessControl
152
153
  @included_checkers.each do |ancestor|
153
154
  next unless visited.add?(ancestor)
154
155
  next if include_ancestor && !include_ancestor.call(ancestor)
156
+
155
157
  ancestor.each_check(check_name) { |x| yield x }
156
158
  end
157
159
  end
158
160
 
159
161
  def inspect
160
- s = super + "("
161
- s += inspect_checks.join(", ")
162
+ s = super + '('
163
+ s += inspect_checks.join(', ')
162
164
  s += " includes checkers: #{@included_checkers.inspect}" if @included_checkers.present?
163
- s += ")"
165
+ s += ')'
164
166
  s
165
167
  end
166
168
 
@@ -174,7 +176,6 @@ class ViewModel::AccessControl::Composed < ViewModel::AccessControl
174
176
  checks << "edit_valid_unless: #{@edit_valid_unlesses.map(&:reason)}" if @edit_valid_unlesses.present?
175
177
  checks
176
178
  end
177
-
178
179
  end
179
180
 
180
181
  # final
@@ -199,7 +200,7 @@ class ViewModel::AccessControl::Composed < ViewModel::AccessControl
199
200
 
200
201
  veto = vetoed_checker.present?
201
202
  if veto
202
- veto_error = vetoed_checker.error_type.new("Action not permitted because: " +
203
+ veto_error = vetoed_checker.error_type.new('Action not permitted because: ' +
203
204
  vetoed_checker.reason,
204
205
  env.view.blame_reference)
205
206
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ViewModel::AccessControl::Open < ViewModel::AccessControl
2
4
  def visible_check(_traversal_env)
3
5
  ViewModel::AccessControl::Result::PERMIT
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ViewModel::AccessControl::ReadOnly < ViewModel::AccessControl
2
4
  def visible_check(_traversal_env)
3
5
  ViewModel::AccessControl::Result::PERMIT
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ## Defines an access control discipline for a given action against a tree of
2
4
  ## viewmodels.
3
5
  ##
@@ -78,7 +80,7 @@ class ViewModel::AccessControl::Tree < ViewModel::AccessControl
78
80
  def initialize
79
81
  super()
80
82
  @always_policy_instance = self.class::AlwaysPolicy.new(self)
81
- @view_policy_instances = self.class.view_policies.each_with_object({}) { |(name, policy), h| h[name] = policy.new(self) }
83
+ @view_policy_instances = self.class.view_policies.transform_values { |policy| policy.new(self) }
82
84
  @root_visibility_store = {}
83
85
  @root_editability_store = {}
84
86
  end
@@ -98,27 +100,29 @@ class ViewModel::AccessControl::Tree < ViewModel::AccessControl
98
100
 
99
101
  def store_descendent_editability(view, descendent_editability)
100
102
  if @root_editability_store.has_key?(view.object_id)
101
- raise RuntimeError.new("Root access control data already saved for root")
103
+ raise RuntimeError.new('Root access control data already saved for root')
102
104
  end
105
+
103
106
  @root_editability_store[view.object_id] = descendent_editability
104
107
  end
105
108
 
106
109
  def fetch_descendent_editability(view)
107
110
  @root_editability_store.fetch(view.object_id) do
108
- raise RuntimeError.new("No root access control data recorded for root")
111
+ raise RuntimeError.new('No root access control data recorded for root')
109
112
  end
110
113
  end
111
114
 
112
115
  def store_descendent_visibility(view, descendent_visibility)
113
116
  if @root_visibility_store.has_key?(view.object_id)
114
- raise RuntimeError.new("Root access control data already saved for root")
117
+ raise RuntimeError.new('Root access control data already saved for root')
115
118
  end
119
+
116
120
  @root_visibility_store[view.object_id] = descendent_visibility
117
121
  end
118
122
 
119
123
  def fetch_descendent_visibility(view)
120
124
  @root_visibility_store.fetch(view.object_id) do
121
- raise RuntimeError.new("No root access control data recorded for root")
125
+ raise RuntimeError.new('No root access control data recorded for root')
122
126
  end
123
127
  end
124
128
 
@@ -152,6 +156,7 @@ class ViewModel::AccessControl::Tree < ViewModel::AccessControl
152
156
 
153
157
  def initialize_as_node
154
158
  @root = false
159
+
155
160
  @root_children_editable_ifs = []
156
161
  @root_children_editable_unlesses = []
157
162
  @root_children_visible_ifs = []
@@ -187,7 +192,7 @@ class ViewModel::AccessControl::Tree < ViewModel::AccessControl
187
192
  def inspect_checks
188
193
  checks = super
189
194
  if root?
190
- checks << "no root checks"
195
+ checks << 'no root checks'
191
196
  else
192
197
  checks << "root_children_visible_if: #{root_children_visible_ifs.map(&:reason)}" if root_children_visible_ifs.present?
193
198
  checks << "root_children_visible_unless: #{root_children_visible_unlesses.map(&:reason)}" if root_children_visible_unlesses.present?