Module: Denormalized::Core::ClassMethods
- Defined in:
- lib/denormalized/core.rb
Instance Method Summary collapse
- #denormalized_attribute?(name) ⇒ Boolean
- #update(id, attributes) ⇒ Object
- #update_all(updates) ⇒ Object
Instance Method Details
#denormalized_attribute?(name) ⇒ Boolean
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/denormalized/core.rb', line 119 def denormalized_attribute?(name) name = name.to_sym if name.is_a?(String) if name.is_a?(Symbol) return denormalized_configuration[:columns_hash][name] end Rails.logger.warn '[DENORMALIZED]: Symbol expected, instead received ' + name.class.to_s false end |
#update(id, attributes) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/denormalized/core.rb', line 130 def update(id, attributes) if attributes.keys.any? { |name| denormalized_attribute?(name) } subjects = base_class.where(id: id) # we will let super handle errors if subject doesn't exist if subjects.any? subjects.each do |subject| gifted_attributes = subject.extract_denormalized_attributes(attributes) denormalized_configuration[:tables].each do |table| subject.denormalized_action( table: table, where_attrs: subject.extract_existing_denormalized_attributes(attributes), method: :update, args: gifted_attributes ) end end end end super end |
#update_all(updates) ⇒ Object
153 154 155 156 157 158 159 |
# File 'lib/denormalized/core.rb', line 153 def update_all(updates) if updates.keys.any? { |name| denormalized_attribute?(name) } Rails.logger.warn '[DENORMALIZED]: Unable to update followers when using `update_all` -- orphans may have been created' end super end |