Class: FSEvent::SimpleDevice

Inherits:
AbstractDevice show all
Defined in:
lib/fsevent/simpledevice.rb

Overview

simpledevice.rb — simple device definition using constructor arguments

Copyright © 2014 National Institute of Advanced Industrial Science and Technology (AIST)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <www.gnu.org/licenses/>.

Instance Attribute Summary collapse

Attributes inherited from AbstractDevice

#framework, #name, #schedule

Instance Method Summary collapse

Methods inherited from AbstractDevice

#add_watch, #define_status, #set_elapsed_time, #status_changed, #unregister_device, #unregistered

Constructor Details

#initialize(device_name, initial_status, watches, registered_elapsed_time, schedule = nil, &run_block) ⇒ SimpleDevice

Returns a new instance of SimpleDevice.



19
20
21
22
23
24
25
26
27
# File 'lib/fsevent/simpledevice.rb', line 19

def initialize(device_name, initial_status, watches, registered_elapsed_time, schedule=nil, &run_block)
  super device_name
  @name = device_name
  @initial_status = initial_status
  @watches = watches
  @registered_elapsed_time = registered_elapsed_time
  @schedule.merge_schedule schedule if schedule
  @run_block = run_block
end

Instance Attribute Details

#registered_elapsed_time=(value) ⇒ Object (writeonly)

Sets the attribute registered_elapsed_time

Parameters:

  • value

    the value to set the attribute registered_elapsed_time to.



28
29
30
# File 'lib/fsevent/simpledevice.rb', line 28

def registered_elapsed_time=(value)
  @registered_elapsed_time = value
end

Instance Method Details

#registeredObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fsevent/simpledevice.rb', line 30

def registered
  @initial_status.each {|status_name, value|
    define_status status_name, value
  }
  @watches.each {|watchee_device_name, status_name, reaction|
    reaction ||= :immediate
    add_watch watchee_device_name, status_name, reaction
  }
  if @registered_elapsed_time
    set_elapsed_time @registered_elapsed_time
  end
end

#run(watched_status_change) ⇒ Object



43
44
45
# File 'lib/fsevent/simpledevice.rb', line 43

def run(watched_status_change)
  @run_block.call watched_status_change
end