volt 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +56 -0
  3. data/CHANGELOG.md +4 -0
  4. data/Rakefile +0 -1
  5. data/app/volt/models/user.rb +1 -3
  6. data/app/volt/tasks/live_query/live_query.rb +1 -1
  7. data/app/volt/tasks/store_tasks.rb +4 -5
  8. data/app/volt/tasks/user_tasks.rb +1 -1
  9. data/lib/volt.rb +2 -6
  10. data/lib/volt/boot.rb +0 -2
  11. data/lib/volt/cli.rb +0 -1
  12. data/lib/volt/cli/asset_compile.rb +0 -2
  13. data/lib/volt/cli/console.rb +3 -4
  14. data/lib/volt/cli/generate.rb +3 -4
  15. data/lib/volt/cli/new_gem.rb +1 -3
  16. data/lib/volt/controllers/actions.rb +6 -6
  17. data/lib/volt/controllers/model_controller.rb +4 -8
  18. data/lib/volt/data_stores/base.rb +1 -2
  19. data/lib/volt/data_stores/data_store.rb +2 -2
  20. data/lib/volt/data_stores/mongo_driver.rb +3 -3
  21. data/lib/volt/extra_core/hash.rb +1 -1
  22. data/lib/volt/extra_core/inflector/inflections.rb +10 -2
  23. data/lib/volt/extra_core/logger.rb +1 -4
  24. data/lib/volt/extra_core/object.rb +1 -1
  25. data/lib/volt/models.rb +2 -4
  26. data/lib/volt/models/array_model.rb +3 -7
  27. data/lib/volt/models/associations.rb +5 -4
  28. data/lib/volt/models/buffer.rb +1 -2
  29. data/lib/volt/models/dirty.rb +2 -2
  30. data/lib/volt/models/errors.rb +1 -1
  31. data/lib/volt/models/listener_tracker.rb +1 -3
  32. data/lib/volt/models/model.rb +16 -20
  33. data/lib/volt/models/permissions.rb +15 -18
  34. data/lib/volt/models/persistors/array_store.rb +5 -10
  35. data/lib/volt/models/persistors/cookies.rb +2 -2
  36. data/lib/volt/models/persistors/model_store.rb +3 -9
  37. data/lib/volt/models/persistors/params.rb +1 -3
  38. data/lib/volt/models/persistors/query/normalizer.rb +3 -3
  39. data/lib/volt/models/persistors/query/query_listener.rb +1 -1
  40. data/lib/volt/models/persistors/store.rb +2 -2
  41. data/lib/volt/models/state_helpers.rb +1 -1
  42. data/lib/volt/models/state_manager.rb +4 -4
  43. data/lib/volt/models/url.rb +2 -6
  44. data/lib/volt/models/validations.rb +8 -13
  45. data/lib/volt/models/validators/numericality_validator.rb +2 -6
  46. data/lib/volt/models/validators/unique_validator.rb +1 -1
  47. data/lib/volt/models/validators/user_validation.rb +0 -1
  48. data/lib/volt/page/bindings/attribute_binding.rb +9 -19
  49. data/lib/volt/page/bindings/content_binding.rb +1 -1
  50. data/lib/volt/page/bindings/each_binding.rb +3 -4
  51. data/lib/volt/page/bindings/if_binding.rb +1 -1
  52. data/lib/volt/page/bindings/view_binding.rb +15 -22
  53. data/lib/volt/page/bindings/view_binding/controller_handler.rb +5 -7
  54. data/lib/volt/page/bindings/view_binding/view_lookup_for_path.rb +1 -2
  55. data/lib/volt/page/bindings/yield_binding.rb +1 -2
  56. data/lib/volt/page/channel.rb +3 -3
  57. data/lib/volt/page/document_events.rb +1 -1
  58. data/lib/volt/page/page.rb +3 -6
  59. data/lib/volt/page/path_string_renderer.rb +7 -8
  60. data/lib/volt/page/sub_context.rb +1 -3
  61. data/lib/volt/page/targets/binding_document/component_node.rb +1 -3
  62. data/lib/volt/page/tasks.rb +3 -5
  63. data/lib/volt/reactive/class_eventable.rb +2 -2
  64. data/lib/volt/reactive/computation.rb +7 -7
  65. data/lib/volt/reactive/dependency.rb +1 -1
  66. data/lib/volt/reactive/eventable.rb +3 -4
  67. data/lib/volt/reactive/reactive_accessors.rb +0 -1
  68. data/lib/volt/reactive/reactive_array.rb +4 -12
  69. data/lib/volt/router/routes.rb +1 -3
  70. data/lib/volt/server.rb +6 -6
  71. data/lib/volt/server/component_handler.rb +1 -1
  72. data/lib/volt/server/component_templates.rb +2 -2
  73. data/lib/volt/server/forking_server.rb +6 -9
  74. data/lib/volt/server/html_parser/component_view_scope.rb +2 -2
  75. data/lib/volt/server/html_parser/each_scope.rb +1 -1
  76. data/lib/volt/server/html_parser/sandlebars_parser.rb +2 -6
  77. data/lib/volt/server/html_parser/view_handler.rb +1 -1
  78. data/lib/volt/server/html_parser/view_parser.rb +1 -1
  79. data/lib/volt/server/html_parser/view_scope.rb +2 -4
  80. data/lib/volt/server/rack/asset_files.rb +1 -3
  81. data/lib/volt/server/rack/component_paths.rb +1 -3
  82. data/lib/volt/server/rack/http_request.rb +1 -3
  83. data/lib/volt/server/rack/http_resource.rb +1 -3
  84. data/lib/volt/server/rack/http_response_renderer.rb +2 -2
  85. data/lib/volt/server/rack/index_files.rb +1 -1
  86. data/lib/volt/server/rack/opal_files.rb +1 -3
  87. data/lib/volt/server/socket_connection_handler.rb +1 -3
  88. data/lib/volt/server/websocket/rack_server_adaptor.rb +1 -1
  89. data/lib/volt/server/websocket/websocket_handler.rb +1 -2
  90. data/lib/volt/spec/capybara.rb +1 -1
  91. data/lib/volt/spec/setup.rb +18 -12
  92. data/lib/volt/tasks/dispatcher.rb +1 -2
  93. data/lib/volt/tasks/task_handler.rb +1 -3
  94. data/lib/volt/utils/boolean_patch.rb +1 -1
  95. data/lib/volt/utils/event_counter.rb +2 -2
  96. data/lib/volt/utils/generic_pool.rb +5 -9
  97. data/lib/volt/utils/logging/task_argument_filterer.rb +4 -4
  98. data/lib/volt/utils/logging/task_logger.rb +2 -2
  99. data/lib/volt/utils/modes.rb +2 -2
  100. data/lib/volt/utils/promise_patch.rb +1 -2
  101. data/lib/volt/utils/read_write_lock.rb +21 -23
  102. data/lib/volt/utils/tilt_patch.rb +1 -1
  103. data/lib/volt/utils/timers.rb +3 -7
  104. data/lib/volt/utils/volt_user_error.rb +1 -1
  105. data/lib/volt/version.rb +2 -2
  106. data/lib/volt/volt/app.rb +4 -6
  107. data/lib/volt/volt/users.rb +4 -3
  108. data/spec/apps/kitchen_sink/app/main/controllers/main_controller.rb +1 -1
  109. data/spec/apps/kitchen_sink/app/main/controllers/server/simple_http_controller.rb +1 -1
  110. data/spec/apps/kitchen_sink/app/main/controllers/todos_controller.rb +5 -5
  111. data/spec/apps/kitchen_sink/app/main/controllers/upload_controller.rb +1 -1
  112. data/spec/apps/kitchen_sink/app/main/controllers/yield_component_controller.rb +1 -1
  113. data/spec/controllers/actions_spec.rb +9 -10
  114. data/spec/controllers/model_controller_spec.rb +1 -1
  115. data/spec/extra_core/blank_spec.rb +2 -2
  116. data/spec/extra_core/logger_spec.rb +6 -8
  117. data/spec/extra_core/string_transformations_spec.rb +3 -3
  118. data/spec/integration/bindings_spec.rb +3 -9
  119. data/spec/integration/first_last_spec.rb +1 -1
  120. data/spec/integration/missing_spec.rb +1 -2
  121. data/spec/integration/raw_html_binding.rb +2 -2
  122. data/spec/integration/todos_spec.rb +22 -0
  123. data/spec/integration/yield_spec.rb +2 -2
  124. data/spec/models/associations_spec.rb +4 -4
  125. data/spec/models/buffer_spec.rb +2 -2
  126. data/spec/models/dirty_spec.rb +10 -11
  127. data/spec/models/model_spec.rb +19 -13
  128. data/spec/models/model_state_spec.rb +1 -1
  129. data/spec/models/permissions_spec.rb +8 -12
  130. data/spec/models/url_spec.rb +1 -1
  131. data/spec/models/user_spec.rb +17 -10
  132. data/spec/models/user_validation_spec.rb +2 -3
  133. data/spec/models/validations_spec.rb +7 -10
  134. data/spec/models/validators/email_validator_spec.rb +5 -7
  135. data/spec/models/validators/format_validator_spec.rb +21 -3
  136. data/spec/models/validators/length_validator_spec.rb +12 -22
  137. data/spec/models/validators/shared_examples_for_validators.rb +1 -1
  138. data/spec/models/validators/unique_validator_spec.rb +1 -2
  139. data/spec/page/bindings/content_binding_spec.rb +1 -1
  140. data/spec/page/bindings/template_binding/view_lookup_for_path_spec.rb +0 -1
  141. data/spec/page/path_string_renderer_spec.rb +2 -3
  142. data/spec/reactive/class_eventable_spec.rb +1 -1
  143. data/spec/reactive/computation_spec.rb +30 -31
  144. data/spec/reactive/reactive_hash_spec.rb +1 -1
  145. data/spec/router/routes_spec.rb +14 -16
  146. data/spec/server/html_parser/view_handler_spec.rb +1 -1
  147. data/spec/server/html_parser/view_parser_spec.rb +0 -1
  148. data/spec/server/rack/quite_common_logger_spec.rb +3 -3
  149. data/spec/tasks/dispatcher_spec.rb +1 -1
  150. data/spec/tasks/query_tracker_spec.rb +1 -3
  151. data/spec/utils/task_argument_filtererer_spec.rb +5 -5
  152. data/templates/project/app/main/controllers/main_controller.rb +1 -1
  153. data/templates/project/spec/app/main/models/sample_model_spec.rb +2 -2
  154. data/templates/project/spec/app/main/tasks/sample_task_spec.rb +2 -2
  155. data/volt.gemspec +3 -5
  156. metadata +19 -4
