Class: Jsonizer

Inherits:
Module
  • Object
show all
Defined in:
lib/jsonizer/jsonizer.rb,
lib/jsonizer/version.rb

Overview

Defines all methods neccessary for JSON encoding through JSON[], JSON.dump and #to_json

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Constructor Details

#initialize(*attributes) ⇒ undefined

Initialize a Jsonizer to use the given attributes

They will be used to define as_json, to_json and self.json_create

Parameters:

  • attributes (Array<Symbol>)


12
13
14
15
16
# File 'lib/jsonizer/jsonizer.rb', line 12

def initialize *attributes
  @attributes = attributes
  define_as_json
  define_to_json
end

Instance Method Details

#included(mod) ⇒ undefined

Include the equalizer instance into mod

Parameters:

  • mod (Module)

Returns:

  • (undefined)

Raises:

  • (ArgumentError)


22
23
24
25
# File 'lib/jsonizer/jsonizer.rb', line 22

def included mod
  raise ArgumentError, "Cannot jsonize anonymous classes. They cannot be restored." unless mod.name
  mod.extend(class_methods_module)
end