Class: Mysql::Result::RowHash

Inherits:
Object
  • Object
show all
Defined in:
lib/slim_attributes.rb,
lib/slim_attributes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



52
53
54
# File 'lib/slim_attributes.rb', line 52

def method_missing(name, *args, &block)
  to_hash.send(name, *args, &block)
end

Instance Attribute Details

#real_hashObject

Returns the value of attribute real_hash.



12
13
14
# File 'lib/slim_attributes.rb', line 12

def real_hash
  @real_hash
end

Instance Method Details

#freezeObject



47
48
49
50
# File 'lib/slim_attributes.rb', line 47

def freeze
  to_hash.freeze
  regular_freeze
end

#keysObject



24
25
26
# File 'lib/slim_attributes.rb', line 24

def keys
  @real_hash ? @real_hash.keys : @field_indexes.keys
end

#marshal_dumpObject



14
15
16
# File 'lib/slim_attributes.rb', line 14

def marshal_dump
  to_hash
end

#marshal_load(hash) ⇒ Object



18
19
20
# File 'lib/slim_attributes.rb', line 18

def marshal_load(hash)
  @real_hash = hash
end

#regular_freezeObject

Load up all the attributes before a freeze



45
# File 'lib/slim_attributes.rb', line 45

alias_method :regular_freeze, :freeze

#to_aObject



40
41
42
# File 'lib/slim_attributes.rb', line 40

def to_a
  to_hash.to_a
end

#to_hashObject

If you want to do anything other than [], []=, dup, keys and has_key? then we’ll handle that by doing the operation on a real ruby hash. This should be the exception though, and the efficiencies of using slim-attributes are lost when this happens.



32
33
34
35
36
37
38
# File 'lib/slim_attributes.rb', line 32

def to_hash
  return @real_hash unless @field_indexes
  @real_hash ||= {}
  @field_indexes.each_pair {|name, index| @real_hash[name] = fetch_by_index(index)}
  @field_indexes = nil
  @real_hash
end