class Ribose::CLI::Commands::File

Public Instance Methods

add(file) click to toggle source
# File lib/ribose/cli/commands/file.rb, line 28
def add(file)
  file_upload = create_upload(file, options)

  if file_upload.id
    say("#{file_upload.name} added to your space!")
  end
end
list() click to toggle source
# File lib/ribose/cli/commands/file.rb, line 9
def list
  say(build_output(list_files(options), options))
end
remove() click to toggle source
# File lib/ribose/cli/commands/file.rb, line 54
def remove
  Ribose::SpaceFile.delete(options[:space_id], options[:file_id])
  say("The file has been removed from your space!")
end
show() click to toggle source
# File lib/ribose/cli/commands/file.rb, line 18
def show
  file = Ribose::SpaceFile.fetch(options[:space_id], options[:file_id])
  say(build_resource_output(file, options))
end
update() click to toggle source
# File lib/ribose/cli/commands/file.rb, line 43
def update
  update_file(symbolize_keys(options))
  say("The file has been updated with new attributes")
rescue Ribose::UnprocessableEntity
  say("Something went wrong! Please check required attributes")
end

Private Instance Methods

create_upload(file, attributes = {}) click to toggle source
# File lib/ribose/cli/commands/file.rb, line 65
def create_upload(file, attributes = {})
  Ribose::SpaceFile.create(
    attributes[:space_id],
    file: file,
    tag_list: attributes[:tag_list],
    description: attributes[:description],
  )
end
list_files(attributes) click to toggle source
# File lib/ribose/cli/commands/file.rb, line 61
def list_files(attributes)
  @files ||= Ribose::SpaceFile.all(attributes[:space_id])
end
table_field_names() click to toggle source
# File lib/ribose/cli/commands/file.rb, line 86
def table_field_names
  %w(id name author content_type content_size version)
end
table_headers() click to toggle source
# File lib/ribose/cli/commands/file.rb, line 82
def table_headers
  ["ID", "Name", "Versions"]
end
table_rows(files) click to toggle source
# File lib/ribose/cli/commands/file.rb, line 90
def table_rows(files)
  files.map { |file| [file.id, file.name, file.version] }
end
update_file(attributes) click to toggle source
# File lib/ribose/cli/commands/file.rb, line 74
def update_file(attributes)
  Ribose::SpaceFile.update(
    attributes.delete(:space_id),
    attributes.delete(:file_id),
    attributes,
  )
end