class Ribose::CLI::Commands::Base

Private Instance Methods

build_output(resources, options) click to toggle source
# File lib/ribose/cli/commands/base.rb, line 37
def build_output(resources, options)
  json_view(resources, options) || table_view(resources)
end
build_resource_output(resource, options) click to toggle source
# File lib/ribose/cli/commands/base.rb, line 41
def build_resource_output(resource, options)
  resource_as_json(resource, options) || resource_as_table(resource)
end
json_view(resources, options) click to toggle source
# File lib/ribose/cli/commands/base.rb, line 45
def json_view(resources, options)
  if options[:format] == "json"
    resources.map(&:to_h).to_json
  end
end
resource_as_json(resource, options) click to toggle source
# File lib/ribose/cli/commands/base.rb, line 51
def resource_as_json(resource, options)
  if options[:format] == "json"
    resource.to_h.to_json
  end
end
resource_as_table(resource) click to toggle source
# File lib/ribose/cli/commands/base.rb, line 63
def resource_as_table(resource)
  Ribose::CLI::Util.list(
    headings: ["Field", "Value"],
    rows: table_field_names.map { |key| [key, resource[key.to_s]] },
  )
end
symbolize_keys(options_hash) click to toggle source
# File lib/ribose/cli/commands/base.rb, line 70
def symbolize_keys(options_hash)
  Hash.new.tap do |hash|
    options_hash.each_key do |key|
      hash[(key.to_sym rescue key) || key] = options_hash.fetch(key)
    end
  end
end
table_field_names() click to toggle source

Table field names

Displaying a single resource in table view will invoke this method to figure out field name and values for each of the row in table, please override this with proper attributes

# File lib/ribose/cli/commands/base.rb, line 33
def table_field_names
  raise NotImplementedError
end
table_headers() click to toggle source

Table Headers

Listing resources in table view will invoke this method to retrieve the list of headers, please override this in the sub-class and fill it in with actual fields name.

# File lib/ribose/cli/commands/base.rb, line 13
def table_headers
  raise NotImplementedError
end
table_rows() click to toggle source

Table Rows

List resources in table view will invoke this method to build each of the individual resource row, please override this with an array that includes the value for headers.

# File lib/ribose/cli/commands/base.rb, line 23
def table_rows
  raise NotImplementedError
end
table_view(resources) click to toggle source
# File lib/ribose/cli/commands/base.rb, line 57
def table_view(resources)
  Ribose::CLI::Util.list(
    headings: table_headers, rows: table_rows(resources),
  )
end