Class: Filemaker::Model::Relations::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/filemaker/model/relations/proxy.rb

Overview

A proxy is a class to send all unknown methods to it’s target. The target here will be the eventual associated model.

Direct Known Subclasses

BelongsTo, HasMany, HasPortal

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, name, options) ⇒ Proxy

Returns a new instance of Proxy.

Parameters:

  • owner (Filemaker::Layout)

    The instance of the model

  • name (String)

    The relationship name

  • options (Hash)

    Relationship options



17
18
19
20
21
22
# File 'lib/filemaker/model/relations/proxy.rb', line 17

def initialize(owner, name, options)
  @owner = owner
  @name = name
  @options = options
  @class_name = options.fetch(:class_name) { name.to_s.classify }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Rubocop will complain and ask to fallback on ‘super`, but we won’t be able to do that because the target may have method that throw exception



32
33
34
# File 'lib/filemaker/model/relations/proxy.rb', line 32

def method_missing(name, *args, &block)
  target.send(name, *args, &block)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



12
13
14
# File 'lib/filemaker/model/relations/proxy.rb', line 12

def options
  @options
end

#ownerObject

Returns the value of attribute owner.



12
13
14
# File 'lib/filemaker/model/relations/proxy.rb', line 12

def owner
  @owner
end

#targetObject

Returns the value of attribute target.



12
13
14
# File 'lib/filemaker/model/relations/proxy.rb', line 12

def target
  @target
end

Instance Method Details

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

Returns:

  • (Boolean)


36
37
38
# File 'lib/filemaker/model/relations/proxy.rb', line 36

def respond_to_missing?(method_name, include_private = false)
  super
end

#target_classObject



24
25
26
27
# File 'lib/filemaker/model/relations/proxy.rb', line 24

def target_class
  return @class_name if @class_name.is_a?(Class)
  @class_name.constantize
end