Class: RemoteResource::AssociationBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/remote_resource/association_builder.rb

Overview

The AssociationBuilder class is responsible for defining a method(s) on a target object that refers to an associated Base class. The body of that method instantiates an attributes class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_class, options = {}) ⇒ AssociationBuilder

Returns a new instance of AssociationBuilder.



8
9
10
11
# File 'lib/remote_resource/association_builder.rb', line 8

def initialize(base_class, options = {})
  @base_class = base_class
  @options = ensure_options(options)
end

Instance Attribute Details

#base_classObject (readonly)

Returns the value of attribute base_class.



6
7
8
# File 'lib/remote_resource/association_builder.rb', line 6

def base_class
  @base_class
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/remote_resource/association_builder.rb', line 6

def options
  @options
end

Instance Method Details

#associated_with(target_class) ⇒ Object



13
14
15
16
17
18
# File 'lib/remote_resource/association_builder.rb', line 13

def associated_with(target_class)
  method_name = @options[:as]
  set_associated_class(method_name, target_class)
  define_association_method(method_name, target_class)
  self
end