Skip to content

Commit

Permalink
Rename opened_limit configuration parameter to opened_index_limit
Browse files Browse the repository at this point in the history
  • Loading branch information
simukappu committed Sep 24, 2016
1 parent 8dcde06 commit 591e53c
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 37 deletions.
16 changes: 8 additions & 8 deletions lib/activity_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ def self.config
# All available options and their defaults are in the example below:
# @example Initializer for Rails
# ActivityNotification.configure do |config|
# config.enabled = true
# config.table_name = "notifications"
# config.email_enabled = false
# config.mailer_sender = nil
# config.mailer = 'ActivityNotification::Mailer'
# config.parent_mailer = 'ActionMailer::Base'
# config.parent_controller = 'ApplicationController'
# config.opened_limit = 10
# config.enabled = true
# config.table_name = "notifications"
# config.email_enabled = false
# config.mailer_sender = nil
# config.mailer = 'ActivityNotification::Mailer'
# config.parent_mailer = 'ActionMailer::Base'
# config.parent_controller = 'ApplicationController'
# config.opened_index_limit = 10
# end
def self.configure(&block)
yield(config) if block_given?
Expand Down
16 changes: 8 additions & 8 deletions lib/activity_notification/apis/notification_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def group_member?
#
# @param [Integer] limit Limit to query for opened notifications
# @return [Boolean] If group member of the notification exists
def group_member_exists?(limit = ActivityNotification.config.opened_limit)
def group_member_exists?(limit = ActivityNotification.config.opened_index_limit)
group_member_count(limit) > 0
end

Expand All @@ -209,7 +209,7 @@ def group_member_exists?(limit = ActivityNotification.config.opened_limit)
#
# @param [Integer] limit Limit to query for opened notifications
# @return [Boolean] If group member of the notification exists
def group_member_notifier_exists?(limit = ActivityNotification.config.opened_limit)
def group_member_notifier_exists?(limit = ActivityNotification.config.opened_index_limit)
group_member_notifier_count(limit) > 0
end

