Class: Pageflow::FileReuse

Inherits:
Object
  • Object
show all
Defined in:
app/models/pageflow/file_reuse.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(destination_entry, source_entry, file_type, file_id) ⇒ FileReuse

Returns a new instance of FileReuse.



5
6
7
8
9
10
# File 'app/models/pageflow/file_reuse.rb', line 5

def initialize(destination_entry, source_entry, file_type, file_id)
  @source_entry = source_entry
  @destination_entry = destination_entry
  @file_type = file_type
  @file = source_entry.find_file(file_type.model, file_id)
end

Instance Attribute Details

#destination_entryObject

Returns the value of attribute destination_entry.



3
4
5
# File 'app/models/pageflow/file_reuse.rb', line 3

def destination_entry
  @destination_entry
end

#fileObject

Returns the value of attribute file.



3
4
5
# File 'app/models/pageflow/file_reuse.rb', line 3

def file
  @file
end

#file_typeObject

Returns the value of attribute file_type.



3
4
5
# File 'app/models/pageflow/file_reuse.rb', line 3

def file_type
  @file_type
end

#source_entryObject

Returns the value of attribute source_entry.



3
4
5
# File 'app/models/pageflow/file_reuse.rb', line 3

def source_entry
  @source_entry
end

Instance Method Details

#save!Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/pageflow/file_reuse.rb', line 12

def save!
  destination_entry.use_file(file)

  file_type.nested_file_types.each do |nested_file_type|
    source_entry.find_files(nested_file_type.model).each do |nested_file|
      next if nested_file.parent_file_id != file.id ||
              nested_file.parent_file_model_type != file.model_name.name

      destination_entry.use_file(nested_file)
    end
  end
end