Class: Moon::DataModel::Metal

Inherits:
Object
  • Object
show all
Includes:
Fields, Serializable
Defined in:
lib/data_model/metal.rb

Overview

Metal is a generic implementation of Moon::DataModel::Model

Direct Known Subclasses

Base

Constant Summary collapse

@@dmid =

Returns Global DataModel id, incremented each time a Metal based model is created.

Returns:

  • (Integer)

    Global DataModel id, incremented each time a Metal based model is created.

0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Fields

adjust_field_options, included

Methods included from Fields::InstanceMethods

#[], #[]=, #assoc, #each_field, #each_field_name, #each_field_with_value, #each_pair, #each_value, #field_get, #field_set, #field_set!, #fields=, #fields_hash, #initialize_fields, #invalid?, #post_initialize_fields, #pre_initialize_fields, #reset_field, #reset_fields, #update_fields, #update_fields!, #valid?, #validate, #validate_fields?

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Metal

Parameters:

  • options (Hash<Symbol, Object>) (defaults to: {})

    Values to initialize the model with, each Key value pair should be a field name and value for the field to initialize with.

Yields:

  • (_self)

Yield Parameters:


25
26
27
28
29
30
31
# File 'lib/data_model/metal.rb', line 25

def initialize(options = {})
  @dmid = @@dmid += 1
  pre_initialize
  initialize_fields(options)
  yield self if block_given?
  post_initialize
end

Instance Attribute Details

#dmidObject (readonly)

Returns the value of attribute dmid


19
20
21
# File 'lib/data_model/metal.rb', line 19

def dmid
  @dmid
end

Instance Method Details

#post_initializevoid

This method returns an undefined value.

Final initialization method, use this as your own initialize method. Called after the fields have been initialized at the very end. if you need to change the model before it ever reaches the user use Fields::InstanceMethods#post_initialize_fields instead.


46
47
# File 'lib/data_model/metal.rb', line 46

def post_initialize
end

#pre_initializevoid

This method returns an undefined value.

Pre initialization method, use this as a way to setup the model before its fields are initialized.


37
38
# File 'lib/data_model/metal.rb', line 37

def pre_initialize
end

#to_hHash<Symbol, Object>

Converts the Model to a Hash, all fields will be converted to Hashes via #to_h

Returns:

  • (Hash<Symbol, Object>)

53
54
55
# File 'lib/data_model/metal.rb', line 53

def to_h
  FieldsToHash.call(self)
end