Class: Jenkins2::ResourceProxy

Inherits:
BasicObject
Defined in:
lib/jenkins2/resource_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, path, params = {}, &block) ⇒ ResourceProxy

Returns a new instance of ResourceProxy.



11
12
13
14
15
16
# File 'lib/jenkins2/resource_proxy.rb', line 11

def initialize(connection, path, params={}, &block)
  @path = path
  @id = nil
  @connection, @params = connection, params
  subject if block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



18
19
20
21
22
23
24
25
# File 'lib/jenkins2/resource_proxy.rb', line 18

def method_missing(message, *args, &block)
  if respond_to_missing? message
    ::Jenkins2::Log.debug message
    subject.send(message, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



9
10
11
# File 'lib/jenkins2/resource_proxy.rb', line 9

def connection
  @connection
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/jenkins2/resource_proxy.rb', line 9

def path
  @path
end

Instance Method Details

#rawObject



31
32
33
# File 'lib/jenkins2/resource_proxy.rb', line 31

def raw
  @raw ||= connection.get_json(build_path, @params)
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/jenkins2/resource_proxy.rb', line 27

def respond_to_missing?(method_name, include_private=false)
  subject.respond_to? method_name, include_private
end

#subjectObject



35
36
37
# File 'lib/jenkins2/resource_proxy.rb', line 35

def subject
  @subject ||= ::JSON.parse(raw.body, object_class: ::OpenStruct)
end