lib/notification_settings/setting_library.rb in notification-settings-1.0.0.beta8 vs lib/notification_settings/setting_library.rb in notification-settings-1.0.0.beta9

- old
+ new

@@ -1,16 +1,26 @@ module NotificationSettings module SettingLibrary - def status - if self.object.respond_to?(NotificationSettings.configuration.last_seen) && ( Time.now - self.object.send(NotificationSettings.configuration.last_seen) ).round >= NotificationSettings.configuration.idle_after && ( Time.now - self.object.send(NotificationSettings.configuration.last_seen) ).round < NotificationSettings.configuration.offline_after - default = 'idle' - elsif self.object.respond_to?(NotificationSettings.configuration.last_seen) && ( Time.now - self.object.send(NotificationSettings.configuration.last_seen) ).round >= NotificationSettings.configuration.offline_after - default = 'offline' - else - 'online' + extend ActiveSupport::Concern + + included do + include NotificationSettings::SettingLibrary::InstanceMethods + end + + module InstanceMethods + + def status + if self.object.respond_to?(NotificationSettings.configuration.last_seen) && ( Time.now - self.object.send(NotificationSettings.configuration.last_seen) ).round >= NotificationSettings.configuration.idle_after && ( Time.now - self.object.send(NotificationSettings.configuration.last_seen) ).round < NotificationSettings.configuration.offline_after + default = 'idle' + elsif self.object.respond_to?(NotificationSettings.configuration.last_seen) && ( Time.now - self.object.send(NotificationSettings.configuration.last_seen) ).round >= NotificationSettings.configuration.offline_after + default = 'offline' + else + 'online' + end + self[:status] || default end - self[:status] || default + end end end