Class: Chimps::Commands::List

Inherits:
Chimps::Command show all
Includes:
Utils::UsesModel
Defined in:
lib/chimps/commands/list.rb

Overview

A command to issue a GET request against an index of resources at Infochimps.

Constant Summary collapse

"chimps list [OPTIONS]"
HELP =
"\nList resources of a given type (defaults to dataset).\n\nLists your resources by default but see options below.\n\n"
MODELS =

Models that can be indexed (default first)

%w[dataset license source]

Instance Attribute Summary

Attributes inherited from Chimps::Command

#argv

Instance Method Summary collapse

Methods included from Utils::UsesModel

#define_model_option, #model, #model=, #model_identifier, #model_path, #models_path, #models_string, #plural_model

Methods inherited from Chimps::Command

#initialize, name, #name

Constructor Details

This class inherits a constructor from Chimps::Command

Instance Method Details

#all?Boolean

List all resources or just those owned by the Chimps user?

Returns:

  • (Boolean)


33
34
35
# File 'lib/chimps/commands/list.rb', line 33

def all?
  @all
end

#define_optionsObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/chimps/commands/list.rb', line 21

def define_options
  on_tail("-a", "--all", "List all resources, not just those owned by you.") do |a|
    @all = a
  end

  on_tail("-s", "--[no-]skip-column-names", "Don't print column names in output.") do |s|
    @skip_column_names = s
  end
  
end

#execute!Object

Issue the GET request.



47
48
49
# File 'lib/chimps/commands/list.rb', line 47

def execute!
  Request.new(models_path, :params => params).get.print(:skip_column_names => @skip_column_names)
end

#paramsHash?

Parameters to include in the query.

If listing all resources, then return nil.

Returns:



42
43
44
# File 'lib/chimps/commands/list.rb', line 42

def params
  return { :id => Chimps.username } unless all?
end