@@ -21,7 +21,7 @@ else
21
21
 
22
22
  module Volt
23
23
  class VoltLogger < Logger
24
- def initialize(current={})
24
+ def initialize(current = {})
25
25
  super(STDOUT)
26
26
  @current = current
27
27
  @formatter = Volt::VoltLoggerFormatter.new
@@ -38,7 +38,6 @@ else
38
38
  level = error ? Logger::ERROR : Logger::INFO
39
39
  text = TaskLogger.task_dispatch_message(self, args)
40
40
 
41
-
42
41
  if error
43
42
  text += "\n" + colorize(error.to_s, :red)
44
43
  if error.is_a?(Exception) && !error.is_a?(VoltUserError)
@@ -47,7 +46,6 @@ else
47
46
  end
48
47
 
49
48
  log(level, text)
50
-
51
49
  end
52
50
 
53
51
  def args
@@ -70,7 +68,6 @@ else
70
68
  Volt.logger.info(colorize(msg, color))
71
69
  end
72
70
 
73
-
74
71
  private
75
72
 
76
73
  def colorize(string, color)
@@ -13,7 +13,7 @@ class Object
13
13
  # TODO: Need a real implementation of this
14
14
  def deep_clone
15
15
  if RUBY_PLATFORM == 'opal'
16
- JSON.parse(self.to_json)
16
+ JSON.parse(to_json)
17
17
  else
