Class: Wake::Script::Rule
- Inherits:
-
Struct
- Object
- Struct
- Wake::Script::Rule
- Defined in:
- lib/wake/script.rb,
lib/wake/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
64 65 66 |
# File 'lib/wake/script.rb', line 64 def action @action end |
#batch ⇒ Object
Returns the value of attribute batch
64 65 66 |
# File 'lib/wake/script.rb', line 64 def batch @batch end |
#event_types ⇒ Object
Returns the value of attribute event_types
64 65 66 |
# File 'lib/wake/script.rb', line 64 def event_types @event_types end |
#options ⇒ Object
Returns the value of attribute options
64 65 66 |
# File 'lib/wake/script.rb', line 64 def @options end |
#pattern ⇒ Object
Returns the value of attribute pattern
64 65 66 |
# File 'lib/wake/script.rb', line 64 def pattern @pattern end |
#predicate ⇒ Object
Returns the value of attribute predicate
64 65 66 |
# File 'lib/wake/script.rb', line 64 def predicate @predicate end |
Instance Method Details
#call(data, event, path) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/wake/script.rb', line 68 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 res = nil if action.arity == 1 res = action.call data elsif action.arity == 2 res = action.call data, event else res = action.call data, event, path end Script.learn path res end end |
#match(path) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/wake/script.rb', line 98 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
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/wake/script.rb', line 87 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 |