Class: TaliaCore::Oai::ActiveSourceModel
- Inherits:
-
OAI::Provider::Model
- Object
- OAI::Provider::Model
- TaliaCore::Oai::ActiveSourceModel
- 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
-
#model_adapter ⇒ Object
Returns the value of attribute model_adapter.
Instance Method Summary collapse
- #earliest ⇒ Object
- #find(selector, options = {}) ⇒ Object
-
#initialize(model_adapter = ActiveSourceOaiAdapter) ⇒ ActiveSourceModel
constructor
A new instance of ActiveSourceModel.
- #last_id(options) ⇒ Object
- #latest ⇒ Object
- #sets ⇒ Object
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_adapter ⇒ Object
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
#earliest ⇒ Object
23 24 25 |
# File 'lib/talia_core/oai/active_source_model.rb', line 23 def earliest select_first_or_last('asc').send() 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, = {}) return select_partial([:resumption_token]) if([:resumption_token]) conditions = sql_conditions() 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), .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() select_first_or_last('desc', ).id end |
#latest ⇒ Object
27 28 29 |
# File 'lib/talia_core/oai/active_source_model.rb', line 27 def latest select_first_or_last('desc').send() end |
#sets ⇒ Object
35 36 37 |
# File 'lib/talia_core/oai/active_source_model.rb', line 35 def sets raise OAI::SetException # TODO: Support sets end |