Class: Synchronisable::DSL::Association
- 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
-
.valid_options ⇒ Object
Returns the value of attribute valid_options.
Instance Attribute Summary collapse
-
#force_sync ⇒ Object
readonly
Returns the value of attribute force_sync.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
Class Method Summary collapse
Instance Method Summary collapse
- #create(options) ⇒ Object
-
#initialize(synchronizer, kind, name) ⇒ Association
constructor
A new instance of Association.
- #model_name ⇒ Object
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_options ⇒ Object
Returns the value of attribute valid_options.
17 18 19 |
# File 'lib/synchronisable/dsl/association.rb', line 17 def @valid_options end |
Instance Attribute Details
#force_sync ⇒ Object (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 |
#key ⇒ Object (readonly)
Returns the value of attribute key.
26 27 28 |
# File 'lib/synchronisable/dsl/association.rb', line 26 def key @key end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
26 27 28 |
# File 'lib/synchronisable/dsl/association.rb', line 26 def kind @kind end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
26 27 28 |
# File 'lib/synchronisable/dsl/association.rb', line 26 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
26 27 28 |
# File 'lib/synchronisable/dsl/association.rb', line 26 def name @name end |
#required ⇒ Object (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, ) new(synchronizer, kind, name).create() 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() () @key = [:key] @required = [:required] @force_sync = [:force_sync] if [:class_name].present? @model = [:class_name].constantize end set_defaults @synchronizer.associations[@key] = self end |
#model_name ⇒ Object
50 51 52 |
# File 'lib/synchronisable/dsl/association.rb', line 50 def model_name @model.to_s.demodulize.underscore.to_sym end |