Module: TaliaCore::ActiveSourceParts::PredicateHandler

Included in:
TaliaCore::ActiveSource
Defined in:
lib/talia_core/active_source_parts/predicate_handler.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#each_cached_wrapperObject

Loops through the cache and passes each existing wrapper to the block



82
83
84
85
# File 'lib/talia_core/active_source_parts/predicate_handler.rb', line 82

def each_cached_wrapper
  return unless(@type_cache)
  @type_cache.each_value {  |wrap| yield(wrap) }
end

#get_objects_on(predicate) ⇒ Object

Returns the objects on the given predicate. This will be cached internally so that the object will always be the same as long as the parent source lives.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/talia_core/active_source_parts/predicate_handler.rb', line 53

def get_objects_on(predicate)
  @type_cache ||= {}
  active_wrapper = @type_cache[predicate.to_s]

  if(active_wrapper.nil?)
    active_wrapper = SemanticCollectionWrapper.new(self, predicate)
    
    # If this is a prefetched source we have everything, so we can 
    # initialize the wrapper without loading anything
    active_wrapper.init_as_empty! if(@prefetched)
    
    @type_cache[predicate.to_s] = active_wrapper
  end
  
  active_wrapper
end

#has_type?(type) ⇒ Boolean

Returns if the Facsimile is of the given type

Returns:

  • (Boolean)


46
47
48
# File 'lib/talia_core/active_source_parts/predicate_handler.rb', line 46

def has_type?(type)
  (self.types.include?(type))
end

#inject_predicate(fat_relation) ⇒ Object

Injects a ‘fat’ predicate relation on a source



94
95
96
97
# File 'lib/talia_core/active_source_parts/predicate_handler.rb', line 94

def inject_predicate(fat_relation)
  wrapper = get_objects_on(fat_relation.predicate_uri)
  wrapper.inject_fat_item(fat_relation)
end

#reset!Object

Clear the source (this will force reloading of elements and discard unsaved changes



89
90
91
# File 'lib/talia_core/active_source_parts/predicate_handler.rb', line 89

def reset!
  @type_cache = nil
end

#save_wrappersObject

Go through the existing relation wrappers and save the (new) items



71
72
73
74
75
76
77
78
79
# File 'lib/talia_core/active_source_parts/predicate_handler.rb', line 71

def save_wrappers
  each_cached_wrapper do |wrap|
    # Load unloaded if we're not rdf_autosaving. Quick hack since otherwise
    # since the blanking of unloaded properties could cause problems with
    # the rdf writing otherwise
    wrap.send(:load!) unless(wrap.loaded? || autosave_rdf?)
    wrap.save_items!
  end
end

#typesObject

Gets the types



41
42
43
# File 'lib/talia_core/active_source_parts/predicate_handler.rb', line 41

def types
  get_objects_on(N::RDF.type.to_s)
end