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

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

Overview

Association builder. Subclasses must implement #macro method.

Direct Known Subclasses

BelongsTo, 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.



26
27
28
# File 'lib/synchronisable/dsl/associations/association.rb', line 26

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

Class Attribute Details

.valid_optionsObject

Returns the value of attribute valid_options.



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

def valid_options
  @valid_options
end

Instance Attribute Details

#force_syncObject (readonly)

Returns the value of attribute force_sync.



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

def force_sync
  @force_sync
end

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

#modelObject (readonly)

Returns the value of attribute model.



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

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#requiredObject (readonly)

Returns the value of attribute required.



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

def required
  @required
end

Class Method Details

.create(synchronizer, name, options) ⇒ Object



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

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

Instance Method Details

#create(options) ⇒ Object



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

def create(options)
  validate_options(options)

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

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

  set_defaults

  @synchronizer.associations[@key] = self
end

#macroObject

Raises:

  • (NotImplementedError)


46
47
48
# File 'lib/synchronisable/dsl/associations/association.rb', line 46

def macro
  raise NotImplementedError
end

#model_nameObject



50
51
52
# File 'lib/synchronisable/dsl/associations/association.rb', line 50

def model_name
  @model.to_s.demodulize.underscore.to_sym
end