lib/denko/behaviors/component.rb in denko-0.13.6 vs lib/denko/behaviors/component.rb in denko-0.14.0

- old
+ new

@@ -1,30 +1,36 @@ module Denko module Behaviors module Component + attr_reader :board, :params include State - attr_reader :board def initialize(options={}) - super(options) - before_initialize(options) - initialize_board(options) - convert_pins(options) - initialize_pins(options) + @params = options + run_before_initialize_cbs + + initialize_board + convert_pins(params) + initialize_pins(params) register - after_initialize(options) + + run_after_initialize_cbs end def micro_delay(duration) board.micro_delay(duration) end + def board_is_register? + @board_is_register ||= board.class.ancestors.include?(SPI::BaseRegister) + end + protected - def initialize_board(options={}) - raise ArgumentError, 'a board is required for a component' unless options[:board] - @board = options[:board] + def initialize_board + raise ArgumentError, 'a board is required for a component' unless params[:board] + @board = params[:board] end def register board.add_component(self) end @@ -34,15 +40,11 @@ end # Behaviors::Component only requires a board. # Include modules from Setup or override this to use pins. # - def before_initialize(options={}); end def convert_pins(options={}); end def initialize_pins(options={}); end alias :initialize_pin :initialize_pins - - # Override in components. Call super when inheriting or mixing in. - def after_initialize(options={}); end end end end