Class: Xencap::SessionProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/xencap/session_proxy.rb

Direct Known Subclasses

Vm

Defined Under Namespace

Classes: Vm

Instance Method Summary collapse

Constructor Details

#initialize(session, scope) ⇒ SessionProxy

Returns a new instance of SessionProxy.



2
3
4
5
6
7
8
9
10
# File 'lib/xencap/session_proxy.rb', line 2

def initialize(session, scope)
  @session = session

  if scope.length <= 3
    @scope = scope.upcase
  else
    @scope = scope
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



12
13
14
# File 'lib/xencap/session_proxy.rb', line 12

def method_missing(method, *args, &block)
  _request(method, *args)
end

Instance Method Details

#_request(method, *args) ⇒ Object



36
37
38
# File 'lib/xencap/session_proxy.rb', line 36

def _request(method, *args)
  @session.send(@scope).send(method, *args)
end

#clone(*args) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/xencap/session_proxy.rb', line 16

def clone(*args)
  if args.length > 0
    _request(:clone, *args)
  else
    super
  end
end

#find_all_records(options = {}) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/xencap/session_proxy.rb', line 24

def find_all_records(options = {})
  get_all_records.select do |ref, record|
    options.all? do |key, value|
      record[key.to_s] == value
    end
  end
end

#find_record(options = {}) ⇒ Object



32
33
34
# File 'lib/xencap/session_proxy.rb', line 32

def find_record(options = {})
  find_all_records(options).first
end