18
18
  Marshal.load(Marshal.dump(self))
19
19
  end
data/lib/volt/models.rb CHANGED
@@ -5,9 +5,7 @@ require 'volt/models/persistors/store_factory'
5
5
  require 'volt/models/persistors/array_store'
6
6
  require 'volt/models/persistors/model_store'
7
7
  require 'volt/models/persistors/params'
8
- if RUBY_PLATFORM == 'opal'
9
- require 'volt/models/persistors/cookies'
10
- end
8
+ require 'volt/models/persistors/cookies' if RUBY_PLATFORM == 'opal'
11
9
  require 'volt/models/persistors/flash'
12
10
  require 'volt/models/persistors/local_store'
13
11
  if RUBY_PLATFORM == 'opal'
@@ -20,4 +18,4 @@ else
20
18
  require(gem_dir + '/stdlib/promise')
21
19
  end
22
20
  # TODO: remove once https://github.com/opal/opal/pull/725 is released.
23
- require 'volt/utils/promise_patch'
21
+ require 'volt/utils/promise_patch'
@@ -11,7 +11,6 @@ module Volt
11
11
  include StateManager
12
12
  include StateHelpers
13
13
 
14
-
15
14
  attr_reader :parent, :path, :persistor, :options, :array
16
15
 
17
16
  # For many methods, we want to call load data as soon as the model is interacted
