Module: PrintingPress::Model::InstanceMethods

Defined in:
lib/printing_press/publishable.rb

Instance Method Summary collapse

Instance Method Details

#destroyObject



60
61
62
63
# File 'lib/printing_press/publishable.rb', line 60

def destroy
	remove_published_version
	super
end

#publishObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/printing_press/publishable.rb', line 44

def publish
	return if published?
	
	remove_published_version if not published_version.nil?
	connection.insert("INSERT INTO #{self.class.published_table_name} SELECT * FROM #{self.class.reset_table_name} WHERE id = #{self.id}")
	
	# We need to handle belongs_to dependencies as well
	self.class.dependencies.each do |dependency|
		self.try(dependency).try(:publish)
	end
end

#published?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/printing_press/publishable.rb', line 56

def published?
	not published_version.nil? and published_version.updated_at == self.updated_at
end

#published_atObject



65
66
67
# File 'lib/printing_press/publishable.rb', line 65

def published_at
	published_version.nil? ? nil : published_version.updated_at
end

#published_versionObject



40
41
42
# File 'lib/printing_press/publishable.rb', line 40

def published_version
	@published_version ||= self.class.find_by_sql("SELECT * FROM #{self.class.published_table_name} WHERE id = #{self.id}").first
end