lib/volt/models/persistors/model_store.rb in volt-0.8.15 vs lib/volt/models/persistors/model_store.rb in volt-0.8.16
- old
+ new
@@ -4,11 +4,11 @@
module Volt
module Persistors
class ModelStore < Store
include StoreState
- ID_CHARS = [('a'..'f'), ('0'..'9')].map { |v| v.to_a }.flatten
+ ID_CHARS = [('a'..'f'), ('0'..'9')].map(&:to_a).flatten
attr_reader :model
attr_accessor :in_identity_map
def initialize(model, tasks)
@@ -47,15 +47,15 @@
# Create a random unique id that can be used as the mongo id as well
def generate_id
id = []
24.times { id << ID_CHARS.sample }
- return id.join
+ id.join
end
# Called when the model changes
- def changed(attribute_name=nil)
+ def changed(attribute_name = nil)
path = @model.path
promise = Promise.new
ensure_setup
@@ -65,12 +65,12 @@
if path_size > 3 && (parent = @model.parent) && (source = parent.parent)
@model.attributes[:"#{path[-4].singularize}_id"] = source._id
end
if !collection
- puts "Attempting to save model directly on store."
- raise "Attempting to save model directly on store."
+ puts 'Attempting to save model directly on store.'
+ fail 'Attempting to save model directly on store.'
else
StoreTasks.save(collection, self_attributes).then do |errors|
if errors.size == 0
promise.resolve(nil)
else
@@ -101,13 +101,14 @@
end
end
end
def [](val)
- raise "Models do not support hash style lookup. Hashes inserted into other models are converted to models, see https://github.com/voltrb/volt#automatic-model-conversion"
+ fail 'Models do not support hash style lookup. Hashes inserted into other models are converted to models, see https://github.com/voltrb/volt#automatic-model-conversion'
end
private
+
# Return the attributes that are only for this store, not any sub-associations.
def self_attributes
# Don't store any sub-stores, those will do their own saving.
@model.attributes.reject { |k, v| v.is_a?(Model) || v.is_a?(ArrayModel) }
end