module BBB::Pins::Pinnable
Module which is included in all pins. The module provides the basic interface for a BBB::Pin and also takes care of selecting the right IO
class to work with.
It defines a pinnable?
method to test if the module is properly included in a pin.
Attributes
Public Class Methods
Initializes a Pin
@param position [Symbol] The position of the pin @option opts [Boolean] :mock whether or not to use MockIO
# File lib/BBB/pins/pinnable.rb, line 20 def initialize(position, opts={}) @position = position @opts = opts end
Public Instance Methods
Returns an instance of the IO
class for the pin and memoizes this.
@return [IO]
# File lib/BBB/pins/pinnable.rb, line 30 def io @io ||= mock? ? mock_io : default_io end
Returns if this is a mock pin.
@return [Boolean]
# File lib/BBB/pins/pinnable.rb, line 39 def mock? @mock ||= @opts.fetch(:mock, BBB.configuration.test_mode) end
Always returns true, method is used to test if module is included.
@return [Boolean] true
# File lib/BBB/pins/pinnable.rb, line 48 def pinnable? true end
Private Instance Methods
If a class includes the Pinnable
module, it should overwrite the default_io
method. If this is not done, the module raises an error to point the developer into the right direction.
The default_io
method should return an instantiated object that makes the interface between the filesystem, drivers etc, and the ruby code. Probably the object will behave like an IO
object, relying on the linux kernel and drivers to get things done on the board.
# File lib/BBB/pins/pinnable.rb, line 64 def default_io fail NotImplementedError end