Module: Apipie::DSL::Controller

Includes:
Action, Base, Common, Param
Defined in:
lib/apipie/dsl_definition.rb

Instance Attribute Summary

Attributes included from Base

#apipie_resource_descriptions

Instance Method Summary collapse

Methods included from Param

#_default_param_group_scope, #param, #param_group

Methods included from Action

#api, #def_param_group, #example, #resource_description, #see

Methods included from Common

#_apipie_define_validators, #api_versions, #desc, #document, #error, #formats

Instance Method Details

#_apipie_concern_substObject



295
296
297
298
# File 'lib/apipie/dsl_definition.rb', line 295

def _apipie_concern_subst
  @_apipie_concern_subst ||= {:controller_path => self.controller_path,
                              :resource_id => Apipie.get_resource_name(self)}
end

#_apipie_perform_concern_subst(string) ⇒ Object



300
301
302
303
304
# File 'lib/apipie/dsl_definition.rb', line 300

def _apipie_perform_concern_subst(string)
  return _apipie_concern_subst.reduce(string) do |ret, (key, val)|
    ret.gsub(":#{key}", val)
  end
end

#apipie_concern_subst(subst_hash) ⇒ Object

defines the substitutions to be made in the API paths deifned in concerns included. For example:

There is this method defined in concern:

api GET ':controller_path/:id'
def show
  # ...
end

If you include the concern into some controller, you can specify the value for :controller_path like this:

apipie_concern_subst(:controller_path => '/users')
include ::Concerns::SampleController

The resulting path will be ‘/users/:id’.

It has to be specified before the concern is included.

If not specified, the default predefined substitions are

{:conroller_path => controller.controller_path,
 :resource_id  => `resource_id_from_apipie` }


291
292
293
# File 'lib/apipie/dsl_definition.rb', line 291

def apipie_concern_subst(subst_hash)
  _apipie_concern_subst.merge!(subst_hash)
end

#method_added(method_name) ⇒ Object

create method api and redefine newly added method



307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/apipie/dsl_definition.rb', line 307

def method_added(method_name) #:doc:
  super

  if ! Apipie.active_dsl? || _apipie_dsl_data[:api_args].blank?
    _apipie_dsl_data_clear
    return
  end

  begin
    # remove method description if exists and create new one
    Apipie.remove_method_description(self, _apipie_dsl_data[:api_versions], method_name)
    description = Apipie.define_method_description(self, method_name, _apipie_dsl_data)
  ensure
    _apipie_dsl_data_clear
  end

  _apipie_define_validators(description)
end