Class: Roda::Component::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/roda/component/instance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance, scope = false) ⇒ Instance

Returns a new instance of Instance.



6
7
8
9
# File 'lib/roda/component/instance.rb', line 6

def initialize instance, scope = false
  @instance = instance
  @scope    = scope
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



17
18
19
20
21
22
23
24
25
# File 'lib/roda/component/instance.rb', line 17

def method_missing method, *args, &block
  if instance.respond_to? method, true
    instance.send method, *args, &block
  elsif server && scope && scope.respond_to?(method, true)
    scope.send method, *args, &block
  else
    super
  end
end

Instance Attribute Details

#instanceObject

Returns the value of attribute instance.



4
5
6
# File 'lib/roda/component/instance.rb', line 4

def instance
  @instance
end

#scopeObject

Returns the value of attribute scope.



4
5
6
# File 'lib/roda/component/instance.rb', line 4

def scope
  @scope
end

Instance Method Details

#client?Boolean Also known as: client

Returns:

  • (Boolean)


32
33
34
# File 'lib/roda/component/instance.rb', line 32

def client?
  RUBY_ENGINE == 'opal'
end

#display(*args, &block) ⇒ Object

this is a hack because it seems like display is a ruby object method when doing method(:display) it gives #<Method: # Roda::Component::Instance(Kernel)#display>



13
14
15
# File 'lib/roda/component/instance.rb', line 13

def display *args, &block
  method_missing('display', *args, &block)
end

#server?Boolean Also known as: server

Returns:

  • (Boolean)


27
28
29
# File 'lib/roda/component/instance.rb', line 27

def server?
  RUBY_ENGINE == 'ruby'
end