Class: ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::RubyMiddleware

Inherits:
Dependencies::Extractions::RubyMiddleware::Middleware::Builder show all
Defined in:
lib/convenient_service/support/middleware/stack_builder/entities/builders/ruby_middleware.rb

Instance Method Summary collapse

Methods inherited from Dependencies::Extractions::RubyMiddleware::Middleware::Builder

#call, #delete, #flatten, #inject_logger, #insert, #insert_after, #insert_after_each, #insert_before_each, #inspect, #name, #replace, #use

Constructor Details

#initialize(opts = {}, &block) ⇒ void



25
26
27
28
29
30
31
32
33
34
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/ruby_middleware.rb', line 25

def initialize(opts = {}, &block)
  super

  @middleware_name = opts.fetch(:name) { "Stack" }

  ##
  # https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/builder.rb#L174
  #
  self.stack = opts[:stack] if opts.has_key?(:stack)
end

Instance Method Details

#==(other) ⇒ Boolean?

Parameters:

Returns:

  • (Boolean, nil)


95
96
97
98
99
100
101
102
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/ruby_middleware.rb', line 95

def ==(other)
  return unless other.instance_of?(self.class)

  return false if name != other.name
  return false if stack != other.stack

  true
end

#clearBoolean

Returns:

  • (Boolean)


54
55
56
57
58
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/ruby_middleware.rb', line 54

def clear
  stack.clear

  self
end

#dupConvenientService::Support::Middleware::StackBuilder



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/ruby_middleware.rb', line 123

def dup
  self.class.new(
    ##
    # https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/builder.rb#L45
    #
    runner_class: @runner_class,
    ##
    # https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/builder.rb#L46
    #
    name: @middleware_name.dup,
    ##
    # https://github.com/marian13/ruby-middleware/blob/v0.4.2/lib/middleware/builder.rb#L167
    #
    stack: stack.dup
  )
end

#empty?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/ruby_middleware.rb', line 39

def empty?
  stack.empty?
end

#has?(some_middleware) ⇒ Boolean

Parameters:

  • some_middleware (#call<Hash>)

Returns:

  • (Boolean)


47
48
49
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/ruby_middleware.rb', line 47

def has?(some_middleware)
  stack.any? { |middleware| middleware == [some_middleware, [], nil] }
end

#to_aArray

Returns:

  • (Array)


113
114
115
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/ruby_middleware.rb', line 113

def to_a
  stack.map(&:first)
end

#unshift(middleware, *args, &block) ⇒ ConvenientService::Support::Middleware::StackBuilder::Entities::Builders::RubyMiddleware Also known as: prepend

Parameters:

  • middleware (#call<Hash>)
  • args (Array<Object>)
  • block (Proc, nil)

Returns:



69
70
71
72
73
# File 'lib/convenient_service/support/middleware/stack_builder/entities/builders/ruby_middleware.rb', line 69

def unshift(middleware, *args, &block)
  stack.unshift([middleware, args, block])

  self
end