Class: Locomotive::Wagon::PushContentTypesCommand

Inherits:
PushBaseCommand show all
Defined in:
lib/locomotive/wagon/commands/push_sub_commands/push_content_types_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_types_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_types_command.rb', line 9

def _push
  %i(without_relationships only_relationships).each do |step|
    @step = step
    default_push
  end
end

#decorate(entity) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb', line 20

def decorate(entity)
  if without_relationships?
    ContentTypeDecorator.new(entity, remote_fields_for(entity.slug))
  else
    ContentTypeWithOnlyRelationshipsDecorator.new(entity)
  end
end

#default_pushObject



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

alias_method :default_push, :_push

#entitiesObject



16
17
18
# File 'lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb', line 16

def entities
  repositories.content_type.all
end

#label_for(decorated_entity) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb', line 34

def label_for(decorated_entity)
  name = decorated_entity.name

  if without_relationships?
    name
  else
    "#{name} with relationships"
  end
end

#persist(decorated_entity) ⇒ Object



28
29
30
31
32
# File 'lib/locomotive/wagon/commands/push_sub_commands/push_content_types_command.rb', line 28

def persist(decorated_entity)
  raise SkipPersistingException.new if only_relationships? && !decorated_entity.with_relationships?

  api_client.content_types.update(decorated_entity.slug, decorated_entity.to_hash)
end