Class: Grumlin::Shortcuts::Storage

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/grumlin/shortcuts/storage.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(storage = {}) ⇒ Storage

Returns a new instance of Storage.



16
17
18
19
20
21
# File 'lib/grumlin/shortcuts/storage.rb', line 16

def initialize(storage = {})
  @storage = storage
  storage.each do |n, s|
    add(n, s)
  end
end

Class Method Details

.[](other) ⇒ Object



7
8
9
# File 'lib/grumlin/shortcuts/storage.rb', line 7

def [](other)
  new(other)
end

.emptyObject



11
12
13
# File 'lib/grumlin/shortcuts/storage.rb', line 11

def empty
  @empty ||= new
end

Instance Method Details

#==(other) ⇒ Object



28
29
30
# File 'lib/grumlin/shortcuts/storage.rb', line 28

def ==(other)
  @storage == other.storage
end

#__Object



53
54
55
# File 'lib/grumlin/shortcuts/storage.rb', line 53

def __
  traversal_start_class.new
end

#add(name, shortcut) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/grumlin/shortcuts/storage.rb', line 32

def add(name, shortcut)
  @storage[name] = shortcut

  sc = step_class

  shortcut_methods_module.define_method(name) do |*args, **params|
    next sc.new(name, args:, params:, previous_step: self, pool:)
  end
  extend_traversal_classes(shortcut) unless shortcut.lazy?
end

#add_from(other) ⇒ Object



43
44
45
46
47
# File 'lib/grumlin/shortcuts/storage.rb', line 43

def add_from(other)
  other.storage.each do |name, shortcut|
    add(name, shortcut)
  end
end

#g(middlewares: Grumlin.default_middlewares) ⇒ Object



49
50
51
# File 'lib/grumlin/shortcuts/storage.rb', line 49

def g(middlewares: Grumlin.default_middlewares)
  traversal_start_class.new(pool: Grumlin.default_pool, middlewares:)
end

#step_classObject



61
62
63
# File 'lib/grumlin/shortcuts/storage.rb', line 61

def step_class
  @step_class ||= shortcut_aware_class(Grumlin::Step)
end

#traversal_start_classObject



57
58
59
# File 'lib/grumlin/shortcuts/storage.rb', line 57

def traversal_start_class
  @traversal_start_class ||= shortcut_aware_class(Grumlin::TraversalStart)
end