Class: Guard::Copy::Target

Inherits:
Object
  • Object
show all
Defined in:
lib/guard/copy/target.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, options = {}) ⇒ Target

Initialize a new target

Parameters:

  • pattern (String)

    the pattern for this target

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • glob (Symbol)

    target resolution mode, ‘:newest` or `:all`

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
# File 'lib/guard/copy/target.rb', line 12

def initialize(pattern, options = {})
  raise ArgumentError, 'pattern cannot be nil' unless pattern
  raise ArgumentError, 'pattern cannot be empty' if pattern.empty?
  @pattern = pattern
  @glob = options[:glob] || :all
  @expand_pattern = !options[:mkpath]
  @paths = []
end

Instance Attribute Details

#globObject (readonly)

Returns the value of attribute glob.



5
6
7
# File 'lib/guard/copy/target.rb', line 5

def glob
  @glob
end

#pathsObject (readonly)

Returns the value of attribute paths.



5
6
7
# File 'lib/guard/copy/target.rb', line 5

def paths
  @paths
end

#patternObject (readonly)

Returns the value of attribute pattern.



5
6
7
# File 'lib/guard/copy/target.rb', line 5

def pattern
  @pattern
end

Instance Method Details

#absolute?Boolean

Returns true if the pattern is an absolute path.

Returns:

  • (Boolean)

    true if the pattern is an absolute path



33
34
35
# File 'lib/guard/copy/target.rb', line 33

def absolute?
  pattern.start_with?('/')
end

#resolve!Object

Resolve the target into one or more paths



22
23
24
25
26
27
28
29
30
# File 'lib/guard/copy/target.rb', line 22

def resolve!
  paths.clear
  if expand_pattern?
    expand_pattern
  else
    paths << pattern
  end
  warn_if_empty
end