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

Class Method 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



39
40
41
# File 'lib/filemaker/model/relations/proxy.rb', line 39

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

Class Method Details

.init(owner, name, options) ⇒ Object

Create will not return the proxy if target was NilClass



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

def self.init(owner, name, options)
  new_instance = new(owner, name, options)
  new_instance.target.nil? ? nil : new_instance
end

Instance Method Details

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

Returns:

  • (Boolean)


43
44
45
# File 'lib/filemaker/model/relations/proxy.rb', line 43

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

#target_classObject



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

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

  @class_name.constantize
end