Class: Super::Schema::Fields

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/super/schema.rb

Overview

This class can be thought of as a Hash, where the keys usually refer to the model's column name and the value refers to the column type. Note though that this isn't always the case—different SchemaTypes can do whatever makes sense in their context

Instance Method Summary collapse

Constructor Details

#initializeFields

Returns a new instance of Fields.



17
18
19
# File 'lib/super/schema.rb', line 17

def initialize
  @backing = {}
end

Instance Method Details

#[](key) ⇒ Object



21
22
23
# File 'lib/super/schema.rb', line 21

def [](key)
  @backing[key]
end

#[]=(key, value) ⇒ Object



25
26
27
# File 'lib/super/schema.rb', line 25

def []=(key, value)
  @backing[key] = value
end

#each(&block) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/super/schema.rb', line 37

def each(&block)
  if block_given?
    return @backing.each(&block)
  end

  enum_for(:each)
end

#keysObject



29
30
31
# File 'lib/super/schema.rb', line 29

def keys
  @backing.keys
end

#nestedObject



53
54
55
56
57
58
59
60
61
62
# File 'lib/super/schema.rb', line 53

def nested
  outside = @backing
  inside = {}
  @backing = inside
  yield
  return inside
ensure
  @backing = outside
  inside
end

#replace(other) ⇒ Object



45
46
47
# File 'lib/super/schema.rb', line 45

def replace(other)
  @backing = other
end

#to_hObject



49
50
51
# File 'lib/super/schema.rb', line 49

def to_h
  @backing
end

#valuesObject



33
34
35
# File 'lib/super/schema.rb', line 33

def values
  @backing.values
end