lib/dynamoid/document.rb in dynamoid-3.3.0 vs lib/dynamoid/document.rb in dynamoid-3.4.0

- old
+ new

@@ -49,10 +49,17 @@ # @since 0.4.0 def write_capacity options[:write_capacity] || Dynamoid::Config.write_capacity end + + # Returns the billing (capacity) mode for this table. + # Could be either :provisioned or :on_demand + def capacity_mode + options[:capacity_mode] || Dynamoid::Config.capacity_mode + end + # Returns the field name used to support STI for this table. def inheritance_field options[:inheritance_field] || :type end @@ -136,16 +143,14 @@ @new_record = true @attributes ||= {} @associations ||= {} @attributes_before_type_cast ||= {} - attrs_with_defaults = self.class.attributes.reduce({}) do |res, (attribute, options)| + attrs_with_defaults = self.class.attributes.each_with_object({}) do |(attribute, options), res| if attrs.key?(attribute) - res.merge(attribute => attrs[attribute]) + res[attribute] = attrs[attribute] elsif options.key?(:default) - res.merge(attribute => evaluate_default_value(options[:default])) - else - res + res[attribute] = evaluate_default_value(options[:default]) end end attrs_virtual = attrs.slice(*(attrs.keys - self.class.attributes.keys))