Class: HMap::HMapConstructor

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-hmap-prebuilt/hmap_constructor.rb

Instance Method Summary collapse

Constructor Details

#initializeHMapConstructor

Returns a new instance of HMapConstructor.



5
6
7
# File 'lib/cocoapods-hmap-prebuilt/hmap_constructor.rb', line 5

def initialize
  @bucket = Hash.new
end

Instance Method Details

#add_hmap_with_header_mapping(header_mapping, target_name = nil) ⇒ Object

header_mapping : [Hash=> Hash] Hash of file accessors by header mappings.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cocoapods-hmap-prebuilt/hmap_constructor.rb', line 10

def add_hmap_with_header_mapping(header_mapping, target_name = nil)
  header_mapping.each do |accessor, headers|
    headers.each do |key, paths|
      paths.each do |path|
        pn = Pathname.new(path)
        basename = pn.basename.to_s
        dirname = pn.dirname.to_s + '/'
        # construct hmap hash info
        bucket = Hash['suffix' => basename, 'prefix' => dirname]
        if $use_strict_mode == false
          @bucket[basename] = bucket
        end
        if target_name != nil
          @bucket["#{target_name}/#{basename}"] = bucket
        end
      end
    end
  end
end

#save_to(path) ⇒ Object

Returns : success.

Returns:

  • : success



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cocoapods-hmap-prebuilt/hmap_constructor.rb', line 32

def save_to(path)
  if path != nil && @bucket.empty? == false
    pn = Pathname(path)
    json_path = pn.dirname.to_s + '/temp.json'
    # write hmap json to file
    File.open(json_path, 'w') { |file| file << @bucket.to_json }
    # json to hmap
    success = system("hmap convert #{json_path} #{path}")
    # delete json file
    File.delete(json_path)
    success
  else
    false
  end
end