Class: Redmine::Activity::Fetcher
- Inherits:
-
Object
- Object
- Redmine::Activity::Fetcher
- Defined in:
- lib/redmine/activity/fetcher.rb
Overview
Class used to retrieve activity events
Constant Summary
- @@constantized_providers =
Needs to be unloaded in development mode
Hash.new {|h,k| h[k] = Redmine::Activity.providers[k].collect {|t| t.constantize } }
Instance Attribute Summary (collapse)
-
- (Object) project
readonly
Returns the value of attribute project.
-
- (Object) scope
Returns the value of attribute scope.
-
- (Object) user
readonly
Returns the value of attribute user.
Instance Method Summary (collapse)
-
- (Object) default_scope!
Resets the scope to the default scope.
-
- (Object) event_types
Returns an array of available event types.
-
- (Object) events(from = nil, to = nil, options = {})
Returns an array of events for the given date range.
-
- (Fetcher) initialize(user, options = {})
constructor
A new instance of Fetcher.
-
- (Object) scope_select(&block)
Yields to filter the activity scope.
Constructor Details
- (Fetcher) initialize(user, options = {})
A new instance of Fetcher
27 28 29 30 31 32 33 34 |
# File 'lib/redmine/activity/fetcher.rb', line 27 def initialize(user, ={}) .assert_valid_keys(:project, :with_subprojects, :author) @user = user @project = [:project] @options = @scope = event_types end |
Instance Attribute Details
- (Object) project (readonly)
Returns the value of attribute project
22 23 24 |
# File 'lib/redmine/activity/fetcher.rb', line 22 def project @project end |
- (Object) scope
Returns the value of attribute scope
22 23 24 |
# File 'lib/redmine/activity/fetcher.rb', line 22 def scope @scope end |
- (Object) user (readonly)
Returns the value of attribute user
22 23 24 |
# File 'lib/redmine/activity/fetcher.rb', line 22 def user @user end |
Instance Method Details
- (Object) default_scope!
Resets the scope to the default scope
64 65 66 |
# File 'lib/redmine/activity/fetcher.rb', line 64 def default_scope! @scope = Redmine::Activity.default_event_types end |
- (Object) event_types
Returns an array of available event types
37 38 39 40 41 42 43 |
# File 'lib/redmine/activity/fetcher.rb', line 37 def event_types return @event_types unless @event_types.nil? @event_types = Redmine::Activity.available_event_types @event_types = @event_types.select {|o| @user.allowed_to?("view_#{o}".to_sym, @project)} if @project @event_types end |
- (Object) events(from = nil, to = nil, options = {})
Returns an array of events for the given date range
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/redmine/activity/fetcher.rb', line 69 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 if [:limit] e.sort! {|a,b| b.event_date <=> a.event_date} e = e.slice(0, [:limit]) end e end |
- (Object) scope_select(&block)
Yields to filter the activity scope
46 47 48 |
# File 'lib/redmine/activity/fetcher.rb', line 46 def scope_select(&block) @scope = @scope.select {|t| yield t } end |