Expand All @@ -218,7 +218,7 @@ def group_member_notifier_exists?(limit = ActivityNotification.config.opened_lim
#
# @param [Integer] limit Limit to query for opened notifications
# @return [Integer] Count of group members of the notification
def group_member_count(limit = ActivityNotification.config.opened_limit)
def group_member_count(limit = ActivityNotification.config.opened_index_limit)
notification = group_member? ? group_owner : self
notification.opened? ?
notification.opened_group_member_count(limit) :
Expand All @@ -230,7 +230,7 @@ def group_member_count(limit = ActivityNotification.config.opened_limit)
#
# @param [Integer] limit Limit to query for opened notifications
# @return [Integer] Count of group notifications including owner and members
def group_notification_count(limit = ActivityNotification.config.opened_limit)
def group_notification_count(limit = ActivityNotification.config.opened_index_limit)
group_member_count(limit) + 1
end

Expand All @@ -241,7 +241,7 @@ def group_notification_count(limit = ActivityNotification.config.opened_limit)
#
# @param [Integer] limit Limit to query for opened notifications
# @return [Integer] Count of group member notifiers of the notification
def group_member_notifier_count(limit = ActivityNotification.config.opened_limit)
def group_member_notifier_count(limit = ActivityNotification.config.opened_index_limit)
notification = group_member? ? group_owner : self
notification.opened? ?
notification.opened_group_member_notifier_count(limit) :
Expand All @@ -254,7 +254,7 @@ def group_member_notifier_count(limit = ActivityNotification.config.opened_limit
#
# @param [Integer] limit Limit to query for opened notifications
# @return [Integer] Count of group notifications including owner and members
def group_notifier_count(limit = ActivityNotification.config.opened_limit)
def group_notifier_count(limit = ActivityNotification.config.opened_index_limit)
notification = group_member? ? group_owner : self
notification.notifier.present? ? group_member_notifier_count(limit) + 1 : 0
end
Expand Down Expand Up @@ -288,7 +288,7 @@ def unopened_group_member_count
# @api protected
#
# @return [Integer] Count of group members of the opened notification
def opened_group_member_count(limit = ActivityNotification.config.opened_limit)
def opened_group_member_count(limit = ActivityNotification.config.opened_index_limit)
# Cache group by query result to avoid N+1 call
opened_group_member_counts = target.notifications
.opened_index_group_members_only(limit)
Expand Down Expand Up @@ -320,7 +320,7 @@ def unopened_group_member_notifier_count
# @api protected
#
# @return [Integer] Count of group member notifiers of the opened notification
def opened_group_member_notifier_count(limit = ActivityNotification.config.opened_limit)
def opened_group_member_notifier_count(limit = ActivityNotification.config.opened_index_limit)
# Cache group by query result to avoid N+1 call
opened_group_member_notifier_counts = target.notifications
.opened_index_group_members_only(limit)
Expand Down
26 changes: 13 additions & 13 deletions lib/activity_notification/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,26 @@ class Config
# @return [String] Base controller class for notifications_controller.
attr_accessor :parent_controller

# @overload opened_limit
# @overload opened_index_limit
# @return [Integer] Default limit to query for opened notifications.
# @overload opened_limit=(value)
# Sets the opened_limit
# @param [Integer] opened_limit The new opened_limit
# @overload opened_index_limit=(value)
# Sets the opened_index_limit
# @param [Integer] opened_index_limit The new opened_index_limit
# @return [Integer] Default limit to query for opened notifications.
attr_accessor :opened_limit
attr_accessor :opened_index_limit

# Initialize configuration for ActivityNotification.
# These configuration can be overriden in initializer.
# @return [Config] A new instance of Config
def initialize
@enabled = true
@table_name = 'notifications'
@email_enabled = false
@mailer_sender = nil
@mailer = 'ActivityNotification::Mailer'
@parent_mailer = 'ActionMailer::Base'
@parent_controller = 'ApplicationController'
@opened_limit = 10
@enabled = true
@table_name = 'notifications'
@email_enabled = false
@mailer_sender = nil
@mailer = 'ActivityNotification::Mailer'
@parent_mailer = 'ActionMailer::Base'
@parent_controller = 'ApplicationController'
@opened_index_limit = 10
end

end
Expand Down
4 changes: 2 additions & 2 deletions lib/activity_notification/models/concerns/target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def unopened_notification_index(limit = nil)
#
# @param [Integer] limit Limit to query for notifications
# @return [Array<Notificaion>] Opened notification index of the target
def opened_notification_index(limit = ActivityNotification.config.opened_limit)
def opened_notification_index(limit = ActivityNotification.config.opened_index_limit)
notifications.opened_index(limit)
end

Expand Down Expand Up @@ -193,7 +193,7 @@ def unopened_notification_index_with_attributes(limit = nil)
#
# @param [Integer] limit Limit to query for notifications
# @return [Array<Notificaion>] Opened notification index of the target with attributes
def opened_notification_index_with_attributes(limit = ActivityNotification.config.opened_limit)
def opened_notification_index_with_attributes(limit = ActivityNotification.config.opened_index_limit)
include_attributes opened_notification_index(limit)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/generators/templates/activity_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
# config.parent_mailer = 'ActionMailer::Base'

# Configure default limit number of opened notifications you can get from opened* scope
config.opened_limit = 10
config.opened_index_limit = 10

end
8 changes: 4 additions & 4 deletions spec/concerns/models/target_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,12 @@ def custom_notification_email_allowed?(notifiable, key)
end

context "without limit" do
it "uses ActivityNotification.config.opened_limit as limit" do
configured_opened_limit = ActivityNotification.config.opened_limit
ActivityNotification.config.opened_limit = 1
it "uses ActivityNotification.config.opened_index_limit as limit" do
configured_opened_index_limit = ActivityNotification.config.opened_index_limit
ActivityNotification.config.opened_index_limit = 1
expect(test_instance.opened_notification_index(1).size).to eq(1)
expect(test_instance.opened_notification_index(1).first).to eq(@notification_2)
ActivityNotification.config.opened_limit = configured_opened_limit
ActivityNotification.config.opened_index_limit = configured_opened_index_limit
end

it "returns opened notification index" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
# config.parent_mailer = 'ActionMailer::Base'

# Configure default limit number of opened notifications you can get from opened* scope
config.opened_limit = 10
config.opened_index_limit = 10

end

0 comments on commit 591e53c

Please sign in to comment.