Module: GlobalRegistry::Bindings::Model::Entity
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/global_registry_bindings/model/entity.rb
Instance Method Summary collapse
- #entity_attributes_to_push ⇒ Object
- #entity_columns_to_push ⇒ Object
- #value_for_global_registry(name, type) ⇒ Object
Instance Method Details
#entity_attributes_to_push ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/global_registry_bindings/model/entity.rb', line 9 def entity_attributes_to_push entity_attributes = entity_columns_to_push.map do |name, type| value_for_global_registry(name, type) end.compact.to_h entity_attributes[:client_integration_id] = id unless global_registry_entity.exclude .include?(:client_integration_id) if respond_to?(:updated_at) && updated_at.present? entity_attributes[:client_updated_at] = updated_at.to_s(:db) end if global_registry_entity.parent_is_self? entity_attributes[:parent_id] = global_registry_entity.parent_id_value end entity_attributes end |
#entity_columns_to_push ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/global_registry_bindings/model/entity.rb', line 40 def entity_columns_to_push @columns_to_push ||= if global_registry_entity.include_all_columns? self .class .columns .collect do |c| {c.name.underscore.to_sym => normalize_entity_column_type(c.type, c.name)} end # rubocop:disable Style/MultilineBlockChain .reduce(&:merge) .except(*global_registry_entity.exclude) .merge(global_registry_entity.fields) else global_registry_entity.fields end end |
#value_for_global_registry(name, type) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/global_registry_bindings/model/entity.rb', line 24 def value_for_global_registry(name, type) value = send(name) return [name, value] if value.nil? value = case type when :datetime, :date value.to_s(:db) when :boolean value ? "true" : "false" else value.to_s.strip end [name, value] rescue ::NoMethodError nil end |