@@ -74,7 +73,7 @@ module Volt
74
73
  end
75
74
 
76
75
  if model.is_a?(Model) && !model.can_create?
77
- raise "permissions did not allow create for #{model.inspect}"
76
+ fail "permissions did not allow create for #{model.inspect}"
78
77
  end
79
78
 
80
79
  super(model)
@@ -135,7 +134,6 @@ module Volt
135
134
  self[0]
136
135
  end
137
136
 
138
-
139
137
  # returns a promise to fetch the first instance
140
138
  def fetch_first(&block)
141
139
  persistor = self.persistor
@@ -201,7 +199,7 @@ module Volt
201
199
  end
202
200
  end
203
201
 
204
- def buffer(attrs={})
202
+ def buffer(attrs = {})
205
203
  model_path = options[:path] + [:[]]
206
204
  model_klass = Volt::Model.class_at_path(model_path)
207
205
 
@@ -215,9 +213,7 @@ module Volt
215
213
 
216
214
  # Takes the persistor if there is one and
217
215
  def setup_persistor(persistor)
218
- if persistor
219
- @persistor = persistor.new(self)
220
- end
216
+ @persistor = persistor.new(self) if persistor
221
217
  end
222
218
  end
223
219
  end
@@ -1,7 +1,7 @@
1
1
  module Volt
2
2
  module Associations
3
3
  module ClassMethods
4
- def belongs_to(method_name, key_name=nil)
4
+ def belongs_to(method_name, key_name = nil)
5
5
  # getter
6
6
  define_method(method_name) do
7
7
  association_with_root_model('belongs_to') do |root|
@@ -9,15 +9,15 @@ module Volt
9
9
  lookup_key = send(:"_#{key_name || method_name}_id")
10
10
 
11
11
  # Return a promise for the belongs_to
12
- root.send(:"_#{method_name.pluralize}").where(:_id => lookup_key).fetch_first
12
+ root.send(:"_#{method_name.pluralize}").where(_id: lookup_key).fetch_first
13
13
  end
14
14
  end
15
15
  end
16
16
 
17
- def has_many(method_name, remote_key_name=nil)
17
+ def has_many(method_name, remote_key_name = nil)
18
18
  define_method(method_name) do
19
19
  association_with_root_model('has_many') do |root|
20
- id = self._id
20
+ id = _id
21
21
 
22
22
  # The key will be "{this class name}_id"
23
23
  remote_key_name ||= :"#{path[-2].singularize}_id"
@@ -33,6 +33,7 @@ module Volt
33
33
  end
34
34
 
35
35
  private
36
+
36
37
  # Currently the has_many and belongs_to associations only work on the store collection,
37
38
  # this method checks to make sure we are on store and returns the root reference to it.
38
39
  def association_with_root_model(method_name)
@@ -7,8 +7,7 @@ module Volt
7
7
  def save!(&block)
