Module: SimpleEndpoint::Controller::ClassMethods

Defined in:
lib/simple_endpoint/controller/class_methods.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_casesObject

Returns the value of attribute default_cases.



6
7
8
# File 'lib/simple_endpoint/controller/class_methods.rb', line 6

def default_cases
  @default_cases
end

#default_handlerObject

Returns the value of attribute default_handler.



6
7
8
# File 'lib/simple_endpoint/controller/class_methods.rb', line 6

def default_handler
  @default_handler
end

Instance Method Details

#cases(inherit: true, &block) ⇒ Object



20
21
22
23
24
# File 'lib/simple_endpoint/controller/class_methods.rb', line 20

def cases(inherit: true, &block)
  builder = Builder.new(&block)
  self.default_cases = ((inherit && default_cases) || {}).merge(builder.to_h)
  define_method(:default_cases) { self.class.default_cases }
end

#endpoint_options(inherit: true, &block) ⇒ Object



26
27
28
29
30
# File 'lib/simple_endpoint/controller/class_methods.rb', line 26

def endpoint_options(inherit: true, &block)
  define_method(:endpoint_options) do
    (inherit ? super() : {}).merge(instance_exec(&block))
  end
end

#handler(inherit: true, &block) ⇒ Object



14
15
16
17
18
# File 'lib/simple_endpoint/controller/class_methods.rb', line 14

def handler(inherit: true, &block)
  builder = Builder.new(&block)
  self.default_handler = ((inherit && default_handler) || {}).merge(builder.to_h)
  define_method(:default_handler) { self.class.default_handler }
end

#inherited(subclass) ⇒ Object



8
9
10
11
12
# File 'lib/simple_endpoint/controller/class_methods.rb', line 8

def inherited(subclass)
  super
  subclass.default_handler = default_handler.dup
  subclass.default_cases = default_cases.dup
end