Class: Synchronisable::DSL::Association

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

Overview

Association builder. Subclasses must implement #macro method.

Constant Summary collapse

KIND_KEY_SUFFIX_MAP =
{
  :belongs_to => :id,
  :has_one => :id,
  :has_many => :ids
}

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(synchronizer, kind, name) ⇒ Association

Returns a new instance of Association.


29
30
31
32
# File 'lib/synchronisable/dsl/association.rb', line 29

def initialize(synchronizer, kind, name)
  @synchronizer, @kind, @name = synchronizer, kind, name.to_sym
  @key_suffix = KIND_KEY_SUFFIX_MAP[kind]
end

Class Attribute Details

.valid_optionsObject

Returns the value of attribute valid_options


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

def valid_options
  @valid_options
end

Instance Attribute Details

#force_syncObject (readonly)

Returns the value of attribute force_sync


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

def force_sync
  @force_sync
end

#keyObject (readonly)

Returns the value of attribute key


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

def key
  @key
end

#kindObject (readonly)

Returns the value of attribute kind


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

def kind
  @kind
end

#modelObject (readonly)

Returns the value of attribute model


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

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name


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

def name
  @name
end

#requiredObject (readonly)

Returns the value of attribute required


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

def required
  @required
end

Class Method Details

.create(synchronizer, kind, name, options) ⇒ Object


19
20
21
# File 'lib/synchronisable/dsl/association.rb', line 19

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

Instance Method Details

#create(options) ⇒ Object


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/synchronisable/dsl/association.rb', line 34

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

#model_nameObject


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

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