Class: RoadForest::Application::RouteBinding

Inherits:
Object
  • Object
show all
Defined in:
lib/roadforest/application/route-adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(router) ⇒ RouteBinding

Returns a new instance of RouteBinding.



154
155
156
# File 'lib/roadforest/application/route-adapter.rb', line 154

def initialize(router)
  @router = router
end

Instance Attribute Details

#bindingsObject

Returns the value of attribute bindings.



158
159
160
# File 'lib/roadforest/application/route-adapter.rb', line 158

def bindings
  @bindings
end

#content_engineObject

Returns the value of attribute content_engine.



159
160
161
# File 'lib/roadforest/application/route-adapter.rb', line 159

def content_engine
  @content_engine
end

#guardObject

Returns the value of attribute guard.



158
159
160
# File 'lib/roadforest/application/route-adapter.rb', line 158

def guard
  @guard
end

#interface_builderObject

Returns the value of attribute interface_builder.



159
160
161
# File 'lib/roadforest/application/route-adapter.rb', line 159

def interface_builder
  @interface_builder
end

#interface_classObject

Returns the value of attribute interface_class.



159
160
161
# File 'lib/roadforest/application/route-adapter.rb', line 159

def interface_class
  @interface_class
end

#path_specObject

Returns the value of attribute path_spec.



158
159
160
# File 'lib/roadforest/application/route-adapter.rb', line 158

def path_spec
  @path_spec
end

#resource_typeObject

Returns the value of attribute resource_type.



159
160
161
# File 'lib/roadforest/application/route-adapter.rb', line 159

def resource_type
  @resource_type
end

#route_nameObject

Returns the value of attribute route_name.



158
159
160
# File 'lib/roadforest/application/route-adapter.rb', line 158

def route_name
  @route_name
end

#servicesObject

Returns the value of attribute services.



159
160
161
# File 'lib/roadforest/application/route-adapter.rb', line 159

def services
  @services
end

#traceObject

Returns the value of attribute trace.



159
160
161
# File 'lib/roadforest/application/route-adapter.rb', line 159

def trace
  @trace
end

Instance Method Details

#build_interface(&block) ⇒ Object



175
176
177
# File 'lib/roadforest/application/route-adapter.rb', line 175

def build_interface(&block)
  @interface_builder = block
end

#build_resource(&block) ⇒ Object



167
168
169
# File 'lib/roadforest/application/route-adapter.rb', line 167

def build_resource(&block)
  @resource_builder = block
end

#resource_adapterObject



193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/roadforest/application/route-adapter.rb', line 193

def resource_adapter
  @resource_adapter ||=
    begin
      ResourceAdapter.new.tap do |adapter|
        adapter.router = @router
        adapter.route_name = route_name
        adapter.interface_builder = interface_builder
        adapter.resource_builder = resource_builder
        adapter.content_engine = content_engine
        adapter.trace = trace
      end
    end
end

#resource_builderObject



161
162
163
164
165
# File 'lib/roadforest/application/route-adapter.rb', line 161

def resource_builder
  @resource_builder ||= proc do |request, response|
    Resource.get(resource_type).new(request, response)
  end
end

#routeObject



179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/roadforest/application/route-adapter.rb', line 179

def route
  @route ||=
    begin
      route =
        if guard.nil?
          Route.new(path_spec, resource_adapter, bindings || {})
        else
          Route.new(path_spec, resource_adapter, bindings || {}, &guard)
        end
      route.name = route_name
      route
    end
end

#validate!Object



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/roadforest/application/route-adapter.rb', line 207

def validate!
  problems = []

  if @path_spec.nil?
    problems << "Path specification is nil - no way to route URLs here."
  end

  if @resource_builder.nil? && @resource_type.nil?
    problems << "No means provided to build a resource adapter: set resource_type or resource_builder"
  end

  if @interface_builder.nil? and @interface_class.nil?
    problems << "No means provided to build an application interface: set interface_class or interface_builder"
  end

  unless problems.empty?
    raise InvalidRouteDefinition, "Route invalid:\n  #{problems.join("  \n")}"
  end
  return true
end