Class: Unimatrix::DynamicResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/unimatrix/dynamic_resource.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

build, field, find_by_type_name, has_many, has_one, inherited, type_name

Constructor Details

#initialize(attributes = {}, associations = {}) {|_self| ... } ⇒ DynamicResource

Returns a new instance of DynamicResource.

Yields:

  • (_self)

Yield Parameters:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/unimatrix/dynamic_resource.rb', line 19

def initialize( attributes = {}, associations = {} )

  unsupported_attributes_names = []
  attributes.each do | key, value |
    unsupported_attributes_names << key.to_sym \
      unless self.respond_to?( key.to_sym )
  end

  self.class_eval do
    unsupported_attributes_names.each do | name |
      field name
    end
  end

  super( attributes, associations )
  yield self if block_given?

end

Class Method Details

.new(attributes = {}, associations = {}) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/unimatrix/dynamic_resource.rb', line 9

def new( attributes = {}, associations = {} )
  Class.new( self ).old_new(
    { type_name: self.name.split( '::' ).last.underscore }.
      merge( attributes ),
    associations
  )
end

.old_newObject



7
# File 'lib/unimatrix/dynamic_resource.rb', line 7

alias old_new new