Class: FeaturePackager

Inherits:
Object
  • Object
show all
Includes:
Logging, RunCommand, YAMLConfig
Defined in:
lib/seabass/feature_packager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFeaturePackager

Returns a new instance of FeaturePackager.



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

def initialize()
  @valid_file_types = ['aspx', 'ascx', 'js', 'css', 'png', 'gif', 'jpeg', 'dll']
end

Instance Attribute Details

#package_dirObject

Returns the value of attribute package_dir.



9
10
11
# File 'lib/seabass/feature_packager.rb', line 9

def package_dir
  @package_dir
end

#source_dirObject

Returns the value of attribute source_dir.



9
10
11
# File 'lib/seabass/feature_packager.rb', line 9

def source_dir
  @source_dir
end

#valid_file_typesObject

Returns the value of attribute valid_file_types.



9
10
11
# File 'lib/seabass/feature_packager.rb', line 9

def valid_file_types
  @valid_file_types
end

Instance Method Details

#executeObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/seabass/feature_packager.rb', line 15

def execute()
  raise "Please specify the directory where the features to package exist" if @source_dir.nil?
  raise "Please specify the directory packages should be placed into" if @package_dir.nil?

  Dir[@source_dir + '/**/feature.yml'].each do |feature|
    next if File.basename(File.dirname(feature)).downcase == File.basename(@source_dir).downcase

    feature_config = YAML.load(File.read(feature))
 
    raise "The feature config does not contain the feature name" if !feature_config.has_key?('name')
    raise "The feature config does not contain the destination name" if !feature_config.has_key?('destination_name')
 
    destination = File.expand_path(File.join(@package_dir, feature_config['name'], feature_config['destination_name']))
    FileUtils.mkdir_p(destination)

    feature_root = File.expand_path(File.dirname(feature) + '/../')

    Dir[feature_root  + '/**/**'].each do |file|
      next if File.directory?(file)
      next if is_not_valid_file_type(file)
      file_destination = File.join(destination, file.gsub(/#{feature_root}/, ''))
      FileUtils.mkdir_p(File.dirname(file_destination)) if(!File.exists?(File.dirname(file_destination)))
      File.copy(file, file_destination)
    end
  end
end