Class: RXCode::Commands::Unwrap

Inherits:
RXCode::Command show all
Defined in:
lib/rxcode/commands/unwrap.rb

Instance Attribute Summary

Attributes inherited from RXCode::Command

#arguments, #err, #input, #options, #output

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RXCode::Command

command_class_for_name, command_names, commands, display_name, #env, inherited, #initialize, new_global_option_parser, run!, run_command

Constructor Details

This class inherits a constructor from RXCode::Command

Class Method Details

.new_command_option_parserObject

COMMAND LINE OPTIONS =======================================================================================


8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rxcode/commands/unwrap.rb', line 8

def self.new_command_option_parser
  Trollop::Parser.new do
    banner <<-TEXT
Unwraps archive files, in particular the project.pbxproj file, and prints their contents to standard out as a ruby hash.

Usage:
  rxcode [global options] unwrap [options] FILENAME...

Options:
    TEXT
    
    opt :raw, "Prints the raw archive structure instead of the object structure"
  end
end

.unwrap_object_value(objects, archive, object_value) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/rxcode/commands/unwrap.rb', line 43

def self.unwrap_object_value(objects, archive, object_value)
  if object_value.is_a?(String) && archive.object_hashes.has_key?(object_value)
    unwrap_object_with_id(objects, archive, object_value)
  elsif object_value.is_a?(Array) && object_value.all? { |array_member| archive.object_hashes.has_key?(array_member) }
    object_value.map { |array_member| unwrap_object_with_id(objects, archive, array_member) }
  else
    object_value
  end
end

.unwrap_object_with_id(objects, archive, object_id) ⇒ Object

OBJECT UNWRAPPING ==========================================================================================


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rxcode/commands/unwrap.rb', line 25

def self.unwrap_object_with_id(objects, archive, object_id)
  if objects.has_key?(object_id)
    
    objects[object_id]
    
  elsif object_hash = archive.object_hashes[object_id]
    
    unwrapped_object = {}
    objects[object_id] = unwrapped_object
    
    object_hash.each do |object_key, object_value|
      unwrapped_object[object_key] = unwrap_object_value(objects, archive, object_value)
    end
    
    unwrapped_object
  end
end

Instance Method Details

#run!Object

RUN! =======================================================================================================


59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rxcode/commands/unwrap.rb', line 59

def run!
  require 'pp'
  
  arguments.each do |filename|
    archive = ::RXCode::Archive.new(filename)
    if unwrap_objects?
      unwrapped_dictionary = self.class.unwrap_object_with_id({}, archive, archive.root_object_archive_id)
      PP.pp(unwrapped_dictionary, output)
    else
      PP.pp(archive.archive_hash, output)
    end
  end
end

#unwrap_objects?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/rxcode/commands/unwrap.rb', line 53

def unwrap_objects?
  !options[:raw]
end