module Deserializer::Attributable

Public Class Methods

attribute( name, opts = {} ) click to toggle source
# File lib/deserializer/attributable.rb, line 16
def attribute( name, opts = {} )
  attribute = Attribute::Attribute.new( Attribute::ValueAttribute, name, opts )
  self.__attrs = __attrs.merge attribute.key => attribute
end
attributes( *attrs ) click to toggle source

deserializer interface functions

# File lib/deserializer/attributable.rb, line 9
def attributes( *attrs )
  self.__attrs = __attrs.dup
  attrs.each do |attr|
    attribute( attr, {} )
  end
end
belongs_to( *args ) click to toggle source
# File lib/deserializer/attributable.rb, line 39
def belongs_to( *args )
  raise DeserializerError, class: self, message: "belongs_to is unsupported."
end
has_many( name, opts = {} ) click to toggle source
# File lib/deserializer/attributable.rb, line 30
def has_many( name, opts = {} )
  unless opts[:deserializer]
    raise DeserializerError, class: self, message: "has_many associations need a deserilaizer" 
  end

  attribute = Attribute::Attribute.new( Attribute::HasManyAssociation, name, opts )
  self.__attrs = __attrs.merge attribute.key => attribute
end
has_one( name, opts = {} ) click to toggle source
# File lib/deserializer/attributable.rb, line 21
def has_one( name, opts = {} )
  unless opts[:deserializer]
    raise DeserializerError, class: self, message: "has_one associations need a deserilaizer" 
  end
  
  attribute = Attribute::Attribute.new( Attribute::HasOneAssociation, name, opts )
  self.__attrs = __attrs.merge attribute.key => attribute
end
nests( name, opts = {} ) click to toggle source
# File lib/deserializer/attributable.rb, line 43
def nests( name, opts = {} )
  unless opts[:deserializer]
    raise DeserializerError, class: self, message: "nested associations need a deserilaizer" 
  end

  attribute = Attribute::Attribute.new( Attribute::NestedAssociation, name, opts )
  self.__attrs = __attrs.merge attribute.key => attribute
end