Class: Tracker::Cli::Command::Create

Inherits:
Object
  • Object
show all
Defined in:
lib/tracker/cli/command/create.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cli:, object_type:, query_params: {}, **arguments) ⇒ Create

Returns a new instance of Create.



7
8
9
10
11
12
13
14
# File 'lib/tracker/cli/command/create.rb', line 7

def initialize(cli: , object_type: , query_params: {}, **arguments)
  @cli = cli
  @arguments = arguments
  @params = query_params.dup
 
  setup_create(object_type, **arguments)
  print cli.connection.post(@path, URI.encode_www_form(@params)).body.to_json
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



5
6
7
# File 'lib/tracker/cli/command/create.rb', line 5

def arguments
  @arguments
end

#cliObject (readonly)

Returns the value of attribute cli.



5
6
7
# File 'lib/tracker/cli/command/create.rb', line 5

def cli
  @cli
end

Instance Method Details

#setup_create(object_type, interactive: false, **arguments) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tracker/cli/command/create.rb', line 16

def setup_create(object_type, interactive: false, **arguments)
  case object_type
  when 'project'
    @params.merge!(
      name: View::Input.new('Name').value,
      no_owner: View::Input.new('No owner', type: :boolean).value
    ) if interactive

    @path = 'projects'

  when 'story'
    @params.merge!({
      name: View::Input.new('Name').value,
      story_type: View::Select.new('What type of story is this?', [ :feature, :bug, :chore, :release ]).selection
    }) if interactive
    
    @path = "projects/#{Tracker.project}/stories"
    
  end
end