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.



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

def entity_property_cache
  @entity_property_cache
end

Class Method Details

.extended(base) ⇒ Object



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

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.format = base.to_s
  base
end

.formatsObject



63
64
65
# File 'lib/scout/entity/format.rb', line 63

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[Entity.formats.find(field)]
  return [] unless entity_type and entity_type.include? Entity::Identified 
  entity_type.identifier_files
end

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



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

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

  if Entity === field or (Entity.respond_to?(:formats) and (_format = Entity.formats.find(field)))
    options ||= {}

    dup_array = options.delete :dup_array

    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



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
109
110
111
112
113
# File 'lib/scout/entity/identifiers.rb', line 84

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

  name = default if name.nil?

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

  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