8
8
  # TODO: this shouldn't need to be run, but if no attributes are assigned, then
9
9
  # if needs to be run. Maybe there's a better way to handle it.
10
- return validate!.then do
11
-
10
+ validate!.then do
12
11
  # Get errors from validate
13
12
  errors = self.errors.to_h
14
13
 
@@ -8,7 +8,7 @@ module Volt
8
8
  end
9
9
 
10
10
  # Return true if key has changed
11
- def changed?(key=nil)
11
+ def changed?(key = nil)
12
12
  if key
13
13
  # return the changed values for the keys
14
14
  changed_attributes.key?(key)
@@ -85,4 +85,4 @@ module Volt
85
85
  super
86
86
  end
87
87
  end
88
- end
88
+ end
@@ -29,4 +29,4 @@ module Volt
29
29
  str.join
30
30
  end
31
31
  end
32
- end
32
+ end
@@ -1,7 +1,6 @@
1
1
  module Volt
2
2
  # Included in model's so they can inform the ArrayModel when new listeners are added or removed.
3
3
  module ListenerTracker
4
-
5
4
  # Called when data from this model begins being watched
6
5
  def listener_added
7
6
  @listener_count ||= 0
@@ -12,6 +11,5 @@ module Volt
12
11
  @listener_count ||= 0
13
12
  @listener_count -= 1
14
13
  end
15
-
16
14
  end
17
- end
15
+ end
@@ -49,11 +49,11 @@ module Volt
49
49
  attr_reader :attributes, :parent, :path, :persistor, :options
50
50
 
51
51
  INVALID_FIELD_NAMES = {
52
- :attributes => true,
53
- :parent => true,
54
- :path => true,
55
- :options => true,
56
- :persistor => true
52
+ attributes: true,
53
+ parent: true,
54
+ path: true,
55
+ options: true,
56
+ persistor: true
57
57
  }
58
58
 
59
59
  def initialize(attributes = {}, options = {}, initial_state = nil)
@@ -126,7 +126,7 @@ module Volt
126
126
  end
127
127
 
128
128
  # Assign multiple attributes as a hash, directly.
129
- def assign_attributes(attrs, initial_setup=false, skip_changes=false)
129
+ def assign_attributes(attrs, initial_setup = false, skip_changes = false)
130
130
  @attributes ||= {}
131
131
 
132
132
  attrs = wrap_values(attrs)
@@ -227,9 +227,7 @@ module Volt
227
227
 
228
228
  @deps.changed!(attribute_name)
229
229
 
230
- if old_value == nil || new_value == nil
231
- @size_dep.changed!
232
- end
230
+ @size_dep.changed! if old_value.nil? || new_value.nil?
233
231
 
234
232
  # TODO: Can we make this so it doesn't need to be handled for non store collections
235
233
  # (maybe move it to persistor, though thats weird since buffers don't have a persistor)
@@ -246,7 +244,7 @@ module Volt
246
244
  # 1) a nil model, which returns a wrapped error
247
245
  # 2) reading directly from attributes
248
246
  # 3) trying to read a key that doesn't exist.
249
- def get(attr_name, expand=false)
247
+ def get(attr_name, expand = false)
250
248
  # Reading an attribute, we may get back a nil model.
251
249
  attr_name = attr_name.to_sym
252
250
 
@@ -286,7 +284,7 @@ module Volt
286
284
  end
287
285
  end
288
286
 
289
- def respond_to_missing?(method_name, include_private=false)
287
+ def respond_to_missing?(method_name, include_private = false)
290
288
  method_name.to_s.start_with?('_') || super
291
289
  end
292
290
 
@@ -343,7 +341,7 @@ module Volt
343
341
  # Wrap result in a promise if it isn't one
344
342
  return Promise.new.then { result }
345
343
  else
346
- fail "Model does not have a parent and cannot be deleted."
344
+ fail 'Model does not have a parent and cannot be deleted.'
347
345
  end
348
346
  end
349
347
 
@@ -355,12 +353,13 @@ module Volt
355
353
  end
356
354
 
357
355
  private
356
+
358
357
  # Volt provides a few access methods to get more data about the model,
