Class: Synchronisable::DSL::Associations::Association

Inherits:
Object
  • Object
show all
Includes:
Macro
Defined in:
lib/synchronisable/dsl/associations/association.rb

Overview

Association builder.

Direct Known Subclasses

HasMany, HasOne

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(synchronizer, name) ⇒ Association

Returns a new instance of Association.



24
25
26
# File 'lib/synchronisable/dsl/associations/association.rb', line 24

def initialize(synchronizer, name)
  @synchronizer, @name = synchronizer, name.to_sym
end

Class Attribute Details

.valid_optionsObject

Returns the value of attribute valid_options.



13
14
15
# File 'lib/synchronisable/dsl/associations/association.rb', line 13

def valid_options
  @valid_options
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



22
23
24
# File 'lib/synchronisable/dsl/associations/association.rb', line 22

def key
  @key
end

#modelObject (readonly)

Returns the value of attribute model.



22
23
24
# File 'lib/synchronisable/dsl/associations/association.rb', line 22

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/synchronisable/dsl/associations/association.rb', line 22

def name
  @name
end

#requiredObject (readonly)

Returns the value of attribute required.



22
23
24
# File 'lib/synchronisable/dsl/associations/association.rb', line 22

def required
  @required
end

Class Method Details

.create(synchronizer, name, options) ⇒ Object



15
16
17
# File 'lib/synchronisable/dsl/associations/association.rb', line 15

def create(synchronizer, name, options)
  new(synchronizer, name).create(options)
end

Instance Method Details

#create(options) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/synchronisable/dsl/associations/association.rb', line 28

def create(options)
  validate_options(options)

  @key = options[:key]
  @required = options[:required]

  if options[:class_name].present?
    @model = options[:class_name].constantize
  end

  set_defaults

  @synchronizer.associations[@key] = self
end