Class: Locomotive::Wagon::PushContentEntriesCommand

Inherits:
PushBaseCommand
  • Object
show all
Defined in:
lib/locomotive/wagon/commands/push_sub_commands/push_content_entries_command.rb

Instance Attribute Summary collapse

Attributes inherited from PushBaseCommand

#api_client, #content_assets_pusher, #filter, #remote_site, #steam_services

Instance Method Summary collapse

Methods inherited from PushBaseCommand

#_push_with_timezone, #default_locale, #instrument, #locales, #only, #path, push, #push, #resource_name, #with_data, #with_data?

Instance Attribute Details

#stepObject (readonly)

Returns the value of attribute step.



5
6
7
# File 'lib/locomotive/wagon/commands/push_sub_commands/push_content_entries_command.rb', line 5

def step
  @step
end

Instance Method Details

#_pushObject



9
10
11
12
13
14
# File 'lib/locomotive/wagon/commands/push_sub_commands/push_content_entries_command.rb', line 9

def _push
  ([:without_relationships] + other_locales + [:only_relationships]).each do |step|
    @step = step
    default_push
  end
end

#decorate(entity) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/locomotive/wagon/commands/push_sub_commands/push_content_entries_command.rb', line 25

def decorate(entity)
  if locale?
    ContentEntryWithLocalizedAttributesDecorator.new(entity, @step, path, content_assets_pusher)
  elsif only_relationships?
    ContentEntryWithOnlyRelationshipsDecorator.new(entity, default_locale, path, content_assets_pusher)
  else
    ContentEntryDecorator.new(entity, default_locale, path, content_assets_pusher)
  end
end

#default_pushObject



7
# File 'lib/locomotive/wagon/commands/push_sub_commands/push_content_entries_command.rb', line 7

alias_method :default_push, :_push

#entitiesObject



16
17
18
19
20
21
22
23
# File 'lib/locomotive/wagon/commands/push_sub_commands/push_content_entries_command.rb', line 16

def entities
  @entities ||= repositories.content_type.all.map do |content_type|
    # bypass a locale if there is no fields marked as localized
    next if skip_content_type?(content_type) || (locale? && content_type.fields.localized_names.blank?)

    repositories.content_entry.with(content_type).all(_visible: nil)
  end.compact.flatten
end

#label_for(decorated_entity) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/locomotive/wagon/commands/push_sub_commands/push_content_entries_command.rb', line 50

def label_for(decorated_entity)
  label = decorated_entity.__with_locale__(default_locale) { decorated_entity._label }
  label = "#{decorated_entity.content_type.name} / #{label}"

  if without_relationships?
    label
  elsif only_relationships?
    "#{label} with relationships"
  elsif locale?
    "#{label} in #{self.step}"
  end
end

#persist(decorated_entity) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/locomotive/wagon/commands/push_sub_commands/push_content_entries_command.rb', line 35

def persist(decorated_entity)
  attributes = decorated_entity.to_hash

  raise SkipPersistingException.new if attributes.blank?

  _locale = locale? ? @step : nil

  remote_entity = api_client.content_entries(decorated_entity.content_type).update(decorated_entity._id, attributes, _locale)

  # Note: very important to use the real id in the next API calls
  # because the _slug can be localized and so, won't be unique for
  # a content entry.
  decorated_entity._id = remote_entity._id
end