Class: Pulitzer::FreeFormSection

Inherits:
ApplicationRecord show all
Defined in:
app/models/pulitzer/free_form_section.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

assoc_name, attrs_name, convert_hash_to_nested

Class Method Details

.convert_nested_assoc(json_hash) ⇒ Object



20
21
22
23
24
25
# File 'app/models/pulitzer/free_form_section.rb', line 20

def self.convert_nested_assoc(json_hash)
  json_hash[attrs_name].map!{|ffs_attrs|
    new_attrs = Pulitzer::Partial.convert_hash_to_nested ffs_attrs
  }
  json_hash      
end

.export_configObject



11
12
13
14
15
16
17
18
# File 'app/models/pulitzer/free_form_section.rb', line 11

def self.export_config
  {
    except: [:id, :version_id, :free_form_section_type_id],
    include: {
      partials: Pulitzer::Partial.export_config
    }
  }
end

Instance Method Details

#clone_meObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/pulitzer/free_form_section.rb', line 31

def clone_me
  clone_attrs = self.attributes.dup
  clone_attrs.delete 'id'
  clone_attrs.delete 'version_id'

  my_clone = Pulitzer::FreeFormSection.create!(clone_attrs)
  partials.each do |partial|
    cloned_partial = partial.clone_me
    my_clone.partials << cloned_partial
  end
  my_clone
end

#partial(name) ⇒ Object



27
28
29
# File 'app/models/pulitzer/free_form_section.rb', line 27

def partial(name)
  self.partials.to_a.detect{|ffs| ffs.name == name}
end