Class: Airake::Commands::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/airake/commands/base.rb

Overview

Base command

Direct Known Subclasses

Acompc, Adl, Adt, Asdoc, FCSH, FlashPlayer, Mxmlc

Instance Method Summary collapse

Instance Method Details

#assert_not_blank(*instance_vars) ⇒ Object



54
55
56
57
58
59
# File 'lib/airake/commands/base.rb', line 54

def assert_not_blank(*instance_vars)
  instance_vars.each do |var|
    instance = instance_variable_get("@#{var}")
    raise ArgumentError, "#{var} can't be blank" if instance.blank?
  end
end

#assert_required(options, keys) ⇒ Object



48
49
50
51
52
# File 'lib/airake/commands/base.rb', line 48

def assert_required(options, keys)        
  keys.each do |key|
    raise ArgumentError, "Missing option: #{key}" unless options.include?(key)
  end
end

#escape(command) ⇒ Object

Escape any spacing



16
17
18
19
20
21
22
23
24
25
# File 'lib/airake/commands/base.rb', line 16

def escape(command)
  if windows?
    if command =~ /\S+\s+\S+/ then 
      command = "\"#{command}\""
    end
  else 
    command = command.to_s.gsub(" ", "\\ ")
  end
  command
end

#include_classes(source_path, include_packages) ⇒ Object

Find classes list from packages, raises error if result is empty



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/airake/commands/base.rb', line 87

def include_classes(source_path, include_packages)
  classes = []
  paths = []
  include_packages.each do |include_package|
    path = File.join(source_path, include_package.gsub(".", "/")) + "/**/*.as"
    paths << path
    Dir[path].each do |file|
      classes << include_package + "." + File.basename(file).gsub(".as", "")
    end
  end
  raise "No classes found at:\n\t#{paths.join("\n\t")}" if classes.empty?
  classes
end

#library_paths(lib_dir) ⇒ Object



61
62
63
64
65
# File 'lib/airake/commands/base.rb', line 61

def library_paths(lib_dir)
  if lib_dir and File.directory?(lib_dir) 
    Dir["#{lib_dir}/*"].collect { |f| escape(f) if File.directory?(f) }.compact 
  end
end

#process(command) ⇒ Object

Process command options array



11
12
13
# File 'lib/airake/commands/base.rb', line 11

def process(command)
  command.compact.join(" ")
end

#relative_path(path, from) ⇒ Object

Get relative path



28
29
30
# File 'lib/airake/commands/base.rb', line 28

def relative_path(path, from)
  Pathname.new(path).relative_path_from(Pathname.new(from))
end

#source_paths(src_dirs = [], lib_dir = nil) ⇒ Object

Returns an array of source paths from src_dirs and lib_dir



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/airake/commands/base.rb', line 68

def source_paths(src_dirs = [], lib_dir = nil)
  source_paths = []
  
  # List of directories in lib/ for source paths
  if lib_dir and File.directory?(lib_dir) 
    source_paths += Dir["#{lib_dir}/*"].collect { |f| escape(f) if File.directory?(f) }.compact 
  end
  
  src_dirs.each do |src_dir|
    if File.directory?(src_dir)
      source_paths << escape(src_dir) 
    else
      raise "Source directory: #{src_dir} is not a directory or does not exist"
    end
  end
  source_paths
end

#windows?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/airake/commands/base.rb', line 32

def windows?
  RUBY_PLATFORM =~ /win32/
end

#with_options(options, defaults = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/airake/commands/base.rb', line 36

def with_options(options, defaults = {}) 
  options.each do |key, value|
    raise "Invalid option: '#{key}' for command: #{self.class}" unless respond_to?(key.to_sym)
    instance_variable_set("@#{key}", value)          
  end
  
  defaults.each do |key, value|
    existing = instance_variable_get("@#{key}")
    instance_variable_set("@#{key}", value) unless existing
  end
end