Skip to content

Ruby gem to persist object and retrieve them.

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

hedselu/dumb_serializer

Repository files navigation

dumbdump

This gem is mongoDB mapper that allows you to save, destroy and load any custom object with deep nested core/custom attributes.

At actual version the only restriction is, that objects you want to save/load, cannot have initializers with arguments-passing or they provide optional params values if nothing is passed(nil, hash, etc.).

Below are few examples of using gem.

class CoolClass
  attr_accessor :cool_attr
  include DumbSerializer

  def initialize
    @cool_attr = NestedClass.new
  end
end

class NestedClass
  attr_accessor :nested_attr

  def initialize
    @nested_attr = 9
  end
end

serialization

You would usually use document id to find it, but in any case, insertion result is being returned from #serialize.

object = CoolClass.new
id = object.dump.inserted_id.to_s #=> '562f8ab72d27c231fb000003'

loading

CoolClass.find(id) #=> <CoolClass:0x000000016ad438 @cool_attr = <NestedClass:0x000000016ad439
                  # @nested_attr = 9>,  @config_attr={:cool_attr=>0}>
CoolClass.all     #=> array of saved objects

destroying

.drop method drops collection belonging to class.

CoolClass.remove(id)
CoolClass.drop

config

You can configure database connection with .db_config= by passing options like database, host, port. Beware of configuration. If you set it up for one class it will influence setup of other classes that include DumpSerializer.

# These are defaults
CoolClass.db_config #=> { database: 'dumb_serializer', host: '127.0.0.1', port: '27017'}
CoolClass.db_config = { database: 'custom' }
CoolClass.db_config #=> { database: 'custom', host: '127.0.0.1', port: '27017'}              

Ruby beauty

About

Ruby gem to persist object and retrieve them.

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages