Module: Shrine::Plugins::Column::AttacherMethods

Defined in:
lib/shrine/plugins/column.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#column_serializerObject (readonly)

Column serializer object.


28
29
30
# File 'lib/shrine/plugins/column.rb', line 28

def column_serializer
  @column_serializer
end

Instance Method Details

#column_dataObject

Returns attacher data as a serialized string (JSON by default).

attacher.column_data #=> '{"id":"...","storage":"...","metadata":{...}}'

48
49
50
# File 'lib/shrine/plugins/column.rb', line 48

def column_data
  serialize_column(data)
end

#initialize(column_serializer: shrine_class.opts[:column][:serializer], **options) ⇒ Object

Allows overriding the default column serializer.


31
32
33
34
# File 'lib/shrine/plugins/column.rb', line 31

def initialize(column_serializer: shrine_class.opts[:column][:serializer], **options)
  super(**options)
  @column_serializer = column_serializer
end

#load_column(data) ⇒ Object

Loads attachment from column data.

attacher.file #=> nil
attacher.load_column('{"id":"...","storage":"...","metadata":{...}}')
attacher.file #=> #<Shrine::UploadedFile>

41
42
43
# File 'lib/shrine/plugins/column.rb', line 41

def load_column(data)
  load_data(deserialize_column(data))
end