class EnrichmentDb::DatumModel
Attributes
attrs[RW]
to_hash[RW]
Public Class Methods
all(table_name, schema_name = nil)
click to toggle source
# File lib/enrichment_db.rb, line 53 def self.all(table_name, schema_name = nil) schema_name = schema_name || self::DATABASE_NAME puts "Finding all objects from #{table_name}" query = "SELECT * FROM #{schema_name}.#{table_name}" result = EnrichmentDb.request(schema_name, query).collect do |record| record end format_result(result) end
by_id(table_name, id)
click to toggle source
# File lib/enrichment_db.rb, line 28 def self.by_id(table_name, id) schema_name = self::DATABASE_NAME uid_name = self::UID_NAME puts "Finding object from #{table_name} with #{uid_name} = '#{id}'." query = "SELECT * FROM #{schema_name}.#{table_name} where #{uid_name} = $1" values = [id] result = EnrichmentDb.request(schema_name, query, values).collect do |record| record end format_result(result) end
by_lambda(schema_name, table_name, condition)
click to toggle source
# File lib/enrichment_db.rb, line 42 def self.by_lambda(schema_name, table_name, condition) puts "Finding object from #{table_name} with condition #{condition}." query = "SELECT * FROM #{schema_name}.#{table_name} where #{condition}" result = EnrichmentDb.request(schema_name, query).collect do |record| record end format_result(result) end
format_result(result)
click to toggle source
# File lib/enrichment_db.rb, line 65 def self.format_result(result) if result.size > 0 puts "Found #{result.size} object/s" result else puts "Nothing found" end end
lazy_attr_reader(*attrs)
click to toggle source
Define methods that retrieve the value from an initialized instance variable Hash, using the attribute as a key
@overload self.lazy_attr_reader(attr)
@param attr [Symbol]
@overload self.lazy_attr_reader(attrs)
@param attrs [Array<Symbol>]
# File lib/enrichment_db.rb, line 18 def self.lazy_attr_reader(*attrs) attrs.each do |attribute| class_eval do define_method attribute do @attrs[attribute.to_s] || @attrs[attribute.to_sym] end end end end
new(attrs={})
click to toggle source
Initializes a new Base object
@param attrs [Hash] @return [DatumModel]
# File lib/enrichment_db.rb, line 78 def initialize(attrs={}) @attrs = attrs.dup end