Module: Hashing

Defined in:
lib/hashing.rb,
lib/hashing/ivar.rb,
lib/hashing/hasher.rb,
lib/hashing/macros.rb,
lib/hashing/version.rb,
lib/hashing/ivar_collection.rb,
lib/hashing/unconfigured_ivar_error.rb

Overview

Inject the public api into the host class, and it’s instances. By “public api” we understand the class methods

And the instance method:

When ‘Hashing` is included, the host class will gain the `.from_hash({})` method and the `#to_h` instance method. Another method that will be added is the private class method `.hasherize` will be added so you can indicate what ivars do you want in your sarialized objects.

Examples:

including Hashing

require 'hashing'

class File
  include Hashing
  hasherize :path, :commit

  def initialize(path, commit)
    @path, @commit = path, commit
  end
end

Since:

  • 0.0.1

Defined Under Namespace

Modules: Macros Classes: Hasher, Ivar, IvarCollection, UnconfiguredIvarError

Constant Summary collapse

VERSION =

Since:

  • 0.0.1

"0.1.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(client_class) ⇒ Object

Since:

  • 0.0.1



34
35
36
# File 'lib/hashing.rb', line 34

def self.included(client_class)
  client_class.extend Macros
end

Instance Method Details

#to_hObject

The ‘Hash` returned by `#to_h` will be formed by keys based on the ivars names passed to `hasherize` method.

Examples:

File hahserized (which include ‘Hashing`)


file = File.new 'README.md', 'cfe9aacbc02528b'
file.to_h
# => { path: 'README.md', commit: 'cfe9aacbc02528b' }

Since:

  • 0.0.1



46
47
48
# File 'lib/hashing.rb', line 46

def to_h
  self.class.__hasher.to_h self
end