Class: Fanta::BuildEnvironment

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ BuildEnvironment

Returns a new instance of BuildEnvironment.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fanta/build_environment.rb', line 14

def initialize options
  @options = options
  
  options[:info_plist] ||= 'Resources/Info.plist'
  options[:version] ||= Plist::parse_xml(options[:info_plist])['CFBundleVersion']
  options[:project_name] ||= xcodebuild_list.first.scan(/project\s\"([^\"]+)/i).flatten.first
  options[:full_name] ||= "#{self[:project_name]} #{self[:version]}"
  options[:build_dir] ||= 'build'
  options[:sdk] ||= 'iphoneos'
  options[:configuration] ||= 'Release'
  options[:target] ||= targets.first
  options[:app_file] ||= self[:project_name]
  options[:target_or_scheme] ||= 'target'
  
  if options[:ipa_name]
    options[:ipa_file] ||= File.join self[:build_dir], 
                            [self[:project_name], self[:version], self[:configuration], self[:ipa_name]].join("-") + ".ipa"
    options[:dsym_file] ||= File.join self[:build_dir], 
                            [self[:project_name], self[:version], self[:configuration], self[:ipa_name]].join("-") + ".dSYM.zip"
  end
end

Instance Attribute Details

#build_dirObject (readonly)

Returns the value of attribute build_dir.



12
13
14
# File 'lib/fanta/build_environment.rb', line 12

def build_dir
  @build_dir
end

#default_sdkObject (readonly)

Returns the value of attribute default_sdk.



12
13
14
# File 'lib/fanta/build_environment.rb', line 12

def default_sdk
  @default_sdk
end

#info_plistObject (readonly)

Returns the value of attribute info_plist.



12
13
14
# File 'lib/fanta/build_environment.rb', line 12

def info_plist
  @info_plist
end

Instance Method Details

#[](name) ⇒ Object



64
65
66
67
# File 'lib/fanta/build_environment.rb', line 64

def [](name)
  fail "You need to specify :#{name} in Rakefile" unless @options[name]
  @options[name].respond_to?(:call) ? @options[name].call : @options[name]
end

#apply(options) {|BuildEnvironment.new @options.merge(options)| ... } ⇒ Object

Yields:



36
37
38
# File 'lib/fanta/build_environment.rb', line 36

def apply options, &block
  yield BuildEnvironment.new @options.merge(options)
end

#configurationsObject



48
49
50
51
52
53
54
# File 'lib/fanta/build_environment.rb', line 48

def configurations
  @configurations ||= begin
    start_line = xcodebuild_list.find_index{ |l| l =~ /configurations/i } + 1
    end_line = xcodebuild_list.find_index{ |l| l =~ /if no/i } - 1
    xcodebuild_list.slice start_line...end_line
  end
end

#has_entry?(name) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/fanta/build_environment.rb', line 69

def has_entry? name
  @options[name]
end

#sdksObject



44
45
46
# File 'lib/fanta/build_environment.rb', line 44

def sdks
  @sdks ||= `xcodebuild -showsdks`.scan(/-sdk (.*?$)/m).flatten
end

#targetsObject



56
57
58
59
60
61
62
# File 'lib/fanta/build_environment.rb', line 56

def targets
  @targets ||= begin
    start_line = xcodebuild_list.find_index{ |l| l =~ /targets/i } + 1
    end_line = xcodebuild_list.find_index{ |l| l =~ /configurations/i } - 1
    xcodebuild_list.slice(start_line...end_line).map{|l| l.gsub('(Active)','').strip }
  end
end

#versionObject



40
41
42
# File 'lib/fanta/build_environment.rb', line 40

def version
  self[:version]
end