Class: Discoverer::Model

Inherits:
Object
  • Object
show all
Includes:
Reader, Writer
Defined in:
lib/discoverer/model.rb

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Writer

#to

Methods included from Reader

#from

Constructor Details

#initialize(*args) ⇒ Model

Accepts an attributes Hash as argument. Loads from the default datasource unless the Hash has an _id setted.



16
17
18
19
20
# File 'lib/discoverer/model.rb', line 16

def initialize *args
  super *args
  #binding.pry
  from.default if @_id.nil? and not attributes!.empty?
end

Instance Attribute Details

#_idObject

Returns the id of the object as persisted.

Returns:

  • (Object)

    the id of the object as persisted



10
# File 'lib/discoverer/model.rb', line 10

attribute :_id

Class Method Details

.downcaseString

Returns the name of the clasee, downcased and made into a String.

Returns:

  • (String)

    the name of the clasee, downcased and made into a String



38
39
40
# File 'lib/discoverer/model.rb', line 38

def self.downcase 
  "#{self}".split("::").last.downcase
end

.table_nameSymbol

Static methods

Returns:

  • (Symbol)

    the name of the class, pluralized, downcased and made into a Symbol



33
34
35
# File 'lib/discoverer/model.rb', line 33

def self.table_name
  "#{self.downcase}s".to_sym
end

Instance Method Details

#attributes!Hash

Returns The attributes which are not set to nil.

Returns:

  • (Hash)

    The attributes which are not set to nil



23
24
25
26
27
28
29
# File 'lib/discoverer/model.rb', line 23

def attributes!
  the_attributes = {}
  attributes.each do |key, value|
    the_attributes[key] = value unless value.nil?
  end
  return the_attributes
end