Class: Gumdrop::Data::SqliteLiveData
- Inherits:
-
Object
- Object
- Gumdrop::Data::SqliteLiveData
- Defined in:
- lib/gumdrop/data_providers/sqlite.rb
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
Instance Method Summary collapse
-
#initialize(db, provider) ⇒ SqliteLiveData
constructor
A new instance of SqliteLiveData.
- #load_data_for(hash, table_name) ⇒ Object
- #method_missing(key, *args) ⇒ Object
Constructor Details
#initialize(db, provider) ⇒ SqliteLiveData
Returns a new instance of SqliteLiveData.
23 24 25 26 27 |
# File 'lib/gumdrop/data_providers/sqlite.rb', line 23 def initialize(db, provider) @db= db @provider= provider @data_hash= Hash.new &method(:load_data_for) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key, *args) ⇒ Object
38 39 40 |
# File 'lib/gumdrop/data_providers/sqlite.rb', line 38 def method_missing(key, *args) @data_hash[key] end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
21 22 23 |
# File 'lib/gumdrop/data_providers/sqlite.rb', line 21 def db @db end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
21 22 23 |
# File 'lib/gumdrop/data_providers/sqlite.rb', line 21 def provider @provider end |
Instance Method Details
#load_data_for(hash, table_name) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/gumdrop/data_providers/sqlite.rb', line 29 def load_data_for(hash, table_name) data=[] db.results_as_hash = true db.execute( "select * from #{ table_name.to_s };" ) do |row| data << row.reject {|key,col| key.is_a? Fixnum } end hash[table_name]= provider.supply_data data end |