# File lib/table_sync/publishing/base_publisher.rb, line 24 def primary_keys Array(object_class.primary_key).map(&:to_sym) end
class TableSync::Publishing::BasePublisher
Constants
- BASE_SAFE_JSON_TYPES
- NOT_MAPPED
Attributes
object_class[RW]
Private Instance Methods
attributes_for_sync_defined?()
click to toggle source
# File lib/table_sync/publishing/base_publisher.rb, line 28 def attributes_for_sync_defined? object_class.method_defined?(:attributes_for_sync) end
confirm?()
click to toggle source
# File lib/table_sync/publishing/base_publisher.rb, line 40 def confirm? @confirm end
current_time()
click to toggle source
# File lib/table_sync/publishing/base_publisher.rb, line 20 def current_time Time.current end
filter_safe_for_serialization(object)
click to toggle source
# File lib/table_sync/publishing/base_publisher.rb, line 49 def filter_safe_for_serialization(object) case object when Array object.each_with_object([]) do |value, memo| value = filter_safe_for_serialization(value) memo << value if object_mapped?(value) end when Hash object.each_with_object({}) do |(key, value), memo| key = filter_safe_for_serialization(key) value = filter_safe_hash_values(value) memo[key] = value if object_mapped?(key) && object_mapped?(value) end when Float::INFINITY NOT_MAPPED when *BASE_SAFE_JSON_TYPES object else # rubocop:disable Lint/DuplicateBranch NOT_MAPPED end end
filter_safe_hash_values(value)
click to toggle source
# File lib/table_sync/publishing/base_publisher.rb, line 71 def filter_safe_hash_values(value) case value when Symbol value.to_s else filter_safe_for_serialization(value) end end
job_class()
click to toggle source
# File lib/table_sync/publishing/base_publisher.rb, line 84 def job_class job_callable ? job_callable.call : raise(job_callable_error_message) end
metadata()
click to toggle source
# File lib/table_sync/publishing/base_publisher.rb, line 36 def metadata TableSync.routing_metadata_callable&.call(object_class.name, attrs_for_metadata) end
object_mapped?(object)
click to toggle source
# File lib/table_sync/publishing/base_publisher.rb, line 80 def object_mapped?(object) object != NOT_MAPPED end
params()
click to toggle source
# File lib/table_sync/publishing/base_publisher.rb, line 96 def params params = { event: :table_sync, data: publishing_data, confirm_select: confirm?, routing_key: routing_key, realtime: true, headers: metadata, } params[:exchange_name] = TableSync.exchange_name if TableSync.exchange_name params end
primary_keys()
click to toggle source
publishing_data()
click to toggle source
# File lib/table_sync/publishing/base_publisher.rb, line 88 def publishing_data { model: object_class.try(:table_sync_model_name) || object_class.name, attributes: attributes_for_sync, version: current_time.to_f, } end
resolve_routing_key()
click to toggle source
# File lib/table_sync/publishing/base_publisher.rb, line 32 def resolve_routing_key routing_key_callable.call(object_class.name, attrs_for_routing_key) end
routing_key_callable()
click to toggle source
# File lib/table_sync/publishing/base_publisher.rb, line 44 def routing_key_callable return TableSync.routing_key_callable if TableSync.routing_key_callable raise "Can't publish, set TableSync.routing_key_callable" end