Module: Scalingo::Endpoint::ClassMethods

Included in:
Scalingo::Endpoint
Defined in:
lib/scalingo/endpoint.rb

Instance Method Summary collapse

Instance Method Details

#resources(name, opts = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/scalingo/endpoint.rb', line 10

def resources(name, opts = {})
  name = name.to_s

  endpoint_opts = { auth_api: opts[:auth_api] }

  define_method(name.pluralize.underscore) do
    Scalingo::Endpoint.const_get(
      name.pluralize.camelize,
    ).new(self, nil, endpoint_opts)
  end

  return if opts[:collection_only]

  define_method(name.singularize.underscore) do |id|
    send(name.pluralize.underscore).find(id)
  end
end