Class: Prmd::SchemaHash

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/prmd/core/schema_hash.rb

Overview

Specialized Hash for handling loaded Schema data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, options = {}) ⇒ SchemaHash

Returns a new instance of SchemaHash.

Parameters:

  • data (Hash)
  • options (Hash<Symbol, Object>) (defaults to: {})


21
22
23
24
# File 'lib/prmd/core/schema_hash.rb', line 21

def initialize(data, options = {})
  @data = data
  @filename = options.fetch(:filename, '')
end

Instance Attribute Details

#filenameString (readonly)

Returns:

  • (String)


12
13
14
# File 'lib/prmd/core/schema_hash.rb', line 12

def filename
  @filename
end

Instance Method Details

#fetch(key) ⇒ self

Parameters:

  • key (String)

Returns:

  • (self)


36
37
38
# File 'lib/prmd/core/schema_hash.rb', line 36

def fetch(key)
  @data.fetch(key) { abort "Missing key #{key} in #{filename}" }
end

#initialize_copy(other) ⇒ self

Parameters:

Returns:

  • (self)


28
29
30
31
32
# File 'lib/prmd/core/schema_hash.rb', line 28

def initialize_copy(other)
  super
  @data = other.data.dup
  @filename = other.filename.dup
end

#to_hHash

Returns:

  • (Hash)


41
42
43
# File 'lib/prmd/core/schema_hash.rb', line 41

def to_h
  @data.dup
end