Class: FlexPMD

Inherits:
Object
  • Object
show all
Defined in:
lib/flex_pmd/flex_pmd.rb

Instance Method Summary collapse

Instance Method Details

#cdn_fileObject

Return the full web URL of the PMD to download



41
42
43
# File 'lib/flex_pmd/flex_pmd.rb', line 41

def cdn_file
  cdn_file = config["cdn_path"]
end

#configObject

Return a hash of configuration objects from config.yml



4
5
6
7
8
# File 'lib/flex_pmd/flex_pmd.rb', line 4

def config
  require 'yaml'
  config = YAML.load_file(File.expand_path(File.join((File.dirname(__FILE__)), "..", "..", "config.yml")))
  config_hash = config["flex-pmd"]
end

#dest_dirObject

Return the destination (think: vendor) directory to put the PMD into



11
12
13
# File 'lib/flex_pmd/flex_pmd.rb', line 11

def dest_dir
  dest_dir = File.expand_path(File.join((File.dirname(__FILE__)), "..", "..", config["vendor_path"]))
end

#dest_fileObject

Return the full path of target zip file



31
32
33
# File 'lib/flex_pmd/flex_pmd.rb', line 31

def dest_file
  dest_file = File.join(dest_dir, pmd_zipfile)
end

#downloadObject

Download the PMD zip file into the gem’s directory



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/flex_pmd/flex_pmd.rb', line 46

def download
  puts "\n"
  unless File.file?(dest_file)
    puts "Downloading PMD\n\tFrom:\t#{cdn_file}\n\tTo:\t#{dest_file}\n\n"
    `curl #{cdn_file} --create-dirs -o #{dest_file} `
    if $?.to_i != 0
      raise "Failed to download Flex PMD\n\n"
    end
  else
    puts "Won't download PMD, file #{dest_file} already exists"
  end
end

#pmd_dirObject

Return the full path to the PMD dir, so other things/people can use it



36
37
38
# File 'lib/flex_pmd/flex_pmd.rb', line 36

def pmd_dir
  pmd_dir = File.join(dest_dir, pmd_name)
end

#pmd_nameObject

Return the human readable name of the PMD



21
22
23
# File 'lib/flex_pmd/flex_pmd.rb', line 21

def pmd_name
  pmd_name = "flex_pmd_" + pmd_ver
end

#pmd_verObject

Return the version PMD



16
17
18
# File 'lib/flex_pmd/flex_pmd.rb', line 16

def pmd_ver
  pmd_ver = config["pmd_ver"]
end

#pmd_zipfileObject

Return just the file name of the target zip file



26
27
28
# File 'lib/flex_pmd/flex_pmd.rb', line 26

def pmd_zipfile
  pmd_zipfile = pmd_name + ".zip"
end

#unzipObject

Unzip the downloaded zip file into the target dir



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

def unzip
  puts "\n"
  unless File.directory?(pmd_dir)
    puts "Unzipping PMD\n\tFrom:\t#{dest_file}\n\tTo:\t#{pmd_dir}/\n\n"
    `unzip #{dest_file} -d #{pmd_dir}`
    if $?.to_i != 0
      raise "Failed to unzip Flex PMD\n\n"
    end
  else
    puts "Won't unzip PMD, directory #{pmd_dir}/ already exists\n\n"
  end
end