Class: Toolshed::Commands::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/toolshed/commands/base.rb

Direct Known Subclasses

CreatePullRequest, CreateTicketComment

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



4
5
# File 'lib/toolshed/commands/base.rb', line 4

def initialize(options={})
end

Instance Method Details

#read_user_input(message, options = {}) ⇒ Object



7
8
9
10
# File 'lib/toolshed/commands/base.rb', line 7

def read_user_input(message, options={})
  return options[:default] if Toolshed::Client.use_defaults
  prompt_user_input(message, options)
end

#read_user_input_body(message, options = {}) ⇒ Object



17
18
19
20
# File 'lib/toolshed/commands/base.rb', line 17

def read_user_input_body(message, options={})
  return options[:body] if options.has_key?(:body)
  read_user_input(message, options)
end

#read_user_input_title(message, options = {}) ⇒ Object



12
13
14
15
# File 'lib/toolshed/commands/base.rb', line 12

def read_user_input_title(message, options={})
  return options[:title] if options.has_key?(:title)
  read_user_input(message, options)
end

#use_project_idObject



54
55
56
# File 'lib/toolshed/commands/base.rb', line 54

def use_project_id
  Object.const_get("#{ticket_tracker_class}::USE_PROJECT_ID") rescue false
end

#use_ticket_tracker_by_type(options) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/toolshed/commands/base.rb', line 43

def use_ticket_tracker_by_type(options)
  use_field = Object.const_get("#{ticket_tracker_class}::#{options[:ticket_tracker_const]}") rescue false
  if use_field
    ticket_tracker_response = read_user_input(options[:default_message],
      options.merge!({ default: Toolshed::Client.send(options[:default_method]) })
    )
    options.merge!({ options[:type] => ticket_tracker_response })
  end
  options
end

#use_ticket_tracker_project_id(options) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/toolshed/commands/base.rb', line 22

def use_ticket_tracker_project_id(options)
  options
  options.merge!({
    ticket_tracker_const: 'USE_PROJECT_ID',
    type: :project_id,
    default_method: 'default_pivotal_tracker_project_id',
    default_message: "Project ID (Default: #{Toolshed::Client.default_pivotal_tracker_project_id}):",
  })
  options = use_ticket_tracker_by_type(options)
end

#use_ticket_tracker_project_name(options) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/toolshed/commands/base.rb', line 33

def use_ticket_tracker_project_name(options)
  options.merge!({
    ticket_tracker_const: 'USE_PROJECT_NAME',
    type: :project,
    default_method: 'default_ticket_tracker_project',
    default_message: "Project Name (Default: #{Toolshed::Client.default_ticket_tracker_project}):",
  })
  use_ticket_tracker_by_type(options)
end