Module: Icss::Meta::RecordModel

Included in:
NamedSchema, RecordField, RecordSchema, ReceiverModel
Defined in:
lib/icss/serialization.rb,
lib/icss/type/record_model.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
# File 'lib/icss/type/record_model.rb', line 5

def self.included(base)
  base.extend(Icss::Meta::RecordType)
  base.metamodel
end

Instance Method Details

#attr_set?(attr) ⇒ Boolean

true if the attr is a receiver variable and it has been set

Returns:



26
27
28
# File 'lib/icss/type/record_model.rb', line 26

def attr_set?(attr)
  self.class.has_field?(attr) && self.instance_variable_defined?("@#{attr}")
end

#receive!(hsh = {}) ⇒ Object

modify object in place with new typecast values.

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/icss/type/record_model.rb', line 13

def receive!(hsh={})
  raise ArgumentError, "Can't receive (it isn't hashlike): {#{hsh.inspect}}" unless hsh.respond_to?(:[]) && hsh.respond_to?(:has_key?)
  self.class.send(:_rcvr_methods).each do |attr, meth|
    if    hsh.has_key?(attr)      then val = hsh[attr]
    elsif hsh.has_key?(attr.to_s) then val = hsh[attr.to_s]
    else next ; end
    self.send(meth, val)
  end
  run_after_receivers(hsh)
  self
end

#to_zaml(z = ZAML.new) ⇒ Object



5
6
7
8
9
# File 'lib/icss/serialization.rb', line 5

def to_zaml(z=ZAML.new)
  hsh = self.to_wire
  hsh.to_zaml(z)
  z.to_s
end