Module: ClassX::AttributeMethods::InstanceMethods

Defined in:
lib/classx/attribute.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#getObject



175
176
177
# File 'lib/classx/attribute.rb', line 175

def get
  @data ||= self.class.default(@parent)
end

#initialize(val) ⇒ Object



170
171
172
173
# File 'lib/classx/attribute.rb', line 170

def initialize val
  @parent = val
  @data = nil
end

#inspectObject



191
192
193
# File 'lib/classx/attribute.rb', line 191

def inspect
  "<#ClassX::Attribute:#{object_id} #{ @data.nil? ? '@data=nil' : '@data=' + @data.inspect } @parent=#{@parent} config=#{self.class.config.inspect}>"
end

#set(val) ⇒ Object

XXX:

you should not call this method except for @parent instance's setter method.
It's because caching as instance_variable in @parent instance for performance.


182
183
184
185
186
187
188
189
# File 'lib/classx/attribute.rb', line 182

def set val
  val = self.class.coerce(val)
  raise ClassX::InvalidAttrArgument, "#{val.inspect} is not valid for #{self.inspect}" unless self.class.validate? val
  @data = val

  self.class.trigger(@parent, val)
  @data
end