Class: Mack::Portlet::Unpacker

Inherits:
Utils::RegistryMap
  • Object
show all
Defined in:
lib/mack/portlets/unpacker.rb

Instance Method Summary collapse

Instance Method Details

#initial_stateObject



28
29
30
# File 'lib/mack/portlets/unpacker.rb', line 28

def initial_state
  {}
end

#unpack(key, force = false) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mack/portlets/unpacker.rb', line 5

def unpack(key, force = false)
  m = self.registered_items[key.to_sym]
  if m
    m.call((force || false))
  else
    Mack.search_path(key.to_sym, false).each do |path|
      Dir.glob(File.join(path, '**/*')).each do |f|
        f = File.expand_path(f)
        dest = f.gsub(path, Mack::Paths.send(key))
        FileUtils.mkdir_p(File.dirname(dest))
        if File.file?(f)
          cp = File.exists?(dest) ? force : true
          if cp
            FileUtils.cp(f, f.gsub(path, Mack::Paths.send(key)), :verbose => true) if cp
          else
            puts "Skipping: #{dest}"
          end
        end
      end
    end
  end
end