Class: Terrazzo::Field::Hstore

Inherits:
Base
  • Object
show all
Defined in:
lib/terrazzo/field/hstore.rb

Constant Summary

Constants inherited from Base

Base::ABSTRACT_FIELD_CLASSES

Instance Attribute Summary

Attributes inherited from Base

#attribute, #data, #options, #page, #resource

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

associative?, default_options, eager_load?, #field_type, field_type, #form_input_attributes, #initialize, #required?, searchable?, #serializable_options, with_options

Constructor Details

This class inherits a constructor from Terrazzo::Field::Base

Class Method Details

.permitted_attribute(attr, _options = {}) ⇒ Object



9
10
11
# File 'lib/terrazzo/field/hstore.rb', line 9

def permitted_attribute(attr, _options = {})
  attr.to_sym
end

.sortable?Boolean

Returns:



5
6
7
# File 'lib/terrazzo/field/hstore.rb', line 5

def sortable?
  false
end

.transform_param(value) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/terrazzo/field/hstore.rb', line 13

def transform_param(value)
  return {} if value.blank?
  return value if value.is_a?(Hash)

  JSON.parse(value)
rescue JSON::ParserError
  {}
end

Instance Method Details

#serialize_value(mode) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/terrazzo/field/hstore.rb', line 23

def serialize_value(mode)
  hash = data || {}

  case mode
  when :index
    truncate = options[:truncate] || 80
    preview = hash.map { |k, v| "#{k}: #{v}" }.join(", ")
    preview.length > truncate ? "#{preview[0...truncate]}..." : preview
  else
    hash
  end
end