Class: Trust::Controller::Resource::ParentInfo

Inherits:
Info
  • Object
show all
Defined in:
lib/trust/controller/resource.rb

Overview

Resource::ParentInfo

Resolves the parent resource in subject (see #Resource::ResourceInfo)

Instance Attribute Summary collapse

Attributes inherited from Info

#klass, #name, #params, #path

Instance Method Summary collapse

Constructor Details

#initialize(resources, params, request) ⇒ ParentInfo

Returns a new instance of ParentInfo.



387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/trust/controller/resource.rb', line 387

def initialize(resources, params, request)
  ptr = resources.detect do |r,as|
    @klass = classify(r)
    @as = as
    ([@klass] + @klass.descendants).detect do |c|
      @name = c.to_s.underscore.tr('/','_').to_sym
      unless @id = request.path_parameters["#{@name}_id".to_sym]
        # see if name space handling is necessary
        if c.to_s.include?('::')
          @name = c.to_s.demodulize.underscore.to_sym
          @id = request.path_parameters["#{@name}_id".to_sym]
        end
      end
      @id
    end
    @id
  end
  if ptr
    @object = @klass.find(@id)
  else
    @klass = @name = nil
  end
  @data = params[var_name(ptr)]
end

Instance Attribute Details

#asObject (readonly)

Returns the value of attribute as.



386
387
388
# File 'lib/trust/controller/resource.rb', line 386

def as
  @as
end

#objectObject (readonly)

Returns the value of attribute object.



386
387
388
# File 'lib/trust/controller/resource.rb', line 386

def object
  @object
end

Instance Method Details

#object?Boolean

Returns:

  • (Boolean)


412
413
414
# File 'lib/trust/controller/resource.rb', line 412

def object?
  !!@object
end

#real_classObject



416
417
418
# File 'lib/trust/controller/resource.rb', line 416

def real_class
  @object && @object.class
end