0.0
No commit activity in last 3 years
No release in over 3 years
Support for object persistence.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 0
 Project Readme

ObjectField

Gem Version Build Status Coverage Status Code Climate Dependency Status

Support for object persistence.
Save the object to data store via instance method.

Installation

Add this line to your application's Gemfile:

gem 'object_field'

And then execute:

$ bundle

Or install it yourself as:

$ gem install object_field

Usage

Include ObjectField::Jsonizer or ObjectField::Serializer.

Jsonizer

.#jsonize defines accessor of JSON field.

class InJsonValue
  include ObjectField::Jsonizer
  attr_accessor :field1_json, :field2, :field3_json
  jsonize :field1_json, :field2
  jsonize :field3_json, as: :attributes
end

Setter is save the value to JSON.
Getter returns parsed value.
Name of accessor can be specified with as option.
It is set field1, field2_as_json if not specified.

object = InJsonValue.new
object.field1 = [1, 2, 3]
p object.field1_json # => "[1,2,3]"
object.field1.each {|i| p i}

Serializer

.#serialize defines accessor of marshal data field.
Like marshal option of redis-object.

class InSerializedValue
  include ObjectField::Serializer
  attr_accessor :field_data
  serialize :field_data
end

Setter is save the serialized value.
Can not be saved, Proc object and anonymous class. (To raise TypeError)
Getter returns deserialized value.
Name of accessor can be specified with as option.
It is set field if not specified.

class SerializedObject; end
object = InSerializedValue.new
object.field = SerializedObject.new
p object.field.class # => SerializedObject

Contributing

  1. Fork it ( https://github.com/i2bskn/object_field/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request