lib/granite/form/model/associations/base.rb in granite-form-0.5.0 vs lib/granite/form/model/associations/base.rb in granite-form-0.6.0
- old
+ new
@@ -2,10 +2,11 @@
module Form
module Model
module Associations
class Base
attr_accessor :owner, :reflection
+
delegate :macro, :collection?, to: :reflection
def initialize(owner, reflection)
@owner = owner
@reflection = reflection
@@ -31,10 +32,11 @@
@loaded = true
end
def target
return @target if loaded?
+
self.target = load_target
end
def reload
reset
@@ -64,13 +66,15 @@
reload
raise e
end
def inspect
- "#<#{reflection.macro.to_s.camelize} #{target.inspect.truncate(50, omission: collection? ? '...]' : '...')}>"
+ macro = reflection.macro.to_s.camelize
+ target_for_inspect = target.inspect.truncate(50, omission: collection? ? '...]' : '...')
+ "#<#{macro} #{target_for_inspect}>"
end
- private
+ private
def read_source
reflection.read_source owner
end