Class: Plist4r::Commands

Defined in:
lib/plist4r/commands.rb

Instance Methods

Overview

This objects manages all of the commands to be executed by an instance of Application

See Also:

Constant Summary

PriorityOrder =
[:ruby_lib]

Instance Method Details

- (Object) ruby_lib

Implements the plist4r --ruby-lib subcommand.

See Also:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/plist4r/commands.rb', line 26

def ruby_lib
  plist4r_root = File.expand_path "../../", File.dirname(__FILE__)
  plist4r_lib = File.expand_path "../../lib", File.dirname(__FILE__)
  dest = File.expand_path(Plist4r::Config[:args][:dir] || FileUtils.pwd)

  raise "sorry, cant write to the same source and destination" if plist4r_lib == dest
  raise "sorry, cant write to a destination within the source folder" if dest =~ /^#{plist4r_lib}/

  FileUtils.mkdir_p dest
  FileUtils.rm_rf "#{dest}/plist4r"
  FileUtils.cp_r Dir.glob("#{plist4r_lib}/*"), dest
  FileUtils.cp_r Dir.glob("#{plist4r_root}/VERSION"), "#{dest}/plist4r"
  
  if Plist4r::Config[:args][:brew]
    backends = Dir.glob "#{dest}/plist4r/backend/*"
    docs = Dir.glob "#{dest}/plist4r/docs*"
    haml4r = Dir.glob "#{dest}/plist4r/mixin/haml4r*"
    non_brew_files = [
      "#{dest}/plist4r/application.rb",
      backends - ["#{dest}/plist4r/backend/ruby_cocoa.rb"],
      "#{dest}/plist4r/cli.rb",
      "#{dest}/plist4r/commands.rb",
      docs,
      haml4r,
      "#{dest}/plist4r/mixin/mixlib_cli.rb",
      "#{dest}/plist4r/mixin/script.rb",
      "#{dest}/plist4r/mixin/table.rb",
    ].flatten
    FileUtils.rm_rf(non_brew_files)

    config = File.read "#{dest}/plist4r/config.rb"
    config.gsub! /backends default_backends/,"backends default_backends :brew"

    File.open("#{dest}/plist4r/config.rb",'w') do |o|
      o << config
    end
  end

end

- (Object) run

To be executed once. Branches out to subroutines, and handles the order-of-execution of those main subrountines.



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

def run
  PriorityOrder.each do |command|
    send command if self.class.method_defined?(command) && Plist4r::Config[:args][command]
  end

  left_to_execute = Plist4r::Config[:args].keys - PriorityOrder
  Plist4r::Config[:args].each do |command, value|
    send command if left_to_execute.include?(command) && self.class.method_defined?(command) && value
  end
end