Class: Watchr::Script::Rule
- Inherits:
-
Struct
- Object
- Struct
- Watchr::Script::Rule
- Defined in:
- lib/watchr/script.rb,
lib/watchr/script.rb
Overview
Convenience type. Provides clearer and simpler access to rule properties.
Examples
rule = script.watch('lib/.*\.rb') { 'ohaie' }
rule.pattern #=> 'lib/.*\.rb'
rule.action.call #=> 'ohaie'
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#batch ⇒ Object
Returns the value of attribute batch.
-
#event_types ⇒ Object
Returns the value of attribute event_types.
-
#options ⇒ Object
Returns the value of attribute options.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
-
#predicate ⇒ Object
Returns the value of attribute predicate.
Instance Method Summary collapse
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action
60 61 62 |
# File 'lib/watchr/script.rb', line 60 def action @action end |
#batch ⇒ Object
Returns the value of attribute batch
60 61 62 |
# File 'lib/watchr/script.rb', line 60 def batch @batch end |
#event_types ⇒ Object
Returns the value of attribute event_types
60 61 62 |
# File 'lib/watchr/script.rb', line 60 def event_types @event_types end |
#options ⇒ Object
Returns the value of attribute options
60 61 62 |
# File 'lib/watchr/script.rb', line 60 def @options end |
#pattern ⇒ Object
Returns the value of attribute pattern
60 61 62 |
# File 'lib/watchr/script.rb', line 60 def pattern @pattern end |
#predicate ⇒ Object
Returns the value of attribute predicate
60 61 62 |
# File 'lib/watchr/script.rb', line 60 def predicate @predicate end |
Instance Method Details
#call(data, event, path) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/watchr/script.rb', line 64 def call data, event, path # $stderr.print "call #{data} #{event} #{path}\n" if [:batch] self.batch ||= Batch.new self batch.call data, event, path else if action.arity == 1 action.call data elsif action.arity == 2 action.call data, event else action.call data, event, path end Script.learn path end end |
#match(path) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/watchr/script.rb', line 92 def match path # $stderr.print("match #{path}\n") pattern = self.pattern ( pattern.class == String ) and ( pattern = Regexp.new pattern ) # p path, pattern, pattern.match(path) ( md = pattern.match(path) ) && ( self.predicate == nil || self.predicate.call(md) ) end |
#watch(path) ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/watchr/script.rb', line 81 def watch path watch = nil pattern = self.pattern ( pattern.class == String ) and ( pattern = Regexp.new pattern ) md = pattern.match(path) if md watch = self.predicate.nil? || self.predicate.call(md) end return watch end |