Class: Redmine::Activity::Fetcher
- Inherits:
-
Object
- Object
- Redmine::Activity::Fetcher
- Defined in:
- lib/redmine/activity/fetcher.rb
Overview
Class used to retrieve activity events
Instance Attribute Summary collapse
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#default_scope! ⇒ Object
Resets the scope to the default scope.
-
#event_types ⇒ Object
Returns an array of available event types.
-
#events(from = nil, to = nil, options = {}) ⇒ Object
Returns an array of events for the given date range sorted in reverse chronological order.
-
#initialize(user, options = {}) ⇒ Fetcher
constructor
A new instance of Fetcher.
-
#scope_select(&block) ⇒ Object
Yields to filter the activity scope.
Constructor Details
#initialize(user, options = {}) ⇒ Fetcher
Returns a new instance of Fetcher.
26 27 28 29 30 31 32 33 |
# File 'lib/redmine/activity/fetcher.rb', line 26 def initialize(user, ={}) .assert_valid_keys(:project, :with_subprojects, :author) @user = user @project = [:project] @options = @scope = event_types end |
Instance Attribute Details
#project ⇒ Object (readonly)
Returns the value of attribute project.
24 25 26 |
# File 'lib/redmine/activity/fetcher.rb', line 24 def project @project end |
#scope ⇒ Object
Returns the value of attribute scope.
24 25 26 |
# File 'lib/redmine/activity/fetcher.rb', line 24 def scope @scope end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
24 25 26 |
# File 'lib/redmine/activity/fetcher.rb', line 24 def user @user end |
Instance Method Details
#default_scope! ⇒ Object
Resets the scope to the default scope
81 82 83 |
# File 'lib/redmine/activity/fetcher.rb', line 81 def default_scope! @scope = Redmine::Activity.default_event_types end |
#event_types ⇒ Object
Returns an array of available event types
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/redmine/activity/fetcher.rb', line 36 def event_types return @event_types unless @event_types.nil? @event_types = Redmine::Activity.available_event_types if @project projects = @project.self_and_descendants @event_types = @event_types.select do |event_type| keep = false constantized_providers(event_type).each do |provider| = provider.[event_type] = [:permission] unless .key?(:permission) ||= "view_#{event_type}".to_sym end if keep |= projects.any? {|p| @user.allowed_to?(, p)} else keep = true end end keep end end @event_types end |
#events(from = nil, to = nil, options = {}) ⇒ Object
Returns an array of events for the given date range sorted in reverse chronological order
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/redmine/activity/fetcher.rb', line 87 def events(from = nil, to = nil, ={}) e = [] @options[:limit] = [:limit] @scope.each do |event_type| constantized_providers(event_type).each do |provider| e += provider.find_events(event_type, @user, from, to, @options) end end e.sort! {|a, b| b.event_datetime <=> a.event_datetime} if [:limit] e = e.slice(0, [:limit]) end e end |
#scope_select(&block) ⇒ Object
Yields to filter the activity scope
63 64 65 |
# File 'lib/redmine/activity/fetcher.rb', line 63 def scope_select(&block) @scope = @scope.select {|t| yield t} end |