Class: Locomotive::Wagon::DeleteCommand

Inherits:
Struct
  • Object
show all
Includes:
ApiConcern, DeployFileConcern
Defined in:
lib/locomotive/wagon/commands/delete_command.rb

Constant Summary collapse

SITE_RESOURCE =
'site'
SINGLE_RESOURCES =
%w(page content_type snippet section translation).freeze
ALL_RESOURCES =
%w(content_types snippets theme_assets sections translations).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DeployFileConcern

#deploy_file, #read_deploy_settings, #write_deploy_settings

Methods included from ApiConcern

#api_client, #api_credentials, #api_host, #api_site_client, #connection_information_from_env_and_path

Instance Attribute Details

#envObject

Returns the value of attribute env

Returns:

  • (Object)

    the current value of env



6
7
8
# File 'lib/locomotive/wagon/commands/delete_command.rb', line 6

def env
  @env
end

#identifierObject

Returns the value of attribute identifier

Returns:

  • (Object)

    the current value of identifier



6
7
8
# File 'lib/locomotive/wagon/commands/delete_command.rb', line 6

def identifier
  @identifier
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



6
7
8
# File 'lib/locomotive/wagon/commands/delete_command.rb', line 6

def path
  @path
end

#resourceObject

Returns the value of attribute resource

Returns:

  • (Object)

    the current value of resource



6
7
8
# File 'lib/locomotive/wagon/commands/delete_command.rb', line 6

def resource
  @resource
end

#shellObject

Returns the value of attribute shell

Returns:

  • (Object)

    the current value of shell



6
7
8
# File 'lib/locomotive/wagon/commands/delete_command.rb', line 6

def shell
  @shell
end

Class Method Details

.delete(*args) ⇒ Object

Parameters:

  • env (String)

    The environment to delete from

  • path (String)

    The path to a wagon site to delete from

  • resource (String)

    The resource type to delete. @see RESOURCES

  • identifier (String)

    The id or handle of the resource entry to delete



19
20
21
# File 'lib/locomotive/wagon/commands/delete_command.rb', line 19

def self.delete(*args)
  new(*args).delete
end

Instance Method Details

#deleteObject

Raises:

  • (ArgumentError)

    unless the given resources is in SINGLE_RESOURCES or ALL_RESOURCES



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

def delete
  if resource == SITE_RESOURCE
    delete_site
  elsif SINGLE_RESOURCES.include?(resource)
    delete_single
  elsif ALL_RESOURCES.include?(resource)
    delete_all
  else
    raise ArgumentError, "Resource must be one of #{SINGLE_RESOURCES.join(?,)} if you pass an identifier OR be one of #{ALL_RESOURCES.join(?,)} if you want to delete all the items of that resource."
  end
end