Module: ActivityNotification::Common
- Included in:
- Group, Notifiable, Notifier, ORM::ActiveRecord::Notification, ORM::Mongoid::Notification, Target
- Defined in:
- lib/activity_notification/common.rb
Overview
Common module included in target and notifiable model. Provides methods to resolve parameters from configured field or defined method. Also provides methods to convert into resource name or class name as string.
Instance Method Summary collapse
-
#printable_name ⇒ String
Convets to printable model name to show in view or email.
-
#printable_type ⇒ String
Convets to printable model type name to be humanized.
-
#resolve_value(thing, *args) ⇒ Object
Used to transform value from metadata to data which belongs model instance.
-
#to_class_name ⇒ String
Convets to class name.
-
#to_resource_name ⇒ String
Convets to singularized model name (resource name).
-
#to_resources_name ⇒ String
Convets to pluralized model name (resources name).
Instance Method Details
#printable_name ⇒ String
Convets to printable model name to show in view or email.
127 128 129 |
# File 'lib/activity_notification/common.rb', line 127 def printable_name "#{self.printable_type} (#{id})" end |
#printable_type ⇒ String
Is this the best to make readable?
Convets to printable model type name to be humanized.
121 122 123 |
# File 'lib/activity_notification/common.rb', line 121 def printable_type "#{self.class.name.demodulize.humanize}" end |
#resolve_value(thing, *args) ⇒ Object
Used to transform value from metadata to data which belongs model instance. Accepts Symbols, which it will send against this instance, Accepts Procs, which it will execute with this instance. Both Symbols and Procs will be passed arguments of this method. Also accepts Hash of these Symbols or Procs. If any other value will be passed, returns original value.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/activity_notification/common.rb', line 72 def resolve_value(thing, *args) case thing when Symbol symbol_method = method(thing) if symbol_method.arity > 0 symbol_method.call(*args) else symbol_method.call end when Proc if thing.arity > 1 thing.call(self, *args) elsif thing.arity > 0 thing.call(self) else thing.call end when Hash thing.dup.tap do |hash| hash.each do |key, value| hash[key] = resolve_value(value, *args) end end else thing end end |
#to_class_name ⇒ String
Convets to class name.
102 103 104 |
# File 'lib/activity_notification/common.rb', line 102 def to_class_name self.class.name end |
#to_resource_name ⇒ String
Convets to singularized model name (resource name).
108 109 110 |
# File 'lib/activity_notification/common.rb', line 108 def to_resource_name self.class.name.demodulize.singularize.underscore end |
#to_resources_name ⇒ String
Convets to pluralized model name (resources name).
114 115 116 |
# File 'lib/activity_notification/common.rb', line 114 def to_resources_name self.class.name.demodulize.pluralize.underscore end |