Class: Guard::Copy::Target
- Inherits:
-
Object
- Object
- Guard::Copy::Target
- Defined in:
- lib/guard/copy/target.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
-
#absolute? ⇒ Boolean
True if the pattern is an absolute path.
-
#initialize(pattern, options = {}) ⇒ Target
constructor
Initialize a new target.
-
#resolve ⇒ Boolean
Resolve the target into one or more paths.
Constructor Details
#initialize(pattern, options = {}) ⇒ Target
Initialize a new target
12 13 14 15 16 17 18 19 20 |
# File 'lib/guard/copy/target.rb', line 12 def initialize(pattern, = {}) raise ArgumentError, 'pattern cannot be nil' unless pattern raise ArgumentError, 'pattern cannot be empty' if pattern.empty? @pattern = pattern @options = { :glob => :all }.merge() @paths = [] end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/guard/copy/target.rb', line 5 def @options end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
5 6 7 |
# File 'lib/guard/copy/target.rb', line 5 def paths @paths end |
#pattern ⇒ Object (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.
36 37 38 |
# File 'lib/guard/copy/target.rb', line 36 def absolute? @pattern.start_with?('/') end |
#resolve ⇒ Boolean
Resolve the target into one or more paths
25 26 27 28 29 30 31 32 33 |
# File 'lib/guard/copy/target.rb', line 25 def resolve @paths.clear if @options[:glob] == :newest @paths.concat(Dir[@pattern].sort_by { |f| File.mtime(f) }.last(1)) else @paths.concat(Dir[@pattern]) end @paths.any? end |