class BooticCli::Console

Constants

SEPCOUNT

Attributes

session[R]

Public Class Methods

new(session) click to toggle source
# File lib/bootic_cli/console.rb, line 9
def initialize(session)
  @session = session
end

Public Instance Methods

explain(entity, include_links = true) click to toggle source
# File lib/bootic_cli/console.rb, line 13
def explain(entity, include_links = true)
  if entity.is_a?(String) || entity.is_a?(Integer)
    puts entity
    return
  end

  if entity.is_a?(Array)
    entity.each{|e| explain(e) }
    return
  end

  title 'PROPERTIES:'
  puts table(entity.properties)

  puts ''

  if include_links
    title 'LINKS (explain_link <ENTITY>, <LINK_NAME>):'
    puts links(entity.rels)

    puts ''
  end

  title 'ENTITIES (explain <SUBENTITY>):'
  puts entity.entities.keys.join("\r\n")

  puts '-' * SEPCOUNT
  puts ''
  nil
end
list(entities) click to toggle source
# File lib/bootic_cli/console.rb, line 67
def list(entities)
  if entities.respond_to?(:each)
    entities.each{|e| explain(e, false)}
    puts ''
    if entities.respond_to?(:total_items)
      puts "Page #{entities.page} of #{(entities.total_items / entities.per_page) + 1}. Total items #{entities.total_items}"
    end
    if entities.respond_to?(:next)
      @last_in_list = entities
      puts "There is more. run 'more'"
    else
      @last_in_list = nil
      puts "End of list"
    end
  else
    explain entities
  end

  nil
end
more() click to toggle source
# File lib/bootic_cli/console.rb, line 88
def more
  puts "End of list" unless @last_in_list
  list @last_in_list.next
end

Private Instance Methods

table(hash) click to toggle source
# File lib/bootic_cli/console.rb, line 95
def table(hash)
  hash.map{|k,v| [k.to_s.ljust(20), v].join}.join("\r\n")
end
title(str) click to toggle source
# File lib/bootic_cli/console.rb, line 99
def title(str)
  puts "### #{str}\r\n"
  nil
end