Class: Rapid::Server::Inspector

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ury_rapid/server/inspector.rb

Overview

An instance of the API Inspector

The API Inspector is Rapid's HTML output. It allows the API space to be navigated and interacted with in a basic way.

Because the API inspector needs more information about the model than its flat representation, the Inspector object is used to hold the extra state.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, target, privilege_set, inner = false) ⇒ Inspector

Initialises an instance of the API Inspector

Parameters:

  • request (Request)

    The HTTP request that spawned this Inspector.

  • target (ModelObject)

    The object to inspect.

  • privilege_set (PrivilegeSet)

    The set of privileges that the inspector instance may use.

  • inner (Boolean) (defaults to: false)

    If true, this inspector is being used inside another inspector.


24
25
26
27
28
29
30
# File 'lib/ury_rapid/server/inspector.rb', line 24

def initialize(request, target, privilege_set, inner = false)
  @request = request
  @target = target
  @resource = target.get(privilege_set)
  @inner = inner
  @privilege_set = privilege_set
end

Instance Attribute Details

#innerObject (readonly)

Returns the value of attribute inner


14
15
16
# File 'lib/ury_rapid/server/inspector.rb', line 14

def inner
  @inner
end

#resourceObject (readonly)

Returns the value of attribute resource


36
37
38
# File 'lib/ury_rapid/server/inspector.rb', line 36

def resource
  @resource
end

Instance Method Details

#inspect_child(id) ⇒ Object

Creates a new Inspector inspecting one of target's children


52
53
54
# File 'lib/ury_rapid/server/inspector.rb', line 52

def inspect_child(id)
  Inspector.new(@request, @target.get_child(id), @privilege_set, true)
end

#resource_general_typeObject


43
44
45
# File 'lib/ury_rapid/server/inspector.rb', line 43

def resource_general_type
  @target.class.name.demodulize.underscore.intern
end

#resource_typeObject

Retrieves the type of the target


39
40
41
# File 'lib/ury_rapid/server/inspector.rb', line 39

def resource_type
  json? ? :json : @target.handler_target
end

#titleObject


32
33
34
# File 'lib/ury_rapid/server/inspector.rb', line 32

def title
  @inner ? resource_id : resource_url
end