Sha256: 426f1ae60f4ebd1b2dc8ee6d6bc5057905d1ced47ed07050eca4bd588a0ce6df

Contents?: true

Size: 831 Bytes

Versions: 10

Compression:

Stored size: 831 Bytes

Contents

module Unimatrix

  class DynamicResource < Resource

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

    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

  end
  
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
unimatrix-2.2.1 lib/unimatrix/dynamic_resource.rb
unimatrix-2.1.1 lib/unimatrix/dynamic_resource.rb
unimatrix-2.0.1 lib/unimatrix/dynamic_resource.rb
unimatrix-2.0.0 lib/unimatrix/dynamic_resource.rb
unimatrix-1.4.3 lib/unimatrix/dynamic_resource.rb
unimatrix-1.4.1 lib/unimatrix/dynamic_resource.rb
unimatrix-1.4.0 lib/unimatrix/dynamic_resource.rb
unimatrix-1.2.0 lib/unimatrix/dynamic_resource.rb
unimatrix-1.1.0 lib/unimatrix/dynamic_resource.rb
unimatrix-1.0.0 lib/unimatrix/dynamic_resource.rb