Class: GH::Stack
- Inherits:
-
Object
- Object
- GH::Stack
- Defined in:
- lib/gh/stack.rb
Overview
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
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.
32 33 34 35 36 |
# File 'lib/gh/stack.rb', line 32 def initialize( = {}, &block) @options = {} @stack = [] instance_eval(&block) if block end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
16 17 18 |
# File 'lib/gh/stack.rb', line 16 def @options 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.
23 24 25 |
# File 'lib/gh/stack.rb', line 23 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.
51 52 53 54 55 |
# File 'lib/gh/stack.rb', line 51 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: …
58 59 60 |
# File 'lib/gh/stack.rb', line 58 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.
41 42 43 44 |
# File 'lib/gh/stack.rb', line 41 def use(klass, = {}) @stack << [klass, ] self end |