Module: RgssDb::JsonableConstructor

Overview

Jsonable constructor module

Instance Method Summary collapse

Instance Method Details

#json_create(hash, *args) ⇒ Object

JSON deserializer

Parameters:

  • hash (Hash)
  • args (Array)

Returns:

  • Class instance



31
32
33
34
35
36
37
38
# File 'lib/rgss_db/model/mixins/jsonable_constructor.rb', line 31

def json_create(hash, *args)
  instance = json_new(*args)
  hash.each_pair do |key, value|
    ivar = "@#{key}".to_sym
    instance.instance_variable_set(ivar, value) if instance.instance_variables.include?(ivar)
  end
  instance
end

#json_new(*args) ⇒ Object

JSON constructor

This constructor is used to create a default instance

Note: Needs to be overriden in case class constructor needs arguments

Parameters:

  • args (Array)

Returns:

  • Class instance



19
20
21
# File 'lib/rgss_db/model/mixins/jsonable_constructor.rb', line 19

def json_new(*args)
  new(*args)
end