Class: Humpyard::Element

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/humpyard/element.rb

Overview

Humpyard::Element is a model of an element to display on a Humpyard::Page.

Constant Summary collapse

SHARED_STATES =

Elements can be shared on other pages. this adds #unshared?, #shared_on_siblings?, shared_on_children? getters plus #to_unshared, #to_shared_on_siblings, #to_shared_on_children “setters”

{ 
  :unshared => 0,
  :shared_on_siblings => 1,
  :shared_on_children => 2
}.each_pair do |key, value|
  define_method "#{key}?" do
    shared_state.to_i == value
  end
  define_method "to_#{key}" do
    update_attribute :shared_state, value.to_i unless state == value # no point in troubling the database if the state is already == value
  end
end

Instance Method Summary collapse

Instance Method Details

#last_modifiedObject

Return the logical modification time for the element.



48
49
50
51
52
# File 'app/models/humpyard/element.rb', line 48

def last_modified
  rails_root_mtime = Time.zone.at(::File.new("#{Rails.root}").mtime)
  timestamps = [rails_root_mtime, self.updated_at]
  timestamps.sort.last
end

#stamp_page_modified_nowObject



22
23
24
25
26
27
# File 'app/models/humpyard/element.rb', line 22

def stamp_page_modified_now
  # Set page's modified_at to now without changing it's last_updated_at column
  Page.update_all ['modified_at = ?', Time.now], ['id = ?', page.id]
  
  # TODO: set other pages' modified_at if element is shared
end