Module: XcodeYamlizer

Defined in:
lib/xcode-yamlizer.rb,
lib/xcode-yamlizer/cli.rb,
lib/xcode-yamlizer/version.rb

Defined Under Namespace

Classes: Cli

Constant Summary collapse

VERSION =
"0.0.4"

Class Method Summary collapse

Class Method Details

.convert_directory(dir, to_xcode, verbose = false, ignore_paths = []) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/xcode-yamlizer.rb', line 117

def self.convert_directory(dir, to_xcode, verbose=false, ignore_paths=[])
  puts "Conventering directory '#{dir}'..." if verbose
  files = []
  formats = to_xcode ? YAML_FORMATS : XCODE_FORMATS

  Find.find(dir) do |path|
    if FileTest.directory?(path)
      if ignore_paths.include?(path) or ignore_paths.include? path.gsub(/^\.\//,"")
        puts "Ignored in submodule: #{path}" if verbose
        Find.prune
      else
        next
      end
    else
      files += [path] if formats.include_filename? path
    end
  end

  puts "Found:" if verbose
  puts files if verbose
  new_files = files.map do |file|
    convert_file file, verbose
  end
  puts "Finished!" if verbose
  return files, new_files
end

.convert_file(input, verbose = false) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/xcode-yamlizer.rb', line 144

def self.convert_file(input, verbose=false)
  result = nil
  if YAML_FORMATS.include_filename? input
    output = input.chomp(File.extname(input))
    FileUtils.cp output, "#{output}~"
  elsif XCODE_FORMATS.include_filename? input
    output = "#{input}.yaml"

  end
  result = load(input)
  dump(output, result)
  if result
    puts "#{input} => #{output}" if verbose
    return output
  else
    puts "Don't know what to do with '#{input}'"
  end
end

.find_submodulesObject



173
174
175
176
177
178
# File 'lib/xcode-yamlizer.rb', line 173

def self.find_submodules
  paths = `git submodule foreach --quiet 'echo $path'`
  paths.lines.map do |line|
    line.chomp
  end
end

.make_filepaths_non_relative(files) ⇒ Object



167
168
169
170
171
# File 'lib/xcode-yamlizer.rb', line 167

def self.make_filepaths_non_relative files
  files.map do |file|
    file.sub(/^\.\//,"")
  end
end

.rootObject



163
164
165
# File 'lib/xcode-yamlizer.rb', line 163

def self.root
  return File.expand_path('../..', __FILE__)
end

.run_post_mergeObject



197
198
199
200
201
# File 'lib/xcode-yamlizer.rb', line 197

def self.run_post_merge
  chroot_to_repo()
  paths_to_ignore = find_submodules
  convert_directory('./', true, false, paths_to_ignore)
end

.run_pre_commitObject



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/xcode-yamlizer.rb', line 180

def self.run_pre_commit
  chroot_to_repo()
  paths_to_ignore = find_submodules


  files_remove, files_add = convert_directory('./', \
                              false, \
                              true, \
                              paths_to_ignore)
  files_remove = make_filepaths_non_relative files_remove
  files_add = make_filepaths_non_relative files_add
  repo_add_files files_add

  repo_remove_files files_remove
  repo_gitignore_add_files files_remove
end