Class: Dotum::AbstractRules::GlobbableFiles

Inherits:
OptionsBase show all
Defined in:
lib/dotum/abstract_rules/globbable_files.rb

Direct Known Subclasses

Rules::Link

Constant Summary collapse

GLOB_MATCHER =
/\*/
DIR_MATCHER =
/[\/\\]$/

Instance Attribute Summary

Attributes inherited from Base

#context

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OptionsBase

exec, #initialize

Methods inherited from Base

exec, #exec, #initialize, pretty

Methods included from RuleOptionsDSL

#eval_options_block, #expand_shorthand, #option_configs, #option_defaults, #optional, #preprocessor_methods, #register_preprocessor, #required, #shorthand, #shorthand_config, #standard, #validate_options

Methods included from RuleDSL

#available?, #failure!, #method_missing, #package_dir, #platform?, #skip!, #state_dir, #success!, #target_dir

Constructor Details

This class inherits a constructor from Dotum::AbstractRules::OptionsBase

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Dotum::RuleDSL

Class Method Details

.expand_options(context, options) ⇒ Object



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
41
42
43
44
45
# File 'lib/dotum/abstract_rules/globbable_files.rb', line 15

def self.expand_options(context, options)
  source      = options[:source]
  destination = options[:destination]

  source_is_glob = GLOB_MATCHER === source
  target_is_dir  = DIR_MATCHER  === destination if destination
  if source_is_glob && destination && !target_is_dir
    raise "target path must be a directory when linking a glob expression."
  end

  sources = context.package_dir.relative_glob(source, &:file?)
  if sources.size > 1 && destination && !target_is_dir
    raise "Bug!  target path is a file, but we globbed multiple sources!"
  end

  sources.reject! { |p| options[:ignore_pattern] =~ p }

  sources.map { |source_path|
    # Behave like `ln` if the target is a directory; the file is made a direct
    # descendent of that directory.
    if target_is_dir
      destination_path = File.join(destination, File.basename(source_path))
    elsif destination
      destination_path = destination
    else
      destination_path = source_path
    end

    options.merge(:source => source_path, :destination => destination_path)
  }
end

Instance Method Details

#pretty_subjectObject



47
48
49
# File 'lib/dotum/abstract_rules/globbable_files.rb', line 47

def pretty_subject
  "#{@destination.pretty} (#{@source.pretty})"
end