Class: Webhookdb::Service::Entities::Base
- Inherits:
-
Grape::Entity
- Object
- Grape::Entity
- Webhookdb::Service::Entities::Base
- Extended by:
- MethodUtilities
- Defined in:
- lib/webhookdb/service/entities.rb
Direct Known Subclasses
API::BaseEntity, AdminAPI::Entities::Base, CurrentCustomer, Image
Class Method Summary collapse
- .delegate_to(*names, safe: false, safe_with_default: nil) ⇒ Object
- .timezone(*lookup_path, field: nil) ⇒ Object
Instance Method Summary collapse
-
#object_type ⇒ Object
Override this on entities that are addressable on their own.
Methods included from MethodUtilities
attr_predicate, attr_predicate_accessor, singleton_attr_accessor, singleton_attr_reader, singleton_attr_writer, singleton_method_alias, singleton_predicate_accessor, singleton_predicate_reader
Class Method Details
.delegate_to(*names, safe: false, safe_with_default: nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/webhookdb/service/entities.rb', line 28 def self.delegate_to(*names, safe: false, safe_with_default: nil) return lambda do |instance| names.reduce(instance) do |memo, name| memo.send(name) rescue NoMethodError => e raise e unless safe || safe_with_default return safe_with_default end end end |
.timezone(*lookup_path, field: nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/webhookdb/service/entities.rb', line 39 def self.timezone(*lookup_path, field: nil) return lambda do |instance, opts| field ||= opts[:attr_path].last tz = lookup_path.reduce(instance) do |memo, name| memo.send(name) rescue NoMethodError nil end t = instance.send(field) if tz.blank? t else tz = tz.timezone if tz.respond_to?(:timezone) tz = tz.time_zone if tz.respond_to?(:time_zone) t.in_time_zone(tz).iso8601 end end end |
Instance Method Details
#object_type ⇒ Object
Override this on entities that are addressable on their own
24 25 26 |
# File 'lib/webhookdb/service/entities.rb', line 24 def object_type return nil end |