Class: Flutterby::NodeExtension

Inherits:
Module
  • Object
show all
Defined in:
lib/flutterby/node_extension.rb

Overview

NodeExtension is a subclass of Module that also provides a convenient ‘setup` method for quick creation of initialization code. It’s used to wrap the blocks of code passed to Flutterby::Node::Staging#extend_all and friends, but can also be used directly through ‘NodeExtension.new { … }`.

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ NodeExtension

Returns a new instance of NodeExtension.



8
9
10
11
# File 'lib/flutterby/node_extension.rb', line 8

def initialize(*args)
  @_setup_procs = []
  super
end

Instance Method Details

#extended(base) ⇒ Object



13
14
15
16
17
# File 'lib/flutterby/node_extension.rb', line 13

def extended(base)
  if @_setup_procs.any?
    base._setup_procs.append(*@_setup_procs)
  end
end

#on_setup(&blk) ⇒ Object



19
20
21
# File 'lib/flutterby/node_extension.rb', line 19

def on_setup(&blk)
  @_setup_procs << blk
end