Class: TheBigDB::StatementRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/thebigdb/resources/statement.rb

Overview

Beautified builder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action) ⇒ StatementRequest

Returns a new instance of StatementRequest.



16
17
18
19
20
# File 'lib/thebigdb/resources/statement.rb', line 16

def initialize(action)
  @action = action
  @params = {}
  @response = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



28
29
30
31
# File 'lib/thebigdb/resources/statement.rb', line 28

def method_missing(method_name, *arguments, &block)
  @response ||= TheBigDB::Statement(@action, @params).response
  @response.send(method_name, *arguments, &block)
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



14
15
16
# File 'lib/thebigdb/resources/statement.rb', line 14

def action
  @action
end

#paramsObject (readonly)

Returns the value of attribute params.



14
15
16
# File 'lib/thebigdb/resources/statement.rb', line 14

def params
  @params
end

Instance Method Details

#inspectObject



45
46
47
# File 'lib/thebigdb/resources/statement.rb', line 45

def inspect
  load.inspect
end

#loadObject Also known as: response, execute



33
34
35
# File 'lib/thebigdb/resources/statement.rb', line 33

def load
  to_hash # goes through method_missing
end

#load!Object Also known as: execute!

forces the request to be re-loadd



39
40
41
42
# File 'lib/thebigdb/resources/statement.rb', line 39

def load! # forces the request to be re-loadd
  @response = nil
  to_hash
end

#with(params = {}) ⇒ Object



22
23
24
25
26
# File 'lib/thebigdb/resources/statement.rb', line 22

def with(params = {})
  @response = nil
  @params.merge!(TheBigDB::Helpers::stringify_keys(params))
  self
end