Module: MIDICommunications::Device::InstanceMethods
Overview
Methods that are shared by both Input and Output instances
Class Method Summary collapse
-
.included(base) ⇒ Object
Add attributes for the device instance :direction, :id, :name.
Instance Method Summary collapse
-
#close(*args) ⇒ Boolean
Close the device Params are passed to the underlying device object.
-
#closed? ⇒ Boolean
Returns true if the device is not enabled.
- #initialize(device) ⇒ Object
-
#open(*args) ⇒ Input, Output
Enable the device for use Params are passed to the underlying device object Can be passed a block to which the device will be passed in as the yieldparam.
Class Method Details
.included(base) ⇒ Object
Add attributes for the device instance :direction, :id, :name
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/midi-communications/device.rb', line 160 def self.included(base) base.send(:attr_reader, :direction) base.send(:attr_reader, :enabled) base.send(:attr_reader, :id) base.send(:attr_reader, :manufacturer) base.send(:attr_reader, :model) base.send(:attr_reader, :name) base.send(:attr_reader, :display_name) base.send(:alias_method, :enabled?, :enabled) base.send(:alias_method, :type, :direction) end |
Instance Method Details
#close(*args) ⇒ Boolean
Close the device Params are passed to the underlying device object
142 143 144 145 146 147 148 149 150 |
# File 'lib/midi-communications/device.rb', line 142 def close(*args) if @enabled @device.close(*args) @enabled = false true else false end end |
#closed? ⇒ Boolean
Returns true if the device is not enabled
154 155 156 |
# File 'lib/midi-communications/device.rb', line 154 def closed? !@enabled end |
#initialize(device) ⇒ Object
107 108 109 110 111 112 |
# File 'lib/midi-communications/device.rb', line 107 def initialize(device) @device = device @enabled = false populate_from_device end |
#open(*args) ⇒ Input, Output
Enable the device for use Params are passed to the underlying device object Can be passed a block to which the device will be passed in as the yieldparam
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/midi-communications/device.rb', line 119 def open(*args) unless @enabled @device.open(*args) @enabled = true end if block_given? begin yield(self) ensure close end else at_exit do close end end self end |