Class: Content

Inherits:
ApplicationRecord show all
Includes:
Mumuki::Domain::Syncable, WithDescription, WithLocale, WithName, WithProgress, WithSlug, WithUsages
Defined in:
app/models/content.rb

Direct Known Subclasses

Book, Guide, Topic

Instance Method Summary collapse

Methods included from WithProgress

#completed_for?, #completion_percentage_for, #dirty_progress_if_structural_children_changed!, #dirty_progresses!, #progress_for

Methods included from WithUsages

#usage_in_organization, #usage_in_organization_of_type

Methods included from WithSlug

#normalize_slug!, #rebase!, #rebased_dup, #transparent_id, #transparent_params

Methods included from WithDescription

#description_teaser

Methods included from Mumuki::Domain::Syncable

#platform_class_name, #sync_key

Methods inherited from ApplicationRecord

aggregate_of, all_except, defaults, #delete, #destroy!, numbered, organic_on, resource_fields, #save, #save_and_notify!, #save_and_notify_changes!, serialize_symbolized_hash_array, #update_and_notify!, update_or_create!, whitelist_attributes

Instance Method Details

#fork_to!(organization, syncer, quiet: false) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'app/models/content.rb', line 20

def fork_to!(organization, syncer, quiet: false)
  rebased_dup(organization).tap do |dup|
    self.class.find_by(slug: dup.slug).try { |it| return it } if quiet

    dup.validate!
    fork_children_into! dup, organization, syncer
    dup.save validate: false

    syncer.export! dup
  end
end

#public?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/models/content.rb', line 32

def public?
  !private?
end

#to_expanded_resource_hObject



16
17
18
# File 'app/models/content.rb', line 16

def to_expanded_resource_h(*)
  as_json(only: [:name, :slug, :description, :locale]).symbolize_keys
end

#to_resource_h(*args) ⇒ Object



12
13
14
# File 'app/models/content.rb', line 12

def to_resource_h(*args)
  to_expanded_resource_h(*args).compact
end