Module: Apipie::DSL::Controller

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

Instance Attribute Summary

Attributes included from Base

#api_params, #apipie_resource_descriptions

Instance Method Summary collapse

Methods included from Param

#_default_param_group_scope, #param, #param_group

Methods included from Action

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

Methods included from Common

#_apipie_define_validators, #_apipie_get_method_params, #_apipie_save_method_params, #api_versions, #desc, #document, #error, #formats, #header, #meta

Instance Method Details

#_apipie_concern_substObject



376
377
378
379
# File 'lib/apipie/dsl_definition.rb', line 376

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



381
382
383
384
385
# File 'lib/apipie/dsl_definition.rb', line 381

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

#apipie_concern?Boolean

Returns:

  • (Boolean)


387
388
389
# File 'lib/apipie/dsl_definition.rb', line 387

def apipie_concern?
  false
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` }


372
373
374
# File 'lib/apipie/dsl_definition.rb', line 372

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



392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/apipie/dsl_definition.rb', line 392

def method_added(method_name) #:doc:
  super
  return if !Apipie.active_dsl? || !_apipie_dsl_data[:api]

  return if _apipie_dsl_data[:api_args].blank? && _apipie_dsl_data[:api_from_routes].blank?

  # 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)

  _apipie_dsl_data_clear
  _apipie_define_validators(description)
ensure
  _apipie_dsl_data_clear
end