359
358
  # we want to prevent these from being assigned or accessed through
360
359
  # underscore methods.
361
360
  def check_valid_field_name(name)
362
361
  if INVALID_FIELD_NAMES[name]
363
- raise InvalidFieldName, "`#{name}` is reserved and can not be used as a field"
362
+ fail InvalidFieldName, "`#{name}` is reserved and can not be used as a field"
364
363
  end
365
364
  end
366
365
 
@@ -377,13 +376,11 @@ module Volt
377
376
 
378
377
  # Takes the persistor if there is one and
379
378
  def setup_persistor(persistor)
380
- if persistor
381
- @persistor = persistor.new(self)
382
- end
379
+ @persistor = persistor.new(self) if persistor
383
380
  end
384
381
 
385
382
  # Used internally from other methods that assign all attributes
386
- def assign_all_attributes(attrs, track_changes=false)
383
+ def assign_all_attributes(attrs, track_changes = false)
387
384
  # Assign each attribute using setters
388
385
  attrs.each_pair do |key, value|
389
386
  key = key.to_sym
@@ -408,7 +405,7 @@ module Volt
408
405
  #
409
406
  # @return [Promise|nil] a promise for when the save is
410
407
  # complete
411
- def run_changed(attribute_name=nil)
408
+ def run_changed(attribute_name = nil)
412
409
  # no_validate mode should only be used internally. no_validate mode is a
413
410
  # performance optimization that prevents validation from running after each
414
411
  # change when assigning multile attributes.
@@ -416,7 +413,6 @@ module Volt
416
413
  # Run the validations for all fields
417
414
  result = nil
418
415
  return validate!.then do
419
-
420
416
  # Buffers are allowed to be in an invalid state
421
417
  unless buffer?
422
418
  # First check that all local validations pass
@@ -458,7 +454,7 @@ module Volt
458
454
  end
459
455
 
460
456
  # Didn't run validations
461
- return nil
457
+ nil
462
458
  end
463
459
  end
464
460
  end
@@ -1,6 +1,5 @@
1
1
  module Volt
2
2
  class Model
3
-
4
3
  # The permissions module provides helpers for working with Volt permissions.
5
4
  module Permissions
6
5
  module ClassMethods
@@ -9,7 +8,7 @@ module Volt
9
8
  # the user can not be changed.
10
9
  #
11
10
  # @param key [Symbol] the name of the attribute to store
12
- def own_by_user(key=:user_id)
11
+ def own_by_user(key = :user_id)
13
12
  # When the model is created, assign it the user_id (if the user is logged in)
14
13
  on(:new) do
15
14
  # Only assign the user_id if there isn't already one and the user is logged in.
@@ -29,12 +28,11 @@ module Volt
29
28
  # for a nil model.
30
29
  unless @attributes[:user_id]
31
30
  # Show an error that the user is not logged in
32
- next {key => ['requires a logged in user']}
31
+ next { key => ['requires a logged in user'] }
33
32
  end
34
33
  end
35
34
  end
36
35
 
37
-
38
36
  # TODO: Change to
39
37
  # permissions(:create, :read, :update) do |action|
40
38
  # if owner?
@@ -81,7 +79,7 @@ module Volt
81
79
  end
82
80
  end
83
81
  else
84
- raise "allow should be called inside of a permissions block"
82
+ fail 'allow should be called inside of a permissions block'
85
83
  end
86
84
  end
87
85
 
@@ -97,7 +95,7 @@ module Volt
97
95
  end
98
96
  end
99
97
  else
100
- raise "deny should be called inside of a permissions block"
98
+ fail 'deny should be called inside of a permissions block'
101
99
  end
102
100
  end
103
101
 
@@ -105,10 +103,10 @@ module Volt
105
103
  # in user (```Volt.current_user```) is the owner of this instance.
106
104
  #
107
105
  # @param key [Symbol] the name of the attribute where the user_id is stored
108
- def owner?(key=:user_id)
106
+ def owner?(key = :user_id)
109
107
  # Lookup the original user_id
110
108
  owner_id = was(key) || send(:"_#{key}")
