module RspecApiDocumentation::DSL::Resource::ClassMethods
Public Class Methods
define_action(method)
click to toggle source
# File lib/rspec_api_documentation/dsl/resource.rb, line 7 def self.define_action(method) define_method method do |*args, &block| options = args.extract_options! options[:method] = method if metadata[:route_uri] options[:route] = metadata[:route_uri] options[:action_name] = args.first else options[:route] = args.first end options[:api_doc_dsl] = :endpoint args.push(options) args[0] = "#{method.to_s.upcase} #{args[0]}" context(*args, &block) end end
Public Instance Methods
attribute(name, *args)
click to toggle source
# File lib/rspec_api_documentation/dsl/resource.rb, line 61 def attribute(name, *args) attributes.push(field_specification(name, *args)) end
authentication(type, value, opts = {})
click to toggle source
# File lib/rspec_api_documentation/dsl/resource.rb, line 73 def authentication(type, value, opts = {}) name, new_opts = case type when :basic then ['Authorization', opts.merge(type: type)] when :apiKey then [opts[:name], opts.merge(type: type, in: :header)] else raise 'Not supported type for authentication' end header(name, value) authentications[name] = new_opts end
callback(*args, &block)
click to toggle source
# File lib/rspec_api_documentation/dsl/resource.rb, line 31 def callback(*args, &block) begin require 'webmock' rescue LoadError raise "Callbacks require webmock to be installed" end self.send(:include, WebMock::API) options = if args.last.is_a?(Hash) then args.pop else {} end options[:api_doc_dsl] = :callback args.push(options) context(*args, &block) end
explanation(text)
click to toggle source
# File lib/rspec_api_documentation/dsl/resource.rb, line 92 def explanation(text) safe_metadata(:resource_explanation, text) end
header(name, value)
click to toggle source
# File lib/rspec_api_documentation/dsl/resource.rb, line 69 def header(name, value) headers[name] = value end
parameter(name, *args)
click to toggle source
# File lib/rspec_api_documentation/dsl/resource.rb, line 57 def parameter(name, *args) parameters.push(field_specification(name, *args)) end
response_field(name, *args)
click to toggle source
# File lib/rspec_api_documentation/dsl/resource.rb, line 65 def response_field(name, *args) response_fields.push(field_specification(name, *args)) end
route(*args, &block)
click to toggle source
# File lib/rspec_api_documentation/dsl/resource.rb, line 46 def route(*args, &block) raise "You must define the route URI" if args[0].blank? raise "You must define the route name" if args[1].blank? options = args.extract_options! options[:route_uri] = args[0].gsub(/\{.*\}/, "") options[:route_optionals] = (optionals = args[0].match(/(\{.*\})/) and optionals[-1]) options[:route_name] = args[1] args.push(options) context(*args, &block) end
route_description(text)
click to toggle source
# File lib/rspec_api_documentation/dsl/resource.rb, line 88 def route_description(text) safe_metadata(:route_description, text) end
route_summary(text)
click to toggle source
# File lib/rspec_api_documentation/dsl/resource.rb, line 84 def route_summary(text) safe_metadata(:route_summary, text) end
Private Instance Methods
attributes()
click to toggle source
# File lib/rspec_api_documentation/dsl/resource.rb, line 117 def attributes safe_metadata(:attributes, []) end
authentications()
click to toggle source
# File lib/rspec_api_documentation/dsl/resource.rb, line 129 def authentications safe_metadata(:authentications, {}) end
field_specification(name, *args)
click to toggle source
# File lib/rspec_api_documentation/dsl/resource.rb, line 98 def field_specification(name, *args) options = args.extract_options! description = args.pop || "#{Array(options[:scope]).join(" ")} #{name}".humanize options.merge(:name => name.to_s, :description => description) end
headers()
click to toggle source
# File lib/rspec_api_documentation/dsl/resource.rb, line 125 def headers safe_metadata(:headers, {}) end
parameter_keys()
click to toggle source
# File lib/rspec_api_documentation/dsl/resource.rb, line 133 def parameter_keys parameters.map { |param| param[:name] } end
parameters()
click to toggle source
# File lib/rspec_api_documentation/dsl/resource.rb, line 113 def parameters safe_metadata(:parameters, []) end
response_fields()
click to toggle source
# File lib/rspec_api_documentation/dsl/resource.rb, line 121 def response_fields safe_metadata(:response_fields, []) end
safe_metadata(field, default)
click to toggle source
# File lib/rspec_api_documentation/dsl/resource.rb, line 105 def safe_metadata(field, default) metadata[field] ||= default if superclass_metadata && metadata[field].equal?(superclass_metadata[field]) metadata[field] = Marshal.load(Marshal.dump(superclass_metadata[field])) end metadata[field] end