Class: Praxis::ResponseTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/praxis/response_template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response_name, &block) ⇒ ResponseTemplate

Returns a new instance of ResponseTemplate.



6
7
8
9
# File 'lib/praxis/response_template.rb', line 6

def initialize(response_name, &block)
  @name = response_name
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



4
5
6
# File 'lib/praxis/response_template.rb', line 4

def block
  @block
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/praxis/response_template.rb', line 4

def name
  @name
end

Instance Method Details

#compile(action = nil, **args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/praxis/response_template.rb', line 11

def compile(action=nil, **args)
  # Default media_type to the resource_definition one, if the block has it in
  # its required args but no value is passed (funky, but can help in the common case)
  if block.parameters.any? { |(type, name)| name == :media_type && type == :keyreq } && action
    unless args.has_key? :media_type
      media_type = action.resource_definition.media_type
      unless media_type
        raise Exceptions::InvalidConfiguration.new(
          "Could not default :media_type argument for response template #{@name}." +
           " Resource #{action.resource_definition} does not have an associated mediatype and none was passed"
        )
      end
      args[:media_type] = media_type
    end
  end
  Praxis::ResponseDefinition.new(name, **args, &block)   
end

#describeObject



29
30
31
# File 'lib/praxis/response_template.rb', line 29

def describe
  puts "TODO!!!!!!"
end