Module: HaveAPI::Spec::ApiBuilder
- Defined in:
- lib/haveapi/spec/api_builder.rb
Overview
Contains methods for specification of API to be used in ‘description` block.
Instance Method Summary collapse
-
#api(mod = nil) { ... } ⇒ Object
Set an API module or create the API using DSL.
-
#auth_chain(chain) ⇒ Object
Set authentication chain.
-
#default_version(v) ⇒ Object
Set default API version.
-
#empty_api ⇒ Object
Uses an empty module as the source for the API.
-
#login(*credentials) ⇒ Object
Login using HTTP basic.
-
#mount_to(path) ⇒ Object
Set a custom mount path.
- #opt(name, v) ⇒ Object
- #opts ⇒ Object
-
#use_version(v) ⇒ Object
Select API versions to be used.
Instance Method Details
#api(mod = nil) { ... } ⇒ Object
Set an API module or create the API using DSL.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/haveapi/spec/api_builder.rb', line 14 def api(mod = nil, &block) unless mod mod = Module.new do def self.define_resource(name, superclass: Resource, &block) return false if const_defined?(name) cls = Class.new(superclass) const_set(name, cls) cls.class_exec(&block) if block cls end module_eval(&block) end const_set(:ApiModule, mod) end opt(:api_module, mod) end |
#auth_chain(chain) ⇒ Object
Set authentication chain.
36 37 38 |
# File 'lib/haveapi/spec/api_builder.rb', line 36 def auth_chain(chain) opt(:auth_chain, chain) end |
#default_version(v) ⇒ Object
Set default API version.
48 49 50 |
# File 'lib/haveapi/spec/api_builder.rb', line 48 def default_version(v) opt(:default_version, v) end |
#empty_api ⇒ Object
Uses an empty module as the source for the API. It will have no resources, no actions. Version default to ‘1`.
6 7 8 9 |
# File 'lib/haveapi/spec/api_builder.rb', line 6 def empty_api api(Module.new) default_version(1) end |
#login(*credentials) ⇒ Object
Login using HTTP basic.
58 59 60 61 62 |
# File 'lib/haveapi/spec/api_builder.rb', line 58 def login(*credentials) before(:each) do (*credentials) end end |
#mount_to(path) ⇒ Object
Set a custom mount path.
53 54 55 |
# File 'lib/haveapi/spec/api_builder.rb', line 53 def mount_to(path) opt(:mount, path) end |
#opt(name, v) ⇒ Object
70 71 72 73 |
# File 'lib/haveapi/spec/api_builder.rb', line 70 def opt(name, v) @opts ||= {} @opts[name] = v end |
#opts ⇒ Object
65 66 67 |
# File 'lib/haveapi/spec/api_builder.rb', line 65 def opts @opts end |
#use_version(v) ⇒ Object
Select API versions to be used.
41 42 43 44 45 |
# File 'lib/haveapi/spec/api_builder.rb', line 41 def use_version(v) before(:each) do self.class.opt(:versions, v) end end |