Class: GH::Stack
- Inherits:
-
Object
- Object
- GH::Stack
- Defined in:
- lib/gh/stack.rb
Overview
Class Method Summary collapse
-
.build(options, &block) ⇒ Object
Public: Generates a new wrapper stack from the given block.
Instance Method Summary collapse
-
#build(options = {}) ⇒ Object
(also: #new)
Public: Generates wrapper instances for stack configuration.
-
#initialize(options = {}, &block) ⇒ Stack
constructor
Public: Generates a new Stack instance.
-
#replace(old_class, new_class) ⇒ Object
Public: …
-
#use(klass, options = {}) ⇒ Object
Public: Adds a new layer to the stack.
Constructor Details
#initialize(options = {}, &block) ⇒ Stack
Public: Generates a new Stack instance.
options - Hash of options that will be passed to all layers upon initialization.
Can be used for easly stacking layers.
28 29 30 31 |
# File 'lib/gh/stack.rb', line 28 def initialize( = {}, &block) @options, @stack = {}, [] instance_eval(&block) if block end |
Class Method Details
.build(options, &block) ⇒ Object
Public: Generates a new wrapper stack from the given block.
options - Hash of options that will be passed to all layers upon initialization.
Returns top most Wrapper instance.
19 20 21 |
# File 'lib/gh/stack.rb', line 19 def self.build(, &block) new(&block).build() end |
Instance Method Details
#build(options = {}) ⇒ Object Also known as: new
Public: Generates wrapper instances for stack configuration.
options - Hash of options that will be passed to all layers upon initialization.
Returns top most Wrapper instance.
46 47 48 49 50 |
# File 'lib/gh/stack.rb', line 46 def build( = {}) @stack.reverse.inject(nil) do |backend, (klass, opts)| klass.new backend, @options.merge(opts).merge() end end |
#replace(old_class, new_class) ⇒ Object
Public: …
53 54 55 |
# File 'lib/gh/stack.rb', line 53 def replace(old_class, new_class) @stack.map! { |klass, | [old_class == klass ? new_class : klass, ] } end |
#use(klass, options = {}) ⇒ Object
Public: Adds a new layer to the stack.
Layer will be wrapped by layers already on the stack.
36 37 38 39 |
# File 'lib/gh/stack.rb', line 36 def use(klass, = {}) @stack << [klass, ] self end |