Module: HasPublishing::InstanceMethods
- Defined in:
- lib/has_publishing/instance_methods.rb
Instance Method Summary collapse
- #draft? ⇒ Boolean
- #ever_published? ⇒ Boolean
- #publish!(extra_attrs = {}) ⇒ Object
- #published? ⇒ Boolean
- #under_embargo? ⇒ Boolean
- #withdraw!(extra_attrs = {}) ⇒ Object
- #withdrawn? ⇒ Boolean
Instance Method Details
#draft? ⇒ Boolean
41 42 43 |
# File 'lib/has_publishing/instance_methods.rb', line 41 def draft? kind == 'draft' end |
#ever_published? ⇒ Boolean
53 54 55 |
# File 'lib/has_publishing/instance_methods.rb', line 53 def ever_published? published? || withdrawn? end |
#publish!(extra_attrs = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/has_publishing/instance_methods.rb', line 13 def publish!(extra_attrs = {}) self.save! if self.new_record? self.class.unscoped { return false unless draft? if published.nil? # first time publishing published_obj = self.class.create!(attributes.merge(:kind => 'published', :published_at => Time.zone.now, :dirty => nil).merge(extra_attrs)) self.published_id = published_obj.id else published.update_attributes!(attributes.merge(:kind => 'published', :published_id => nil, :published_at => Time.zone.now, :dirty => nil).merge(extra_attrs)) end self.class. = false # want same updated_at self.save! # make sure this model is in sync update_attributes!(:published_at => published.published_at, :dirty => false, :updated_at => published.updated_at) self.class. = true return published } end |
#published? ⇒ Boolean
45 46 47 |
# File 'lib/has_publishing/instance_methods.rb', line 45 def published? self.class.unscoped { (draft? && published && published.kind == 'published') || kind == 'published' } end |
#under_embargo? ⇒ Boolean
57 58 59 |
# File 'lib/has_publishing/instance_methods.rb', line 57 def published? && && > Time.zone.now end |
#withdraw!(extra_attrs = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/has_publishing/instance_methods.rb', line 31 def withdraw!(extra_attrs = {}) self.class.unscoped { return false unless draft? && ever_published? self.class. = false # want same updated_at published.update_attributes!(:kind => 'withdrawn') and update_attributes!(published.attributes.merge({:kind => 'draft', :published_id => published_id, :published_at => nil, :dirty => false}).merge(extra_attrs)) self.class. = true return published } end |
#withdrawn? ⇒ Boolean
49 50 51 |
# File 'lib/has_publishing/instance_methods.rb', line 49 def withdrawn? self.class.unscoped { (draft? && published && published.kind == 'withdrawn') || kind == 'withdrawn' } end |