class NormalizrRuby::Schema

Attributes

context[R]
object[R]
props[R]

Public Class Methods

association(key, options = {}) click to toggle source
# File lib/normalizr_ruby/schema.rb, line 21
def self.association(key, options = {})
  _associations[key] = options;
end
attribute(key, options = {}) click to toggle source
# File lib/normalizr_ruby/schema.rb, line 17
def self.attribute(key, options = {})
  _attributes[key] = options;
end
inherited(child) click to toggle source
Calls superclass method
# File lib/normalizr_ruby/schema.rb, line 11
def self.inherited(child)
  super
  child._attributes = _attributes.dup
  child._associations = _associations.dup
end
new(object, context, props) click to toggle source
# File lib/normalizr_ruby/schema.rb, line 25
def initialize(object, context, props)
  @object = object
  @context = context
  @props = props
end

Public Instance Methods

association_resource(association_key) click to toggle source
# File lib/normalizr_ruby/schema.rb, line 59
def association_resource(association_key)
  object.send(association_key)
end
associations() click to toggle source
# File lib/normalizr_ruby/schema.rb, line 40
def associations
  hash = {}
  self.class._associations.each do |key, options|
    next if options[:if] && !send(options[:if])
    hash[key] = options.except(:if)
  end
  hash
end
attributes() click to toggle source
# File lib/normalizr_ruby/schema.rb, line 31
def attributes
  hash = {}
  self.class._attributes.each do |key, options|
    next if options[:if] && !send(options[:if])
    hash[key] = respond_to?(key) ? send(key) : object.send(key)
  end
  hash
end
entity_key() click to toggle source
# File lib/normalizr_ruby/schema.rb, line 49
def entity_key
  klass = object.class
  if klass.respond_to?(:base_class)
    klass = klass.base_class
  end
  klass.name
       .pluralize
       .to_sym
end