Class: TaliaCore::Oai::ActiveSourceModel

Inherits:
OAI::Provider::Model
  • Object
show all
Defined in:
lib/talia_core/oai/active_source_model.rb

Overview

Basic OAI Model for ActiveSources. This provides basic OAI functionality on ActiveSource in the same way the ActiveRecordWrapper provides the functionality on ActiveRecord.

All #find() and related calls will “wrap” the ActiveSource models using using the ActiveSourceOaiAdapter class. You may provide your own adapter class if needed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_adapter = ActiveSourceOaiAdapter) ⇒ ActiveSourceModel

Returns a new instance of ActiveSourceModel.



17
18
19
20
21
# File 'lib/talia_core/oai/active_source_model.rb', line 17

def initialize(model_adapter = ActiveSourceOaiAdapter)
  @model_adapter = (model_adapter || ActiveSourceOaiAdapter)
  @timestamp_field = "created_at"
  @limit = 20
end

Instance Attribute Details

#model_adapterObject

Returns the value of attribute model_adapter.



15
16
17
# File 'lib/talia_core/oai/active_source_model.rb', line 15

def model_adapter
  @model_adapter
end

Instance Method Details

#earliestObject



23
24
25
# File 'lib/talia_core/oai/active_source_model.rb', line 23

def earliest
  select_first_or_last('asc').send(timestamp_field)
end

#find(selector, options = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/talia_core/oai/active_source_model.rb', line 39

def find(selector, options = {})
  return select_partial(options[:resumption_token]) if(options[:resumption_token])
  
  conditions = sql_conditions(options)
 
  if(selector == :first)
    #model_adapter.get_wrapper_for(ActiveSource.find(selector, :prefetch_relations => true, :conditions => conditions))
    model_adapter.get_wrapper_for(Source.find(selector, :prefetch_relations => true, :conditions => conditions))
  elsif(selector == :all)
    select_partial(OAI::Provider::ResumptionToken.new(last_id(conditions), options.merge(:last => 0)))
  else
    #model_adapter.get_wrapper_for(ActiveSource.find(selector, :prefetch_relations => true, :conditions => conditions))
    model_adapter.get_wrapper_for(Source.find(selector, :prefetch_relations => true, :conditions => conditions))
  end
rescue ActiveRecord::RecordNotFound
  nil
end

#last_id(options) ⇒ Object



31
32
33
# File 'lib/talia_core/oai/active_source_model.rb', line 31

def last_id(options)
  select_first_or_last('desc', options).id
end

#latestObject



27
28
29
# File 'lib/talia_core/oai/active_source_model.rb', line 27

def latest
  select_first_or_last('desc').send(timestamp_field)
end

#setsObject

Raises:

  • (OAI::SetException)


35
36
37
# File 'lib/talia_core/oai/active_source_model.rb', line 35

def sets
  raise OAI::SetException # TODO: Support sets
end