Module: Apipie::DSL::Controller
Instance Attribute Summary
Attributes included from Base
#api_params, #apipie_resource_descriptions
Instance Method Summary collapse
- #_apipie_concern_subst ⇒ Object
- #_apipie_perform_concern_subst(string) ⇒ Object
- #apipie_concern? ⇒ Boolean
-
#apipie_concern_subst(subst_hash) ⇒ Object
defines the substitutions to be made in the API paths deifned in concerns included.
-
#method_added(method_name) ⇒ Object
create method api and redefine newly added method.
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, #meta
Instance Method Details
#_apipie_concern_subst ⇒ Object
320 321 322 323 |
# File 'lib/apipie/dsl_definition.rb', line 320 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
325 326 327 328 329 |
# File 'lib/apipie/dsl_definition.rb', line 325 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
331 332 333 |
# File 'lib/apipie/dsl_definition.rb', line 331 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` }
316 317 318 |
# File 'lib/apipie/dsl_definition.rb', line 316 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
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/apipie/dsl_definition.rb', line 336 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 |