111
- owner_id != nil && owner_id == Volt.current_user_id
109
+ !owner_id.nil? && owner_id == Volt.current_user_id
112
110
  end
113
111
 
114
112
  # Returns boolean if the model can be deleted
@@ -134,7 +132,7 @@ module Volt
134
132
 
135
133
  clear_allow_and_deny
136
134
 
137
- return !deny
135
+ !deny
138
136
  end
139
137
 
140
138
  # Return the list of allowed fields
@@ -145,7 +143,7 @@ module Volt
145
143
 
146
144
  clear_allow_and_deny
147
145
 
148
- return result
146
+ result
149
147
  end
150
148
 
151
149
  # Filter fields returns the attributes with any denied or not allowed fields
@@ -161,21 +159,22 @@ module Volt
161
159
  allow << :_id
162
160
 
163
161
  # Only keep fields in the allow list
164
- return @attributes.select {|key| allow.include?(key) }
162
+ return @attributes.select { |key| allow.include?(key) }
165
163
  elsif deny == true
166
164
  # Only keep id
167
165
  # TODO: Should this be a full reject?
168
- return @attributes.reject {|key| key != :_id }
166
+ return @attributes.reject { |key| key != :_id }
169
167
  elsif deny && deny.size > 0
170
168
  # Reject any in the deny list
171
- return @attributes.reject {|key| deny.include?(key) }
169
+ return @attributes.reject { |key| deny.include?(key) }
172
170
  else
173
171
  return @attributes
174
172
  end
175
173
  end
176
174
 
177
175
  private
178
- def run_permissions(action_name=nil)
176
+
177
+ def run_permissions(action_name = nil)
179
178
  compute_allow_and_deny(action_name)
180
179
 
181
180
  errors = {}
@@ -199,9 +198,7 @@ module Volt
199
198
  elsif @__deny_fields
200
199
  # Allow all except the denied
201
200
  @__deny_fields.each do |field_name|
202
- if changed?(field_name)
203
- add_error_if_changed(errors, field_name)
204
- end
201
+ add_error_if_changed(errors, field_name) if changed?(field_name)
205
202
  end
206
203
  end
207
204
 
@@ -244,4 +241,4 @@ module Volt
244
241
  end
245
242
  end
246
243
  end
247
- end
244
+ end
@@ -50,23 +50,19 @@ module Volt
50
50
  end
51
51
 
52
52
  def inspect
53
- "<#{self.class.to_s}:#{object_id} #{@model.path.inspect} #{@query.inspect}>"
53
+ "<#{self.class}:#{object_id} #{@model.path.inspect} #{@query.inspect}>"
54
54
  end
55
55
 
56
56
  # Called when an each binding is listening
57
57
  def event_added(event, first, first_for_event)
58
58
  # First event, we load the data.
59
- if first
60
- @listener_event_counter.add
61
- end
59
+ @listener_event_counter.add if first
62
60
  end
63
61
 
64
62
  # Called when an each binding stops listening
65
63
  def event_removed(event, last, last_for_event)
66
64
  # Remove listener where there are no more events on this model
67
- if last
68
- @listener_event_counter.remove
69
- end
65
+ @listener_event_counter.remove if last
70
66
  end
71
67
 
72
68
  # Called by child models to track their listeners
@@ -141,7 +137,7 @@ module Volt
141
137
  if parent && (attrs = parent.attributes) && attrs[:_id]
142
138
  query = query.dup
143
139
 
144
- query << [:find, {:"#{@model.path[-3].singularize}_id" => attrs[:_id]}]
140
+ query << [:find, { :"#{@model.path[-3].singularize}_id" => attrs[:_id] }]
145
141
  end
146
142
  end
147
143
 
@@ -203,13 +199,12 @@ module Volt
203
199
  if @model.loaded_state == :loaded
204
200
  promise.resolve(@model)
205
201
  else
206
- Proc.new do |comp|
202
+ proc do |comp|
207
203
  if @model.loaded_state == :loaded
208
204
  promise.resolve(@model)
209
205
 
210
206
  comp.stop
211
207
  end
212
-
213
208
  end.watch!
214
209
  end
215
210