Module: RspecApiDocumentation::DSL::Resource::ClassMethods
- Defined in:
- lib/rspec_api_documentation/dsl/resource.rb
Class Method Summary collapse
Instance Method Summary collapse
- #attribute(name, *args) ⇒ Object
- #authentication(type, value, opts = {}) ⇒ Object
- #callback(*args, &block) ⇒ Object
- #explanation(text) ⇒ Object
- #header(name, value) ⇒ Object
- #parameter(name, *args) ⇒ Object
- #response_field(name, *args) ⇒ Object
- #route(*args, &block) ⇒ Object
- #route_description(text) ⇒ Object
- #route_summary(text) ⇒ Object
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| = args. [:method] = method if [:route_uri] [:route] = [:route_uri] [:action_name] = args.first else [:route] = args.first end [:api_doc_dsl] = :endpoint args.push() 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) = if args.last.is_a?(Hash) then args.pop else {} end [:api_doc_dsl] = :callback args.push() 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? = args. [:route_uri] = args[0].gsub(/\{.*\}/, "") [:route_optionals] = (optionals = args[0].match(/(\{.*\})/) and optionals[-1]) [:route_name] = args[1] args.push() 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 |