Class: Pageflow::DraftEntry

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Conversion
Defined in:
app/models/pageflow/draft_entry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry, draft = nil) ⇒ DraftEntry

Returns a new instance of DraftEntry.



23
24
25
26
# File 'app/models/pageflow/draft_entry.rb', line 23

def initialize(entry, draft = nil)
  @entry = entry
  @draft = draft || entry.draft
end

Instance Attribute Details

#draftObject (readonly)

Returns the value of attribute draft.



5
6
7
# File 'app/models/pageflow/draft_entry.rb', line 5

def draft
  @draft
end

#entryObject (readonly)

Returns the value of attribute entry.



5
6
7
# File 'app/models/pageflow/draft_entry.rb', line 5

def entry
  @entry
end

Class Method Details

.accessible_by(ability, action) ⇒ Object



64
65
66
67
68
# File 'app/models/pageflow/draft_entry.rb', line 64

def self.accessible_by(ability, action)
  Entry.accessible_by(ability, action).map do |entry|
    DraftEntry.new(entry)
  end
end

.find(id) ⇒ Object



56
57
58
# File 'app/models/pageflow/draft_entry.rb', line 56

def self.find(id)
  new(Entry.find(id))
end

.for_file_usage(usage) ⇒ Object



60
61
62
# File 'app/models/pageflow/draft_entry.rb', line 60

def self.for_file_usage(usage)
  new(usage.revision.entry)
end

Instance Method Details

#add_file(file) ⇒ Object



44
45
46
# File 'app/models/pageflow/draft_entry.rb', line 44

def add_file(file)
  draft.file_usages.create!(:file => file)
end

#create_file(model, attributes) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'app/models/pageflow/draft_entry.rb', line 28

def create_file(model, attributes)
  file = model.create(attributes) do |f|
    f.entry = entry
  end

  usage = @draft.file_usages.create(:file => file)
  file.usage_id = usage.id

  file
end

#home_buttonObject



78
79
80
# File 'app/models/pageflow/draft_entry.rb', line 78

def home_button
  HomeButton.new(draft, theming)
end

#remove_file(file) ⇒ Object



39
40
41
42
# File 'app/models/pageflow/draft_entry.rb', line 39

def remove_file(file)
  draft.file_usages.where(file: file).destroy_all
  file.destroy if file.usages.empty?
end

#save!Object



48
49
50
# File 'app/models/pageflow/draft_entry.rb', line 48

def save!
  draft.save!
end

#stylesheet_cache_keyObject



74
75
76
# File 'app/models/pageflow/draft_entry.rb', line 74

def stylesheet_cache_key
  draft.cache_key
end

#stylesheet_modelObject



70
71
72
# File 'app/models/pageflow/draft_entry.rb', line 70

def stylesheet_model
  draft
end

#update_meta_data!(attributes) ⇒ Object



52
53
54
# File 'app/models/pageflow/draft_entry.rb', line 52

def update_meta_data!(attributes)
  draft.update_attributes!(attributes)
end