Class: Lca::ImpactSnapshot
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Lca::ImpactSnapshot
- Defined in:
- lib/lca/models/impact_snapshot.rb
Class Method Summary collapse
-
.owned_by(owner_id) ⇒ Object
pull data from owner’s partition.
- .table_name ⇒ Object
- .take!(impact) ⇒ Object
Class Method Details
.owned_by(owner_id) ⇒ Object
pull data from owner’s partition
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lca/models/impact_snapshot.rb', line 22 def self.owned_by(owner_id) return self if !owner_id.is_a? Integer partition_suffix = "_#{owner_id}" table = "#{ self.table_name }#{ partition_suffix }" ApplicationRecord.connection.schema_cache.clear! return self if !ApplicationRecord.connection.schema_cache.data_source_exists? table model_class = Class.new self original_class_name = self.name class_name = "#{name}#{partition_suffix}" model_class.define_singleton_method(:table_name) do table end model_class.define_singleton_method(:name) do class_name end model_class end |
.table_name ⇒ Object
5 6 7 8 |
# File 'lib/lca/models/impact_snapshot.rb', line 5 def self.table_name return "#{::ACTIVE_TREE_OPTIONS[:table_name]}_snapshots" if defined? ::ACTIVE_TREE_OPTIONS return "active_tree_snapshots" end |
.take!(impact) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/lca/models/impact_snapshot.rb', line 47 def self.take!(impact) return create( impact.attributes .deep_symbolize_keys .slice(:impact_amount, :impact_amount_previous, :impact_amount_unit, :impact_factor, :impact_precision, :owner_id, :owner_type) .merge( impact_id: impact.id ) ) end |