Class: Optimizable::Optimization

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/optimizable/optimization.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for(optimizable) ⇒ Object



8
9
10
# File 'app/models/optimizable/optimization.rb', line 8

def self.for(optimizable)
  self.where(:optimizable_id => optimizable.id, :optimizable_type => optimizable.class.to_s).first
end

Instance Method Details

#after_initializeObject



12
13
14
15
16
17
# File 'app/models/optimizable/optimization.rb', line 12

def after_initialize
  self.data ||= {}
  Optimizable.options.each do |option|
    self.data[option] = nil
  end
end

#get(key) ⇒ Object



19
20
21
# File 'app/models/optimizable/optimization.rb', line 19

def get key
  self.data[key]
end

#human_optimizableObject



23
24
25
# File 'app/models/optimizable/optimization.rb', line 23

def human_optimizable
  [optimizable.try(:title) || optimizable.try(:name) || optimizable.try(:id), optimizable.class.to_s].join(' ').downcase
end