Class: Tracker::Cli::Command::List
- Inherits:
-
Object
- Object
- Tracker::Cli::Command::List
- Defined in:
- lib/tracker/cli/command/list.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#cli ⇒ Object
readonly
Returns the value of attribute cli.
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#objects ⇒ Object
readonly
Returns the value of attribute objects.
Instance Method Summary collapse
-
#initialize(cli:, object_type:, **arguments) ⇒ List
constructor
A new instance of List.
- #list_projects ⇒ Object
- #list_stories ⇒ Object
- #print_objects ⇒ Object
Constructor Details
#initialize(cli:, object_type:, **arguments) ⇒ List
Returns a new instance of List.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/tracker/cli/command/list.rb', line 7 def initialize(cli: , object_type: , **arguments) @cli = cli @arguments = arguments case object_type when 'stories' then list_stories when 'projects' then list_projects end case arguments[:format_name] when 'json' print JSON.dump(objects) else print_objects end end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
5 6 7 |
# File 'lib/tracker/cli/command/list.rb', line 5 def arguments @arguments end |
#cli ⇒ Object (readonly)
Returns the value of attribute cli.
5 6 7 |
# File 'lib/tracker/cli/command/list.rb', line 5 def cli @cli end |
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
5 6 7 |
# File 'lib/tracker/cli/command/list.rb', line 5 def columns @columns end |
#objects ⇒ Object (readonly)
Returns the value of attribute objects.
5 6 7 |
# File 'lib/tracker/cli/command/list.rb', line 5 def objects @objects end |
Instance Method Details
#list_projects ⇒ Object
30 31 32 33 |
# File 'lib/tracker/cli/command/list.rb', line 30 def list_projects @objects = cli.connection.get('projects').body @columns = [ 'id', 'name' ] end |
#list_stories ⇒ Object
24 25 26 27 28 |
# File 'lib/tracker/cli/command/list.rb', line 24 def list_stories query_params = arguments.fetch(:query_params, {}) @objects = cli.connection.fetch_stories(project: Tracker.project, query: query_params) @columns = [ 'id', 'name', 'current_state', 'story_type' ] end |
#print_objects ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/tracker/cli/command/list.rb', line 35 def print_objects objects.each do |object| row = object.map do |(k, v)| if columns.include?(k) k == 'name' ? v.to_json : v end end.compact print row.join("\t") print "\n" end end |