Class: Gena::Config

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.createObject



13
14
15
16
17
18
19
20
21
# File 'lib/config/config.rb', line 13

def Config.create
  hash = Hash.new
  hash[:plugins_url] = [
      '~/Development/gena-plugins'
  ]
  hash['sources_dir'] = '/Users/alex/Development/fisho-ios/Sources'

  File.open('gena.plist', 'w') { |f| f.write hash.to_plist }
end

.exists?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/config/config.rb', line 9

def Config.exists?
  File.exists?('gena.plist')
end

Instance Method Details

#collapse_to_project(path) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/config/config.rb', line 63

def collapse_to_project(path)
  if path[0] == '/'
    path = path.dup
    path["#{$config.project_dir}/"] = ''
  end
  path
end

#dataObject



31
32
33
# File 'lib/config/config.rb', line 31

def data
  @data
end

#data=(new_data) ⇒ Object



35
36
37
# File 'lib/config/config.rb', line 35

def data=(new_data)
  @data = new_data
end

#data_without_pluginsObject



39
40
41
# File 'lib/config/config.rb', line 39

def data_without_plugins
  @data.reject { |k, v| k == GENA_PLUGINS_CONFIG_KEY }
end

#expand_to_project(path) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/config/config.rb', line 55

def expand_to_project(path)
  if path[0] == '/'
    path
  else
    File.join(self.project_dir, path)
  end
end

#header_dirObject



43
44
45
46
47
48
49
# File 'lib/config/config.rb', line 43

def header_dir
  if @data['header'] && !@data['header'].empty?
    expand_to_project(@data['header'])
  else
    ''
  end
end

#load_plist_configObject



27
28
29
# File 'lib/config/config.rb', line 27

def load_plist_config
  @data = Plist::parse_xml('gena.plist')
end

#project_dirObject



51
52
53
# File 'lib/config/config.rb', line 51

def project_dir
  File.expand_path((!self.data['project_dir'] || self.data['project_dir'].empty?)? '.' : self.data['project_dir'])
end

#save!Object



23
24
25
# File 'lib/config/config.rb', line 23

def save!
  File.open('gena.plist', 'w') { |f| f.write self.data.to_plist }
end

#sources_dirObject



71
72
73
# File 'lib/config/config.rb', line 71

def sources_dir
  self.expand_to_project(self.data['sources_dir'])
end

#tests_dirObject



75
76
77
# File 'lib/config/config.rb', line 75

def tests_dir
  self.expand_to_project(self.data['tests_dir'])
end

#xcode_project_pathObject



79
80
81
82
83
84
85
86
# File 'lib/config/config.rb', line 79

def xcode_project_path
  path = self.expand_to_project("#{@data['project_name']}.xcodeproj")
  unless File.exists? path
    say "Can't find project with name '#{@data['project_name']}.xcodeproj''", Color::RED
    abort
  end
  path
end