Module: ApipieDSL::Extension
- Includes:
- Delegatable
- Defined in:
- lib/apipie_dsl/dsl.rb
Instance Method Summary collapse
- #apipie(context = :method, desc_or_options = nil, options = {}, &block) ⇒ Object
- #apipie_update(context = :method, &block) ⇒ Object
- #method_added(method_name) ⇒ Object
- #prepended(klass) ⇒ Object
Instance Method Details
#apipie(context = :method, desc_or_options = nil, options = {}, &block) ⇒ Object
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
# File 'lib/apipie_dsl/dsl.rb', line 533 def apipie(context = :method, = nil, = {}, &block) case when Hash = .merge() when String [:desc] = end [:name] ||= context.to_s block = proc {} unless block_given? delegatee = Delegatee.instance_for(self).with(&block) delegatee.short([:desc]) # Don't eval the block, since it will be evaluated after method is defined return if context == :method # Currently method extensions are supported only Delegatee.instance_reset end |
#apipie_update(context = :method, &block) ⇒ Object
553 554 555 556 557 558 559 560 561 562 563 564 |
# File 'lib/apipie_dsl/dsl.rb', line 553 def apipie_update(context = :method, &block) block = proc {} unless block_given? delegatee = Delegatee.instance_for(self).with(&block) delegatee.dsl_data[:update_only] = true return if context == :method # Save instance to reuse when actual scope is set Delegatee.extension_data[:class] = delegatee Delegatee.instance_reset end |
#method_added(method_name) ⇒ Object
594 595 596 597 598 599 600 601 602 603 |
# File 'lib/apipie_dsl/dsl.rb', line 594 def method_added(method_name) super # Methods autoload is not supported for extension modules return if Delegatee.instance.nil? dsl_data = Delegatee.instance.eval_dsl_for(:method) Delegatee.extension_data[:methods] << [method_name, dsl_data] ensure Delegatee.instance_reset end |
#prepended(klass) ⇒ Object
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 |
# File 'lib/apipie_dsl/dsl.rb', line 566 def prepended(klass) super Delegatee.extension_data[:class]&.class_scope = klass Delegatee.extension_data[:class]&.eval_dsl_for(:class) Delegatee.extension_data[:methods].each do |method_name, dsl_data| class_scope = klass if dsl_data[:update_only] class_name = ApipieDSL.get_class_name(class_scope) # Update the old method description method_desc = ApipieDSL.get_method_description(class_name, method_name) unless method_desc raise StandardError, "Could not find method description for #{class_name}##{method_name}. Was the method defined?" end Delegatee.update_method_desc(method_desc, dsl_data) # Define validators for the new method class_scope = self else ApipieDSL.remove_method_description(class_scope, dsl_data[:dsl_versions], method_name) method_desc = ApipieDSL.define_method_description(class_scope, method_name, dsl_data) end Delegatee.instance_reset Delegatee.define_validators(class_scope, method_desc) end ensure Delegatee.instance_reset end |