Module: Pubdraft::InstanceMethods

Defined in:
lib/pubdraft.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/pubdraft.rb', line 5

def self.included(base)
  base.send :before_create, :set_pubdraft_state
  base.attr_accessible :state

  base.scope :published, base.where(:state => 'published')
  base.scope :drafted,   base.where(:state => 'drafted')
end

Instance Method Details

#draftObject



33
34
35
# File 'lib/pubdraft.rb', line 33

def draft
  self.state = 'drafted'
end

#draft!Object



29
30
31
# File 'lib/pubdraft.rb', line 29

def draft!
  draft && save
end

#drafted?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/pubdraft.rb', line 17

def drafted?
  state == 'drafted'
end

#publishObject



25
26
27
# File 'lib/pubdraft.rb', line 25

def publish
  self.state = 'published'
end

#publish!Object



21
22
23
# File 'lib/pubdraft.rb', line 21

def publish!
  publish && save
end

#published?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/pubdraft.rb', line 13

def published?
  state == 'published'
end