Module: Entity

Included in:
AssociationItem
Defined in:
lib/scout/entity.rb,
lib/scout/entity/format.rb,
lib/scout/entity/object.rb,
lib/scout/entity/property.rb,
lib/scout/entity/identifiers.rb

Defined Under Namespace

Modules: Identified, Object, Property Classes: FormatIndex

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.entity_property_cacheObject

Returns the value of attribute entity_property_cache.



3
4
5
# File 'lib/scout/entity/property.rb', line 3

def entity_property_cache
  @entity_property_cache
end

Class Method Details

.extended(base) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/scout/entity.rb', line 8

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

.formatsObject



58
59
60
# File 'lib/scout/entity/format.rb', line 58

def self.formats
  FORMATS
end

.identifier_files(field) ⇒ Object



2
3
4
5
6
# File 'lib/scout/entity/identifiers.rb', line 2

def self.identifier_files(field)
  entity_type = Entity.formats[field]
  return [] unless entity_type and entity_type.include? Entity::Identified 
  entity_type.identifier_files
end

.prepare_entity(entity, field, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/scout/entity.rb', line 18

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)

    entity.extend AnnotatedArray if Array === entity && ! options[:annotated_array] == FalseClass
  end

  entity
end

Instance Method Details

#add_identifiers(file, default = nil, name = nil, description = nil) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/scout/entity/identifiers.rb', line 81

def add_identifiers(file, default = nil, name = nil, description = nil)
  if TSV === file
    all_fields = file.all_fields
  else
    if file =~ /#{Identified::NAMESPACE_TAG}/
      all_fields = file.sub(/#{Identified::NAMESPACE_TAG}/,'**').glob.collect do |f|
        TSV.parse_header(f)["all_fields"]
      end.flatten.compact.uniq
    else
      all_fields = TSV.parse_header(file)["all_fields"]
    end
  end

  self.send(:include, Entity::Identified) unless Entity::Identified === self

  self.format = all_fields
  @formats ||= []
  @formats.concat all_fields
  @formats.uniq!

  @default_format = default if default
  @name_format = name if name
  @description_format = description if description

  @identifier_files ||= []
  @identifier_files << file
  @identifier_files.uniq!
end

#format=(formats) ⇒ Object



2
3
4
5
6
7
# File 'lib/scout/entity/format.rb', line 2

def format=(formats)
  formats = [formats] unless Array === formats
  formats.each do |format|
    Entity.formats[format] ||= self
  end
end