class Ivy::Serializers::Mapping

Public Class Methods

new(klass) click to toggle source
# File lib/ivy/serializers/mapping.rb, line 7
def initialize(klass)
  @attributes = {}
  @relationships = {}
  @klass = klass
end

Public Instance Methods

attribute(name, &block) click to toggle source
# File lib/ivy/serializers/mapping.rb, line 13
def attribute(name, &block)
  @attributes[name] = Attribute.new(name, &block)
end
attributes(*names) click to toggle source
# File lib/ivy/serializers/mapping.rb, line 17
def attributes(*names)
  names.each { |name| attribute(name) }
end
belongs_to(name, options={}, &block) click to toggle source
# File lib/ivy/serializers/mapping.rb, line 21
def belongs_to(name, options={}, &block)
  @relationships[name] = Relationships::BelongsTo.new(name, options, &block)
end
generate_attributes(generator, resource) click to toggle source
# File lib/ivy/serializers/mapping.rb, line 25
def generate_attributes(generator, resource)
  @attributes.each_value { |attribute| attribute.generate(generator, resource) }
end
has_many(name, options={}, &block) click to toggle source
# File lib/ivy/serializers/mapping.rb, line 29
def has_many(name, options={}, &block)
  @relationships[name] = Relationships::HasMany.new(name, options, &block)
end
relationships(generator, resource) click to toggle source
# File lib/ivy/serializers/mapping.rb, line 33
def relationships(generator, resource)
  @relationships.each_value { |relationship| relationship.generate(generator, resource) }
end
resource(generator, resource) click to toggle source
# File lib/ivy/serializers/mapping.rb, line 37
def resource(generator, resource)
  generator.attributes(resource) unless @attributes.empty?
  generator.relationships(resource) unless @relationships.empty?
end