Class: Katarina::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/katarina/schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, controller, action, http_method, response_code, schema) ⇒ Schema

Returns a new instance of Schema.



9
10
11
12
13
14
15
16
# File 'lib/katarina/schema.rb', line 9

def initialize(path, controller, action, http_method, response_code, schema)
  @path = path
  @controller = controller
  @action = action
  @http_method = http_method
  @response_code = response_code
  @schema = schema
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



7
8
9
# File 'lib/katarina/schema.rb', line 7

def controller
  @controller
end

Instance Method Details

#nameObject



26
27
28
29
30
31
32
33
# File 'lib/katarina/schema.rb', line 26

def name
  [
    prefix,
    *Katarina::Path.include_paths(@controller.split('/')),
    action,
    response_code.to_s
  ].map(&:camelize).join
end

#types(schema = @schema) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/katarina/schema.rb', line 18

def types(schema = @schema)
  case schema
  in { type: 'object', properties: } then build_object(properties)
  in { type: 'array', items: }       then [types(items)]
  in { type: type }                  then type
  end
end