Module: Inspectar
- Defined in:
- lib/inspectar.rb,
lib/inspectar/version.rb
Defined Under Namespace
Classes: Connectar
Constant Summary collapse
- VERSION =
"0.0.8"
Class Method Summary collapse
- .attach(params) ⇒ Object
- .class_definition(table_data) ⇒ Object
- .class_definitions ⇒ Object
- .define_classes ⇒ Object
- .fetch ⇒ Object
- .models ⇒ Object
- .tables ⇒ Object
Class Method Details
.attach(params) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/inspectar.rb', line 8 def self.attach(params) ActiveRecord::Base.configurations["inspectar"] = params Connectar.establish_connection params connection_handle = Connectar.connection define_classes end |
.class_definition(table_data) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/inspectar.rb', line 23 def self.class_definition(table_data) %Q{ class #{table_data[:model_name]} < ActiveRecord::Base establish_connection "inspectar" self.table_name = '#{table_data[:table_name]}' self.inheritance_column = :_type_disabled def method_missing(method_id, *args) getters = {} setters = {} self.class.column_names.each do |v| getters[v] = v getters[v.downcase] = v end self.class.column_names.each do |v| setters[v+"="] = v setters[v.downcase+"="] = v + "=" end if getters.has_key?(method_id.to_s) send getters[method_id.to_s].to_sym elsif setters.has_key?(method_id.to_s) send setters[method_id.to_s].to_sym, *args else super end end end } end |
.class_definitions ⇒ Object
60 61 62 63 64 |
# File 'lib/inspectar.rb', line 60 def self.class_definitions fetch.map do |datum| class_definition(datum) end.join("") end |
.define_classes ⇒ Object
56 57 58 |
# File 'lib/inspectar.rb', line 56 def self.define_classes eval(class_definitions) end |
.fetch ⇒ Object
66 67 68 |
# File 'lib/inspectar.rb', line 66 def self.fetch Connectar.connection.tables.map{|table| {table_name: table, model_name: table.tableize.camelize.singularize}} end |
.models ⇒ Object
19 20 21 |
# File 'lib/inspectar.rb', line 19 def self.models fetch.map{|datum| datum[:model_name]} end |
.tables ⇒ Object
15 16 17 |
# File 'lib/inspectar.rb', line 15 def self.tables fetch.map{|datum| datum[:table_name]} end |