Class: Respect::Rails::ActionSchema

Inherits:
Object
  • Object
show all
Includes:
DocHelper
Defined in:
lib/respect/rails/action_schema.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (ActionSchema) initialize(controller, action_name)

A new instance of ActionSchema



17
18
19
20
21
# File 'lib/respect/rails/action_schema.rb', line 17

def initialize(controller, action_name)
  @controller = controller
  @action_name = action_name
  @responses = ResponseSchemaSet.new(controller_name, @action_name)
end

Instance Attribute Details

- (Object) action_name (readonly)

Returns the value of attribute action_name



23
24
25
# File 'lib/respect/rails/action_schema.rb', line 23

def action_name
  @action_name
end

- (Object) controller (readonly)

Returns the value of attribute controller



23
24
25
# File 'lib/respect/rails/action_schema.rb', line 23

def controller
  @controller
end

- (Object) documentation

Returns the value of attribute documentation



38
39
40
# File 'lib/respect/rails/action_schema.rb', line 38

def documentation
  @documentation
end

- (Object) request

Returns the value of attribute request



29
30
31
# File 'lib/respect/rails/action_schema.rb', line 29

def request
  @request
end

- (Object) responses (readonly)

Returns the value of attribute responses



31
32
33
# File 'lib/respect/rails/action_schema.rb', line 31

def responses
  @responses
end

Class Method Details

+ (Object) define(*args, &block)



12
13
14
# File 'lib/respect/rails/action_schema.rb', line 12

def define(*args, &block)
  ActionDef.eval(*args, &block)
end

+ (Object) from_controller(controller_name, action_name)



7
8
9
10
# File 'lib/respect/rails/action_schema.rb', line 7

def from_controller(controller_name, action_name)
  klass = "#{controller_name}_controller".classify.safe_constantize
  @schema = klass.new.action_schema(action_name) if klass
end

Instance Method Details

- (Object) controller_name



25
26
27
# File 'lib/respect/rails/action_schema.rb', line 25

def controller_name
  @controller.controller_name
end

- (Boolean) has_schema?

Whether there is at least a request schema or one response schema for this action.

Returns:

  • (Boolean)


34
35
36
# File 'lib/respect/rails/action_schema.rb', line 34

def has_schema?
  request || !responses.empty? || documentation
end