Class: Moonrope::ActionResult

Inherits:
Object
  • Object
show all
Defined in:
lib/moonrope/action_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action) ⇒ ActionResult

Initialize a new result from a Moonrope::Action.

Parameters:



9
10
11
12
13
14
# File 'lib/moonrope/action_result.rb', line 9

def initialize(action)
  @action = action
  @headers = {}
  @time = nil
  @flags = {}
end

Instance Attribute Details

#dataObject

Returns the return value from the action.

Returns:

  • (Object)

    the return value from the action



17
18
19
# File 'lib/moonrope/action_result.rb', line 17

def data
  @data
end

#flagsHash

Returns flags which have been set in the action.

Returns:

  • (Hash)

    flags which have been set in the action



29
30
31
# File 'lib/moonrope/action_result.rb', line 29

def flags
  @flags
end

#headersHash

Returns headers which have been set in the action.

Returns:

  • (Hash)

    headers which have been set in the action



23
24
25
# File 'lib/moonrope/action_result.rb', line 23

def headers
  @headers
end

#statusString

Returns the status of the request.

Returns:

  • (String)

    the status of the request



20
21
22
# File 'lib/moonrope/action_result.rb', line 20

def status
  @status
end

#timeFloat

Returns the length of time to process the action.

Returns:

  • (Float)

    the length of time to process the action



26
27
28
# File 'lib/moonrope/action_result.rb', line 26

def time
  @time
end

Instance Method Details

#to_hashHash

Return a Hash representation of this ActionResult without the headers.

{
  :status => 'success',
  :time => 1.32,
  :flags => {},
  :data => {}
}

Returns:

  • (Hash)


44
45
46
47
48
49
50
51
# File 'lib/moonrope/action_result.rb', line 44

def to_hash
  {
    :status => self.status,
    :time => self.time,
    :flags => self.flags,
    :data => self.data
  }
end

#to_jsonString

Return the ActionResult’s hash with a JSON.

Returns:

  • (String)


58
59
60
# File 'lib/moonrope/action_result.rb', line 58

def to_json
  to_hash.to_json
end