Module: RspecApiDocumentation::DSL::Resource::ClassMethods

Defined in:
lib/rspec_api_documentation/dsl/resource.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.define_action(method) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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 [:route_uri]
      options[:route] = [: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

Instance Method Details

#attribute(name, *args) ⇒ Object



61
62
63
# 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 = {}) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# 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) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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) ⇒ Object



92
93
94
# File 'lib/rspec_api_documentation/dsl/resource.rb', line 92

def explanation(text)
  (:resource_explanation, text)
end

#header(name, value) ⇒ Object



69
70
71
# File 'lib/rspec_api_documentation/dsl/resource.rb', line 69

def header(name, value)
  headers[name] = value
end

#parameter(name, *args) ⇒ Object



57
58
59
# 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) ⇒ Object



65
66
67
# 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) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# 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) ⇒ Object



88
89
90
# File 'lib/rspec_api_documentation/dsl/resource.rb', line 88

def route_description(text)
  (:route_description, text)
end

#route_summary(text) ⇒ Object



84
85
86
# File 'lib/rspec_api_documentation/dsl/resource.rb', line 84

def route_summary(text)
  (:route_summary, text)
end