Class: Dynamoid::Criteria::Chain
- Inherits:
-
Object
- Object
- Dynamoid::Criteria::Chain
- Defined in:
- lib/activity_notification/orm/dynamoid/extension.rb,
lib/activity_notification/orm/dynamoid.rb
Overview
Direct Known Subclasses
Class Method Summary collapse
-
.all_index!(reverse = false, with_group_members = false) ⇒ Dynamoid::Criteria::Chain
Selects all notification index.
-
.earlier_than(created_time) ⇒ ActiveRecord_AssociationRelation<Notificaion>, Mongoid::Criteria<Notificaion>
Selects filtered notifications earlier than specified time.
-
.exists? ⇒ Boolean
Return if records exist.
-
.filtered_by_association(name, instance) ⇒ Dynamoid::Criteria::Chain
Selects filtered notifications or subscriptions by associated instance.
-
.filtered_by_association_type(name, type) ⇒ Dynamoid::Criteria::Chain
Selects filtered notifications or subscriptions by association type.
-
.filtered_by_association_type_and_id(name, type, id) ⇒ Dynamoid::Criteria::Chain
Selects filtered notifications or subscriptions by association type and id.
-
.filtered_by_group(group) ⇒ Dynamoid::Criteria::Chain
Selects filtered notifications by group instance.
-
.filtered_by_instance(notifiable) ⇒ Dynamoid::Criteria::Chain
Selects filtered notifications by notifiable instance.
-
.filtered_by_key(key) ⇒ Dynamoid::Criteria::Chain
Selects filtered notifications or subscriptions by key.
-
.filtered_by_options(options = {}) ⇒ Dynamoid::Criteria::Chain
Selects filtered notifications or subscriptions by notifiable_type, group or key with filter options.
-
.filtered_by_target(target) ⇒ Dynamoid::Criteria::Chain
Selects filtered notifications or subscriptions by target instance.
-
.filtered_by_target_type(target_type) ⇒ Dynamoid::Criteria::Chain
Selects filtered notifications or subscriptions by target_type.
-
.filtered_by_type(notifiable_type) ⇒ Dynamoid::Criteria::Chain
Selects filtered notifications by notifiable_type.
-
.group_members_of_owner_ids_only(owner_ids) ⇒ Dynamoid::Criteria::Chain
Selects group member notifications with specified group owner ids.
-
.group_members_only ⇒ Dynamoid::Criteria::Chain
Selects group member notifications only.
-
.group_owners_only ⇒ Dynamoid::Criteria::Chain
Selects group owner notifications only.
-
.later_than(created_time) ⇒ ActiveRecord_AssociationRelation<Notificaion>, Mongoid::Criteria<Notificaion>
Selects filtered notifications later than specified time.
-
.limit(limit) ⇒ Dynamoid::Criteria::Chain
Set query result limit as record_limit of Dynamoid.
-
.opened_index(limit, reverse = false, with_group_members = false) ⇒ Dynamoid::Criteria::Chain
Selects unopened notification index.
-
.opened_index_group_members_only(limit) ⇒ Dynamoid::Criteria::Chain
Selects group member notifications in opened_index.
-
.opened_only(limit) ⇒ Dynamoid::Criteria::Chain
Selects opened notifications only with limit.
-
.opened_only! ⇒ Dynamoid::Criteria::Chain
Selects opened notifications only without limit.
-
.size ⇒ Integer
Return size of records as count.
-
.unopened_index(reverse = false, with_group_members = false) ⇒ Dynamoid::Criteria::Chain
Selects unopened notification index.
-
.unopened_index_group_members_only ⇒ Dynamoid::Criteria::Chain
Selects group member notifications in unopened_index.
-
.unopened_only ⇒ Dynamoid::Criteria::Chain
Selects unopened notifications only.
-
.within_expiration_only(expiry_delay) ⇒ Dynamoid::Criteria::Chain
Selects notifications within expiration.
Instance Method Summary collapse
-
#earliest ⇒ Notification
Returns earliest notification instance.
-
#earliest! ⇒ Notification
Returns earliest notification instance.
-
#earliest_order ⇒ Dynamoid::Criteria::Chain
Orders by earliest (older) first as created_at: :asc.
-
#earliest_order! ⇒ Array
Orders by earliest (older) first as created_at: :asc and returns as array.
-
#earliest_subscribed_order ⇒ Array
Orders by earliest (older) first as subscribed_at: :asc.
-
#key_order ⇒ Array
Orders by key name as key: :asc.
-
#latest ⇒ Notification
Returns latest notification instance.
-
#latest! ⇒ Notification
Returns latest notification instance.
-
#latest_order ⇒ Dynamoid::Criteria::Chain
Orders by latest (newest) first as created_at: :desc.
-
#latest_order!(reverse = false) ⇒ Array
Orders by latest (newest) first as created_at: :desc and returns as array.
-
#latest_subscribed_order ⇒ Array
Orders by latest (newest) first as subscribed_at: :desc.
-
#none ⇒ Object
Return new none object.
-
#reload ⇒ Object
Dummy reload method for test of notifications or subscriptions.
-
#serializable_hash(options = {}) ⇒ Object
Return serializable_hash as array.
-
#uniq_keys ⇒ Array<String>
Selects unique keys from query for notifications or subscriptions.
-
#update_all(conditions = {}) ⇒ Object
TODO Make this batch.
-
#with_group ⇒ Dynamoid::Criteria::Chain
Includes group instance with query for notifications.
-
#with_group_members ⇒ Dynamoid::Criteria::Chain
Includes group member instances with query for notifications.
-
#with_group_owner ⇒ Dynamoid::Criteria::Chain
Includes group owner instances with query for notifications.
-
#with_notifiable ⇒ Dynamoid::Criteria::Chain
Includes notifiable instance with query for notifications.
-
#with_notifier ⇒ Dynamoid::Criteria::Chain
Includes notifier instance with query for notifications.
-
#with_target ⇒ Dynamoid::Criteria::Chain
Includes target instance with query for notifications or subscriptions.
Class Method Details
.all_index!(reverse = false, with_group_members = false) ⇒ Dynamoid::Criteria::Chain
Selects all notification index.
ActivityNotification::Notification.all_index!
is defined same as
ActivityNotification::Notification.group_owners_only.latest_order
140 141 142 143 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 140 def all_index!(reverse = false, with_group_members = false) target_index = with_group_members ? self : group_owners_only reverse ? target_index.earliest_order : target_index.latest_order end |
.earlier_than(created_time) ⇒ ActiveRecord_AssociationRelation<Notificaion>, Mongoid::Criteria<Notificaion>
Selects filtered notifications earlier than specified time.
285 286 287 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 285 def earlier_than(created_time) where('created_at.lt': created_time) end |
.exists? ⇒ Boolean
Return if records exist
51 52 53 |
# File 'lib/activity_notification/orm/dynamoid/extension.rb', line 51 def exists? record_limit(1).count > 0 end |
.filtered_by_association(name, instance) ⇒ Dynamoid::Criteria::Chain
Selects filtered notifications or subscriptions by associated instance.
183 184 185 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 183 def filtered_by_association(name, instance) instance.present? ? where("#{name}_key" => "#{instance.class.name}#{ActivityNotification.config.composite_key_delimiter}#{instance.id}") : where("#{name}_key.null" => true) end |
.filtered_by_association_type(name, type) ⇒ Dynamoid::Criteria::Chain
Selects filtered notifications or subscriptions by association type.
192 193 194 195 196 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 192 def filtered_by_association_type(name, type) # Handle both string class names and object instances type_name = type.is_a?(String) ? type : type.class.name where("#{name}_key.begins_with" => "#{type_name}#{ActivityNotification.config.composite_key_delimiter}") end |
.filtered_by_association_type_and_id(name, type, id) ⇒ Dynamoid::Criteria::Chain
Selects filtered notifications or subscriptions by association type and id.
204 205 206 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 204 def filtered_by_association_type_and_id(name, type, id) type.present? && id.present? ? where("#{name}_key" => "#{type}#{ActivityNotification.config.composite_key_delimiter}#{id}") : none end |
.filtered_by_group(group) ⇒ Dynamoid::Criteria::Chain
Selects filtered notifications by group instance.
235 236 237 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 235 def filtered_by_group(group) filtered_by_association("group", group) end |
.filtered_by_instance(notifiable) ⇒ Dynamoid::Criteria::Chain
Selects filtered notifications by notifiable instance.
225 226 227 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 225 def filtered_by_instance(notifiable) filtered_by_association("notifiable", notifiable) end |
.filtered_by_key(key) ⇒ Dynamoid::Criteria::Chain
Selects filtered notifications or subscriptions by key.
265 266 267 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 265 def filtered_by_key(key) where(key: key) end |
.filtered_by_options(options = {}) ⇒ Dynamoid::Criteria::Chain
Selects filtered notifications or subscriptions by notifiable_type, group or key with filter options.
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 313 def ( = {}) = ActivityNotification.cast_to_indifferent_hash() filtered_notifications = self if .has_key?(:filtered_by_type) filtered_notifications = filtered_notifications.filtered_by_type([:filtered_by_type]) end if .has_key?(:filtered_by_group) filtered_notifications = filtered_notifications.filtered_by_group([:filtered_by_group]) end if .has_key?(:filtered_by_group_type) && .has_key?(:filtered_by_group_id) filtered_notifications = filtered_notifications.filtered_by_association_type_and_id("group", [:filtered_by_group_type], [:filtered_by_group_id]) end if .has_key?(:filtered_by_key) filtered_notifications = filtered_notifications.filtered_by_key([:filtered_by_key]) end if .has_key?(:later_than) filtered_notifications = filtered_notifications.later_than(Time.iso8601([:later_than])) end if .has_key?(:earlier_than) filtered_notifications = filtered_notifications.earlier_than(Time.iso8601([:earlier_than])) end if .has_key?(:custom_filter) filtered_notifications = filtered_notifications.where([:custom_filter]) end filtered_notifications end |
.filtered_by_target(target) ⇒ Dynamoid::Criteria::Chain
Selects filtered notifications or subscriptions by target instance.
ActivityNotification::Notification.filtered_by_target(@user)
is the same as
@user.notifications
215 216 217 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 215 def filtered_by_target(target) filtered_by_association("target", target) end |
.filtered_by_target_type(target_type) ⇒ Dynamoid::Criteria::Chain
Selects filtered notifications or subscriptions by target_type.
245 246 247 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 245 def filtered_by_target_type(target_type) filtered_by_association_type("target", target_type) end |
.filtered_by_type(notifiable_type) ⇒ Dynamoid::Criteria::Chain
Selects filtered notifications by notifiable_type.
255 256 257 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 255 def filtered_by_type(notifiable_type) filtered_by_association_type("notifiable", notifiable_type) end |
.group_members_of_owner_ids_only(owner_ids) ⇒ Dynamoid::Criteria::Chain
Selects group member notifications with specified group owner ids.
485 486 487 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 485 def group_members_of_owner_ids_only(owner_ids) owner_ids.present? ? where('group_owner_id.in': owner_ids) : none end |
.group_members_only ⇒ Dynamoid::Criteria::Chain
Selects group member notifications only.
403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 403 def group_members_only # Create a new chain to avoid state issues new_chain = @source.where('group_owner_id.not_null': true) # Apply existing conditions from current chain if instance_variable_defined?(:@where_conditions) && @where_conditions @where_conditions.instance_variable_get(:@hash_conditions).each do |condition| # Skip conflicting group_owner_id conditions next if condition.key?(:"group_owner_id.null") || condition.key?(:"group_owner_id.not_null") new_chain = new_chain.where(condition) end end new_chain end |
.group_owners_only ⇒ Dynamoid::Criteria::Chain
Selects group owner notifications only.
396 397 398 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 396 def group_owners_only where('group_owner_id.null': true) end |
.later_than(created_time) ⇒ ActiveRecord_AssociationRelation<Notificaion>, Mongoid::Criteria<Notificaion>
Selects filtered notifications later than specified time.
275 276 277 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 275 def later_than(created_time) where('created_at.gt': created_time) end |
.limit(limit) ⇒ Dynamoid::Criteria::Chain
Set query result limit as record_limit of Dynamoid
44 45 46 |
# File 'lib/activity_notification/orm/dynamoid/extension.rb', line 44 def limit(limit) record_limit(limit) end |
.opened_index(limit, reverse = false, with_group_members = false) ⇒ Dynamoid::Criteria::Chain
Selects unopened notification index.
ActivityNotification::Notification.opened_index(limit)
is defined same as
ActivityNotification::Notification.opened_only(limit).group_owners_only.latest_order
173 174 175 176 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 173 def opened_index(limit, reverse = false, with_group_members = false) target_index = with_group_members ? opened_only(limit) : opened_only(limit).group_owners_only reverse ? target_index.earliest_order : target_index.latest_order end |
.opened_index_group_members_only(limit) ⇒ Dynamoid::Criteria::Chain
Selects group member notifications in opened_index.
468 469 470 471 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 468 def opened_index_group_members_only(limit) group_owner_ids = opened_index(limit).map(&:id) group_owner_ids.empty? ? none : where('group_owner_id.in': group_owner_ids) end |
.opened_only(limit) ⇒ Dynamoid::Criteria::Chain
Selects opened notifications only with limit.
452 453 454 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 452 def opened_only(limit) limit == 0 ? none : opened_only!.limit(limit) end |
.opened_only! ⇒ Dynamoid::Criteria::Chain
Selects opened notifications only without limit. Be careful to get too many records with this method.
436 437 438 439 440 441 442 443 444 445 446 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 436 def opened_only! # Create a new chain to avoid state issues new_chain = @source.where('opened_at.not_null': true) # Apply existing conditions from current chain if instance_variable_defined?(:@where_conditions) && @where_conditions @where_conditions.instance_variable_get(:@hash_conditions).each do |condition| new_chain = new_chain.where(condition) end end new_chain end |
.size ⇒ Integer
Return size of records as count
58 59 60 |
# File 'lib/activity_notification/orm/dynamoid/extension.rb', line 58 def size count end |
.unopened_index(reverse = false, with_group_members = false) ⇒ Dynamoid::Criteria::Chain
Selects unopened notification index.
ActivityNotification::Notification.unopened_index
is defined same as
ActivityNotification::Notification.unopened_only.group_owners_only.latest_order
156 157 158 159 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 156 def unopened_index(reverse = false, with_group_members = false) target_index = with_group_members ? unopened_only : unopened_only.group_owners_only reverse ? target_index.earliest_order : target_index.latest_order end |
.unopened_index_group_members_only ⇒ Dynamoid::Criteria::Chain
Selects group member notifications in unopened_index.
459 460 461 462 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 459 def unopened_index_group_members_only group_owner_ids = unopened_index.map(&:id) group_owner_ids.empty? ? none : where('group_owner_id.in': group_owner_ids) end |
.unopened_only ⇒ Dynamoid::Criteria::Chain
Selects unopened notifications only.
420 421 422 423 424 425 426 427 428 429 430 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 420 def unopened_only # Create a new chain to avoid state issues new_chain = @source.where('opened_at.null': true) # Apply existing conditions from current chain if instance_variable_defined?(:@where_conditions) && @where_conditions @where_conditions.instance_variable_get(:@hash_conditions).each do |condition| new_chain = new_chain.where(condition) end end new_chain end |
.within_expiration_only(expiry_delay) ⇒ Dynamoid::Criteria::Chain
Selects notifications within expiration.
477 478 479 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 477 def within_expiration_only(expiry_delay) where('created_at.gt': expiry_delay.ago) end |
Instance Method Details
#earliest ⇒ Notification
Returns earliest notification instance.
538 539 540 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 538 def earliest earliest_order.first end |
#earliest! ⇒ Notification
Returns earliest notification instance. It does not use sort key in DynamoDB tables.
552 553 554 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 552 def earliest! earliest_order!.first end |
#earliest_order ⇒ Dynamoid::Criteria::Chain
Orders by earliest (older) first as created_at: :asc. It uses sort key of Global Secondary Index in DynamoDB tables.
351 352 353 354 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 351 def earliest_order # order(created_at: :asc) scan_index_forward(true) end |
#earliest_order! ⇒ Array
Orders by earliest (older) first as created_at: :asc and returns as array. It does not use sort key in DynamoDB tables.
367 368 369 370 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 367 def earliest_order! # order(created_at: :asc) all.to_a.sort_by {|n| n.created_at } end |
#earliest_subscribed_order ⇒ Array
Orders by earliest (older) first as subscribed_at: :asc.
381 382 383 384 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 381 def earliest_subscribed_order # order(subscribed_at: :asc) all.to_a.sort_by {|n| n.subscribed_at } end |
#key_order ⇒ Array
Orders by key name as key: :asc.
388 389 390 391 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 388 def key_order # order(key: :asc) all.to_a.sort_by {|n| n.key } end |
#latest ⇒ Notification
Returns latest notification instance.
532 533 534 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 532 def latest latest_order.first end |
#latest! ⇒ Notification
Returns latest notification instance. It does not use sort key in DynamoDB tables.
545 546 547 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 545 def latest! latest_order!.first end |
#latest_order ⇒ Dynamoid::Criteria::Chain
Orders by latest (newest) first as created_at: :desc. It uses sort key of Global Secondary Index in DynamoDB tables.
343 344 345 346 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 343 def latest_order # order(created_at: :desc) scan_index_forward(false) end |
#latest_order!(reverse = false) ⇒ Array
Orders by latest (newest) first as created_at: :desc and returns as array.
359 360 361 362 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 359 def latest_order!(reverse = false) # order(created_at: :desc) reverse ? earliest_order! : earliest_order!.reverse end |
#latest_subscribed_order ⇒ Array
Orders by latest (newest) first as subscribed_at: :desc.
374 375 376 377 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 374 def latest_subscribed_order # order(subscribed_at: :desc) earliest_subscribed_order.reverse end |
#none ⇒ Object
Return new none object
36 37 38 |
# File 'lib/activity_notification/orm/dynamoid/extension.rb', line 36 def none None.new(self.source) end |
#reload ⇒ Object
Dummy reload method for test of notifications or subscriptions.
526 527 528 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 526 def reload self end |
#serializable_hash(options = {}) ⇒ Object
Return serializable_hash as array
70 71 72 |
# File 'lib/activity_notification/orm/dynamoid/extension.rb', line 70 def serializable_hash( = {}) all.to_a.map { |r| r.serializable_hash() } end |
#uniq_keys ⇒ Array<String>
Selects unique keys from query for notifications or subscriptions.
558 559 560 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 558 def uniq_keys all.to_a.collect {|n| n.key }.uniq end |
#update_all(conditions = {}) ⇒ Object
TODO Make this batch
63 64 65 66 67 |
# File 'lib/activity_notification/orm/dynamoid/extension.rb', line 63 def update_all(conditions = {}) each do |document| document.update_attributes(conditions) end end |
#with_group ⇒ Dynamoid::Criteria::Chain
Includes group instance with query for notifications.
503 504 505 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 503 def with_group self end |
#with_group_members ⇒ Dynamoid::Criteria::Chain
Includes group member instances with query for notifications.
515 516 517 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 515 def with_group_members self end |
#with_group_owner ⇒ Dynamoid::Criteria::Chain
Includes group owner instances with query for notifications.
509 510 511 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 509 def with_group_owner self end |
#with_notifiable ⇒ Dynamoid::Criteria::Chain
Includes notifiable instance with query for notifications.
497 498 499 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 497 def with_notifiable self end |
#with_notifier ⇒ Dynamoid::Criteria::Chain
Includes notifier instance with query for notifications.
521 522 523 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 521 def with_notifier self end |
#with_target ⇒ Dynamoid::Criteria::Chain
Includes target instance with query for notifications or subscriptions.
491 492 493 |
# File 'lib/activity_notification/orm/dynamoid.rb', line 491 def with_target self end |