inspectar 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,3 +1,19 @@
1
1
 
2
-
3
-
2
+ Getting started
3
+
4
+ require 'inspectar'
5
+
6
+ Connect to a database
7
+
8
+ Inspectar.attach adapter: 'mysql2', host: 'localhost', database: 'database', username: 'username', password: 'password'
9
+
10
+ Generate code defining activerecord models
11
+
12
+ puts Inspectar.class_definitions
13
+
14
+ Define models to interact with your database quickly
15
+
16
+ # given a table called invoices
17
+
18
+ Inspectar.define_classes
19
+ Inspectar::Invoice.all
@@ -1,3 +1,3 @@
1
1
  module Inspectar
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/inspectar.rb CHANGED
@@ -1,11 +1,15 @@
1
1
  require "active_record"
2
2
  require "inspectar/version"
3
3
 
4
+ class Connectar < ActiveRecord::Base
5
+
6
+ end
7
+
4
8
  module Inspectar
5
9
 
6
10
  def self.attach(params)
7
- ActiveRecord::Base.establish_connection params
8
- connection_handle = ActiveRecord::Base.connection
11
+ Connectar.establish_connection params
12
+ connection_handle = Connectar.connection
9
13
  end
10
14
 
11
15
  def self.tables
@@ -18,7 +22,7 @@ module Inspectar
18
22
 
19
23
  def self.class_definition(table_data)
20
24
  %Q{
21
- class #{table_data[:model_name]} < ActiveRecord::Base
25
+ class #{table_data[:model_name]} < Connectar
22
26
  self.table_name = '#{table_data[:table_name]}'
23
27
  self.inheritance_column = :_type_disabled
24
28
  end
@@ -36,7 +40,7 @@ end
36
40
  end
37
41
 
38
42
  def self.fetch
39
- conn = ActiveRecord::Base.connection
43
+ conn = Connectar.connection
40
44
  tables = conn.execute("show tables").map { |r| r[0] }
41
45
  tables.map{|table| {table_name: table, model_name: table.tableize.camelize.singularize}}
42
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inspectar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-18 00:00:00.000000000 Z
12
+ date: 2013-01-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport