lib/synchronisable/dsl/associations/association.rb in synchronisable-0.0.9 vs lib/synchronisable/dsl/associations/association.rb in synchronisable-1.0.0
- old
+ new
@@ -2,10 +2,11 @@
module Synchronisable
module DSL
module Associations
# Association builder.
+ # Subclasses must implement #macro method.
class Association
include Synchronisable::DSL::Macro
attribute :key_suffix, default: -> { raise NotImplementedError }
@@ -15,38 +16,40 @@
def create(synchronizer, name, options)
new(synchronizer, name).create(options)
end
end
- self.valid_options = %i(key class_name required type)
+ self.valid_options = %i(key class_name required)
- attr_reader :name, :model, :key, :required, :type
+ attr_reader :name, :model, :key, :required
def initialize(synchronizer, name)
@synchronizer, @name = synchronizer, name.to_sym
end
def create(options)
validate_options(options)
@key = options[:key]
@required = options[:required]
- @type = options[:type]
if options[:class_name].present?
@model = options[:class_name].constantize
end
set_defaults
@synchronizer.associations[@key] = self
end
+ def macro
+ raise NotImplementedError
+ end
+
protected
def set_defaults
@required ||= false
- @type ||= :ids
@model ||= @name.to_s.classify.constantize
@key = "#{@name}_#{self.class.key_suffix}" unless @key.present?
end