Class: FmRest::Spyke::ContainerField

Inherits:
Object
  • Object
show all
Defined in:
lib/fmrest/spyke/container_field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, name) ⇒ ContainerField

Returns a new instance of ContainerField.

Parameters:

  • base (FmRest::Spyke::Base)

    the record this container belongs to

  • name (Symbol)

    the name of the container field



12
13
14
15
# File 'lib/fmrest/spyke/container_field.rb', line 12

def initialize(base, name)
  @base = base
  @name = name
end

Instance Attribute Details

#nameString (readonly)

Returns the name of the container field.

Returns:

  • (String)

    the name of the container field



8
9
10
# File 'lib/fmrest/spyke/container_field.rb', line 8

def name
  @name
end

Instance Method Details

#downloadObject



23
24
25
# File 'lib/fmrest/spyke/container_field.rb', line 23

def download
  FmRest::V1.fetch_container_data(url, @base.class.connection)
end

#upload(filename_or_io, options = {}) ⇒ Object

Parameters:

  • filename_or_io (String, IO)

    a path to the file to upload or an IO object

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :repetition (Integer) — default: 1

    The repetition to pass to the upload URL

Raises:

  • (ArgumentError)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fmrest/spyke/container_field.rb', line 33

def upload(filename_or_io, options = {})
  raise ArgumentError, "Record needs to be saved before uploading to a container field" unless @base.persisted?

  response =
    FmRest::V1.upload_container_data(
      @base.class.connection,
      upload_path(options[:repetition] || 1),
      filename_or_io,
      options
    )

  # Update mod id on record
  @base.__mod_id = response.body[:data][:__mod_id]

  true
end

#urlString

Returns the URL for the container.

Returns:

  • (String)

    the URL for the container



18
19
20
# File 'lib/fmrest/spyke/container_field.rb', line 18

def url
  @base.attributes[name]
end