Class: Editstore::Change
- Inherits:
-
Connection
- Object
- ActiveRecord::Base
- Connection
- Editstore::Change
- Defined in:
- app/models/editstore/change.rb
Constant Summary collapse
- OPERATIONS =
THESE REALLY BELONG IN THE CONTROLLER and are only necessary for mass assignment def change_params
params.require(:change).permit(:field,:project_id,:old_value,:new_value,:operation,:client_note,:druid,:state_id,:error,:pending)
end
%w{create update delete}
Class Method Summary collapse
- .by_project_id(project_id) ⇒ Object
- .by_state_id(state_id) ⇒ Object
-
.latest(params = {}) ⇒ Object
get the latest changes to process for a specific state (defaults to ready) and an optional limit if not restricted by druid, will group by druid.
-
.latest_druids(params = {}) ⇒ Object
get the latest list of unique druids to process for a specific state (defaults to ready) and an optional limit, return an array.
- .prune ⇒ Object
Class Method Details
.by_project_id(project_id) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'app/models/editstore/change.rb', line 34 def self.by_project_id(project_id) if project_id.to_s.empty? #scoped where(nil) else where(:project_id=>project_id) end end |
.by_state_id(state_id) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'app/models/editstore/change.rb', line 43 def self.by_state_id(state_id) if state_id.to_s.empty? #scoped where(nil) else where(:state_id=>state_id) end end |
.latest(params = {}) ⇒ Object
get the latest changes to process for a specific state (defaults to ready) and an optional limit if not restricted by druid, will group by druid
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/models/editstore/change.rb', line 54 def self.latest(params={}) state_id=params[:state_id] || Editstore::State.ready.id limit=params[:limit] project_id=params[:project_id] druid=params[:druid] #changes = scoped changes = where(nil) changes = changes.includes(:project) changes = changes.where(:state_id=>state_id) if state_id != '*' changes = changes.where(:project_id=>project_id) if project_id changes = changes.where(:druid=>druid) if druid changes = changes.order('created_at,id asc') changes = changes.limit(limit) unless limit.blank? druid ? changes : changes.group_by {|c| c.druid} end |
.latest_druids(params = {}) ⇒ Object
get the latest list of unique druids to process for a specific state (defaults to ready) and an optional limit, return an array
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/models/editstore/change.rb', line 74 def self.latest_druids(params={}) state_id=params[:state_id] || Editstore::State.ready.id limit=params[:limit] project_id=params[:project_id] #changes = scoped changes = where(nil) changes = changes.includes(:project) changes = changes.where(:state_id=>state_id) if state_id != '*' changes = changes.where(:project_id=>project_id) if project_id changes = changes.order('editstore_changes.created_at,editstore_changes.id asc') changes = changes.limit(limit) unless limit.blank? changes.distinct.pluck('druid').uniq end |