Class: Dupe::Database::Record

Inherits:
Hash
  • Object
show all
Defined in:
lib/superdupe/record.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

#to_xml_safe

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



14
15
16
17
18
19
20
21
# File 'lib/superdupe/record.rb', line 14

def method_missing(method_name, *args, &block)
  if attempting_to_assign(method_name)
    method_name = method_name.to_s[0..-2].to_sym
    self[method_name] = args.first
  else
    self[method_name.to_sym]
  end
end

Instance Attribute Details

#__model__Object

Returns the value of attribute __model__.



4
5
6
# File 'lib/superdupe/record.rb', line 4

def __model__
  @__model__
end

Instance Method Details

#demodulizeObject



42
43
44
45
46
47
48
# File 'lib/superdupe/record.rb', line 42

def demodulize
  if self.__model__.name.to_s.include?('::')
    self.__model__.name.to_s.demodulize
  else
    self.__model__.name.to_s
  end
end

#idObject



6
7
8
# File 'lib/superdupe/record.rb', line 6

def id
  self[:id]
end

#id=(value) ⇒ Object



10
11
12
# File 'lib/superdupe/record.rb', line 10

def id=(value)
  self[:id] = value
end

#record_inspectObject Also known as: inspect



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/superdupe/record.rb', line 23

def record_inspect
  # if a namespace is available, the titleize method destroy the scope operator
  if class_name = __model__ 
    __model__name.to_s.include?('::') ? "Duped::#{__model__.name.to_s}" : "Duped::#{__model__.name.to_s.titleize}"
  else
    self.class.to_s
  end
  
  "<##{class_name}".tap do |inspection|
    keys.each do |key|
      inspection << " #{key}=#{self[key].inspect}"
    end
    inspection << ">"
  end
end