Class: Discoverer::Model
- Inherits:
-
Object
- Object
- Discoverer::Model
- Defined in:
- lib/discoverer/model.rb
Overview
Instance Attribute Summary collapse
-
#_id ⇒ Object
The id of the object as persisted.
Class Method Summary collapse
-
.downcase ⇒ String
The name of the clasee, downcased and made into a String.
-
.table_name ⇒ Symbol
Static methods.
Instance Method Summary collapse
-
#attributes! ⇒ Hash
The attributes which are not set to nil.
-
#initialize(*args) ⇒ Model
constructor
Accepts an attributes Hash as argument.
Methods included from Writer
Methods included from Reader
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
#_id ⇒ Object
Returns the id of the object as persisted.
10 |
# File 'lib/discoverer/model.rb', line 10 attribute :_id |
Class Method Details
.downcase ⇒ String
Returns 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_name ⇒ Symbol
Static methods
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.
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 |