lib/zertico/delegator.rb in zertico-1.3.0 vs lib/zertico/delegator.rb in zertico-2.0.0.alpha.1

- old
+ new

@@ -1,28 +1,35 @@ require 'delegate' module Zertico class Delegator < SimpleDelegator + def initialize(object = nil) + object ||= interface_class.new + super(object) + end + def self.find(id) new(interface_class.find(id)) end def interface __getobj__ end + def interface=(object) + __setobj__(object) + end + protected def self.interface_name self.interface_class.name.split('::').last.singularize.underscore end def self.interface_class - begin - self.name.chomp('Delegator').constantize - rescue NameError - self.name.chomp('Delegator').split('::').last.constantize - end + self.name.chomp('Delegator').constantize + rescue NameError + self.name.chomp('Delegator').split('::').last.constantize end def interface_name self.class.interface_name end \ No newline at end of file