Class: TargetConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/target_configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, target) ⇒ TargetConfiguration

Returns a new instance of TargetConfiguration.



5
6
7
8
9
10
11
# File 'lib/target_configuration.rb', line 5

def initialize(name, target)
  @name = name
  @target = target
  @pods = []
  @scripts = []
  @options = {}
end

Instance Attribute Details

#podsObject

Returns the value of attribute pods.



2
3
4
# File 'lib/target_configuration.rb', line 2

def pods
  @pods
end

#scriptsObject

Returns the value of attribute scripts.



3
4
5
# File 'lib/target_configuration.rb', line 3

def scripts
  @scripts
end

Instance Method Details

#add_option(name, &block) ⇒ Object



13
14
15
# File 'lib/target_configuration.rb', line 13

def add_option(name, &block)
  @options[name] = block
end

#ask_question(question) ⇒ Object



42
43
44
45
# File 'lib/target_configuration.rb', line 42

def ask_question(question)
  puts question
  get_input()
end

#get_inputObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/target_configuration.rb', line 47

def get_input
  STDOUT.flush
  input = STDIN.gets.chomp
  case input.upcase
    when 'Y'
      true
    when 'N'
      false
    else
      puts 'Please enter Y or N'
      get_input
  end
end

#process_optionalObject



17
18
19
20
21
22
23
24
25
# File 'lib/target_configuration.rb', line 17

def process_optional
  @options.each do |key, obj|
    key_string = key.to_s
      if ask_question "do you want to add #{key_string}? [y/n]"
        raise unless obj.is_a? Proc
        obj.call()
      end
  end
end

#process_scripts(project) ⇒ Object



36
37
38
39
40
# File 'lib/target_configuration.rb', line 36

def process_scripts(project)
  scripts.each do |hash|
    project.add_shell_script(@target, hash[:name], hash[:script])
  end
end

#write_pods(f) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/target_configuration.rb', line 27

def write_pods(f)
  return if @pods.empty?
  f.puts "target '#{@target.name}', :exclusive => true do"
  pods.flatten.each do |pod|
    f.puts "  pod '#{pod}'"
  end
  f.puts 'end'
end