Sha256: 3222af3b6e4cf7717b1b34fe3a51f22733cba2d77bfd6f385f3fe70e9f227bef

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

require 'scout/annotation'
require_relative 'entity/format'
require_relative 'entity/property'
require_relative 'entity/object'
require_relative 'entity/identifiers'

module Entity
  def self.extended(base)
    base.extend Annotation
    base.extend Entity::Property
    base.instance_variable_set(:@properties, [])
    base.instance_variable_set(:@persisted_methods, {})
    base.include Entity::Object
    base.include AnnotatedArray
    base
  end

  def self.prepare_entity(entity, field, options = {})
    return entity unless defined? Entity
    return entity unless String === entity or Array === entity
    options ||= {}

    dup_array = options.delete :dup_array

    if Entity === field or (Entity.respond_to?(:formats) and (_format = Entity.formats.find(field)))
      params = options.dup

      params[:format] ||= params.delete "format"
      params.merge!(:format => _format) unless _format.nil? or (params.include?(:format) and not ((f = params[:format]).nil? or (String === f and f.empty?)))

      mod = Entity === field ? field : Entity.formats[field]

      entity = entity.dup
      entity = (entity.frozen? and not entity.nil?) ? entity.dup : ((Array === entity and dup_array) ? entity.collect{|e| e.nil? ? e : e.dup} : entity) 

      entity = mod.setup(entity, params)
    end

    entity
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scout-gear-10.7.0 lib/scout/entity.rb