inspectar 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/.rvmrc +1 -0
- data/Gemfile +10 -0
- data/README.md +3 -0
- data/Rakefile +1 -0
- data/config.ru +4 -0
- data/inspectar.gemspec +26 -0
- data/lib/inspectar/version.rb +3 -0
- data/lib/inspectar.rb +44 -0
- metadata +119 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.2@inspectar --create
|
data/Gemfile
ADDED
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/config.ru
ADDED
data/inspectar.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "inspectar/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "inspectar"
|
7
|
+
s.version = Inspectar::VERSION
|
8
|
+
s.authors = ["Douglas Anderson"]
|
9
|
+
s.email = ["i.am.douglas.anderson@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{ Generate activerecord models for a MySQL database. }
|
12
|
+
s.description = %q{ Given an existing MySQL database, Inspectar will dynamically generate activerecord classes for each of the tables. }
|
13
|
+
|
14
|
+
s.rubyforge_project = "inspectar"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency "activesupport"
|
22
|
+
s.add_dependency "activerecord", "~> 3.0"
|
23
|
+
s.add_dependency "i18n"
|
24
|
+
|
25
|
+
s.add_development_dependency 'combustion', '~> 0.3.1'
|
26
|
+
end
|
data/lib/inspectar.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require "active_record"
|
2
|
+
require "inspectar/version"
|
3
|
+
|
4
|
+
module Inspectar
|
5
|
+
|
6
|
+
def self.attach(params)
|
7
|
+
ActiveRecord::Base.establish_connection params
|
8
|
+
connection_handle = ActiveRecord::Base.connection
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.tables
|
12
|
+
fetch.map{|datum| datum[:table_name]}
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.models
|
16
|
+
fetch.map{|datum| datum[:model_name]}
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.class_definition(table_data)
|
20
|
+
%Q{
|
21
|
+
class #{table_data[:model_name]} < ActiveRecord::Base
|
22
|
+
self.table_name = '#{table_data[:table_name]}'
|
23
|
+
self.inheritance_column = :_type_disabled
|
24
|
+
end
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.define_classes
|
29
|
+
eval(class_definitions)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.class_definitions
|
33
|
+
fetch.map do |datum|
|
34
|
+
class_definition(datum)
|
35
|
+
end.join("")
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.fetch
|
39
|
+
conn = ActiveRecord::Base.connection
|
40
|
+
tables = conn.execute("show tables").map { |r| r[0] }
|
41
|
+
tables.map{|table| {table_name: table, model_name: table.tableize.camelize.singularize}}
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inspectar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Douglas Anderson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activerecord
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: i18n
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: combustion
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.3.1
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.3.1
|
78
|
+
description: ! ' Given an existing MySQL database, Inspectar will dynamically generate
|
79
|
+
activerecord classes for each of the tables. '
|
80
|
+
email:
|
81
|
+
- i.am.douglas.anderson@gmail.com
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- .rvmrc
|
88
|
+
- Gemfile
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- config.ru
|
92
|
+
- inspectar.gemspec
|
93
|
+
- lib/inspectar.rb
|
94
|
+
- lib/inspectar/version.rb
|
95
|
+
homepage: ''
|
96
|
+
licenses: []
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project: inspectar
|
115
|
+
rubygems_version: 1.8.24
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: Generate activerecord models for a MySQL database.
|
119
|
+
test_files: []
|