Module: Sequencescape::Api::Associations::BelongsTo::CommonBehaviour

Included in:
AssociationProxy, InlineAssociationProxy
Defined in:
lib/sequencescape-api/associations/belongs_to.rb

Defined Under Namespace

Classes: LoadHandler

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



27
28
29
30
# File 'lib/sequencescape-api/associations/belongs_to.rb', line 27

def method_missing(name, *args, &block)
  target = is_handled_by_object_instance?(name) ? @object : object
  target.send(name, *args, &block)
end

Class Method Details

.included(base) ⇒ Object



6
7
8
9
10
# File 'lib/sequencescape-api/associations/belongs_to.rb', line 6

def self.included(base)
  base.class_eval do
    include Sequencescape::Api::ErrorHandling
  end
end

Instance Method Details

#as_json(options = nil) ⇒ Object



73
74
75
# File 'lib/sequencescape-api/associations/belongs_to.rb', line 73

def as_json(options = nil)
  @object.as_json({ root: false, uuid: false }.reverse_merge(options || {}))
end

#initialize(*args, &block) ⇒ Object



12
13
14
15
# File 'lib/sequencescape-api/associations/belongs_to.rb', line 12

def initialize(*args, &block)
  super
  @object = new(@_attributes_, false)
end

#respond_to?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/sequencescape-api/associations/belongs_to.rb', line 22

def respond_to?(name, include_private = false)
  # One of our methods, or an eager loaded attribute, or the object needs to be loaded & checked
  super or is_handled_by_object_instance?(name) or object.respond_to?(name, include_private)
end