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, #error, #formats

Instance Method Details

#_apipie_concern_substObject



282
283
284
285
# File 'lib/apipie/dsl_definition.rb', line 282

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



287
288
289
290
291
# File 'lib/apipie/dsl_definition.rb', line 287

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` }


278
279
280
# File 'lib/apipie/dsl_definition.rb', line 278

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



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/apipie/dsl_definition.rb', line 294

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