Class: Pakyow::Presenter::Presenters::Endpoint

Inherits:
Pakyow::Presenter::Presenter show all
Defined in:
lib/pakyow/presenter/presenters/endpoint.rb

Instance Attribute Summary

Attributes inherited from Pakyow::Presenter::Presenter

#app, #logger, #presentables, #view

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pakyow::Presenter::Presenter

#==, #after, #append, attach, #before, #bind, #clear, #component, #components, #endpoint, #endpoint_action, #find, #find_all, #form, #forms, #initialize, make, options_for, #prepend, #present, present, #presenter_for, #remove, render, #replace, #title, #title=, #to_html, #to_s, #transform, #use, #use_implicit_version, version, #versioned, #with, #wrap_data_in_binder

Constructor Details

This class inherits a constructor from Pakyow::Presenter::Presenter

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object

Delegate private methods.



26
27
28
# File 'lib/pakyow/presenter/presenters/endpoint.rb', line 26

def method_missing(method_name, *args, &block)
  __getobj__.send(method_name, *args, &block)
end

Class Method Details

.attach_to_node(node, renders, binding_path: []) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Recursively attach to binding endpoints.



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/pakyow/presenter/presenters/endpoint.rb', line 125

def attach_to_node(node, renders, binding_path: [])
  node.each_significant_node(:binding) do |binding_node|
    next_binding_path = binding_path.dup
    if binding_node.significant?(:binding_within)
      next_binding_path << binding_node.label(:channeled_binding)
    end

    current_binding_path = binding_path.dup
    current_binding_path << binding_node.label(:channeled_binding)

    if binding_node.significant?(:endpoint)
      renders << {
        binding_path: current_binding_path,
        priority: :low,
        block: Proc.new {
          setup
        }
      }
    else
      binding_node.find_significant_nodes(:endpoint).each do |endpoint_node|
        renders << {
          binding_path: current_binding_path,
          priority: :low,
          block: Proc.new {
            endpoint_view = endpoint(endpoint_node.label(:endpoint))
            case endpoint_view
            when Presenters::Form
              Presenters::Endpoint.new(endpoint_view.__getobj__).setup
            when Presenters::Endpoint
              endpoint_view.setup
            end
          }
        }
      end
    end

    attach_to_node(binding_node, renders, binding_path: next_binding_path)
  end
end

Instance Method Details

#pp(*args) ⇒ Object

Fixes an issue using pp inside a delegator.



20
21
22
# File 'lib/pakyow/presenter/presenters/endpoint.rb', line 20

def pp(*args)
  Kernel.pp(*args)
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/pakyow/presenter/presenters/endpoint.rb', line 30

def respond_to_missing?(method_name, include_private = false)
  super || __getobj__.respond_to?(method_name, true)
end

#setupObject



10
11
12
13
14
15
16
# File 'lib/pakyow/presenter/presenters/endpoint.rb', line 10

def setup
  setup_endpoint(path: endpoint_path, method: endpoint_method)

  unless endpoint_method == :get
    setup_non_get_endpoint(path: endpoint_path, method: endpoint_method)
  end
end