module Extendible

Constants

VERSION

Public Class Methods

included(base) click to toggle source
# File lib/extendible.rb, line 5
def self.included(base)
  base.class_eval { extend ClassMethods }
end

Public Instance Methods

extended_objects() click to toggle source
# File lib/extendible.rb, line 9
def extended_objects
  return @extended_objects unless @extended_objects.nil?
  # empty array if no params[:extend] is provided
  return {} if scope.nil? or scope[:extend].nil?
  all = {}
  # iterate comma separated list of objects to extend
  scope[:extend].split(',').map(&:strip).each do |object_name|
    if object_name.include?('.') # dot found, split into object and attribute
      obj, attr = object_name.split('.')
      all[obj.to_sym] = ['id'] unless all.has_key?(obj.to_sym)
      if all.has_key?(obj.to_sym) # object already has attributes specified, add attribute to array
        all[obj.to_sym] << attr
      else # first attribute for array, initialize array with attribute
        all[obj.to_sym] = [attr]
      end
    else # no dot (.) found, extend with all attributes
      all[object_name.to_sym] = nil
    end
  end

  @extended_objects = all
end
perform_serialization(object, child_sym) click to toggle source
# File lib/extendible.rb, line 32
def perform_serialization(object, child_sym)
  serializer_name = "#{child_sym.to_s.camelize}Serializer"              
  serializer_name.constantize.new(object.try(child_sym)) rescue object.try(child_sym)
end