module Schema::Associations::HasOne::ClassMethods
no-doc
Public Instance Methods
has_one(name, options = {}, &block)
click to toggle source
rubocop:disable Naming/PredicateName
# File lib/schema/associations/has_one.rb, line 14 def has_one(name, options = {}, &block) options = ::Schema::Utils.add_association_class(self, name, :has_one, options) class_eval( <<-STR, __FILE__, __LINE__ + 1 def #{options[:getter]} #{options[:instance_variable]} end def #{name}_schema_creator @#{name}_schema_creator ||= ::Schema::Associations::SchemaCreator.new(self, #{name.inspect}) end def #{options[:setter]}(v) #{options[:instance_variable]} = #{name}_schema_creator.create_schema(self, v) end STR ) kls = const_get(options[:class_name]) kls.class_eval(&block) if block if options[:default] options[:default_code] = options[:class_name] + '.new' ::Schema::Utils.add_association_default_methods(self, options) end add_aliases(name, options) kls end