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.
30 31 32 33 |
# File 'lib/gh/stack.rb', line 30 def initialize( = {}, &block) @options, @stack = {}, [] instance_eval(&block) if block end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/gh/stack.rb', line 14 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.
21 22 23 |
# File 'lib/gh/stack.rb', line 21 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.
48 49 50 51 52 |
# File 'lib/gh/stack.rb', line 48 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: …
55 56 57 |
# File 'lib/gh/stack.rb', line 55 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.
38 39 40 41 |
# File 'lib/gh/stack.rb', line 38 def use(klass, = {}) @stack << [klass, ] self end |