module Ciri::RLP::Serializable::ClassMethods

Public Instance Methods

default_data(data = nil) click to toggle source
# File lib/ciri/rlp/serializable.rb, line 193
def default_data(data = nil)
  @default_data ||= data
end
rlp_decode(input) click to toggle source

Decode object from input

# File lib/ciri/rlp/serializable.rb, line 172
def rlp_decode(input)
  data = schema.rlp_decode(input)
  self.new(data)
end
rlp_encode(item, skip_keys: nil, white_list_keys: nil) click to toggle source

Encode object to rlp encoding string

# File lib/ciri/rlp/serializable.rb, line 178
def rlp_encode(item, skip_keys: nil, white_list_keys: nil)
  schema.rlp_encode(item.serializable_attributes, skip_keys: skip_keys, white_list_keys: white_list_keys)
end
schema(data_schema = nil) click to toggle source
# File lib/ciri/rlp/serializable.rb, line 182
def schema(data_schema = nil)
  if data_schema
    @data_schema = Schema.new(data_schema).tap do |schema|
      # define attributes methods
      define_attributes(schema)
    end
  else
    @data_schema ||= superclass.schema
  end
end

Private Instance Methods

define_attributes(schema) click to toggle source
# File lib/ciri/rlp/serializable.rb, line 199
        def define_attributes(schema)
          schema.keys.each do |attribute|
            module_eval <<-ATTR_METHODS
            def #{attribute}
              serializable_attributes[:"#{attribute}"]
            end

            def #{attribute}=(value)
              serializable_attributes[:"#{attribute}"] = value 
            end
            ATTR_METHODS
          end
        end