class Praxis::ApiDefinition
Attributes
global_info[R]
infos[R]
responses[R]
traits[R]
versioning_scheme[RW]
Public Class Methods
define() { |instance| ... }
click to toggle source
# File lib/praxis/api_definition.rb, line 17 def self.define(&block) if block.arity == 0 self.instance.instance_eval(&block) else yield(self.instance) end end
new()
click to toggle source
# File lib/praxis/api_definition.rb, line 25 def initialize @responses = Hash.new @traits = Hash.new @base_path = '' @global_info = ApiGeneralInfo.new @infos = Hash.new do |hash, version| hash[version] = ApiGeneralInfo.new(@global_info, version: version) end end
Public Instance Methods
describe()
click to toggle source
# File lib/praxis/api_definition.rb, line 71 def describe data = Hash.new do |hash, version| hash[version] = Hash.new end data[:global][:info] = @global_info.describe # Fill in the "info" portion @infos.each do |version,info| data[version][:info] = info.describe end if traits.any? data[:traits] = {} traits.each do |name, trait| data[:traits][name] = trait.describe end end data end
info(version=nil, &block)
click to toggle source
Setting info to the nil version, means setting it for all versions (if they don't override them)
# File lib/praxis/api_definition.rb, line 55 def info(version=nil, &block) if version.nil? if block_given? @global_info.instance_eval(&block) else @global_info end else i = @infos[version] if block_given? i.instance_eval(&block) end i end end
response(name)
click to toggle source
# File lib/praxis/api_definition.rb, line 41 def response(name) return @responses.fetch(name) do raise ArgumentError, "no response template defined with name #{name.inspect}. Are you forgetting to register it with ApiDefinition?" end end
response_template(name, &block)
click to toggle source
# File lib/praxis/api_definition.rb, line 37 def response_template(name, &block) @responses[name] = Praxis::ResponseTemplate.new(name, &block) end
trait(name, &block)
click to toggle source
# File lib/praxis/api_definition.rb, line 47 def trait(name, &block) if self.traits.has_key? name raise Exceptions::InvalidTrait.new("Overwriting a previous trait with the same name (#{name})") end self.traits[name] = Trait.new(&block) end