database_introspection 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd6b1e340f5f576df0fdc03f994f376069ace956
|
4
|
+
data.tar.gz: 0401ddeac82d36e2a54c214cea8cf9c303db3322
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7452dd3c478d085d73c1ad3245fd75e5440814be8c8b0d464e182ee63afadebbe31626ed3e3cd080c74c5fd12a74d4d3a189abf4490ff28218c991b622e0938f
|
7
|
+
data.tar.gz: 4292876722bf17e645aaefc7fafd33021a7ecc6ceb239248a1449b78c8f0b504ea69200c274663e3a3baabd66f6aae1dc92060abdea8bf7972e8329f4889233b
|
data/README.md
CHANGED
@@ -90,7 +90,7 @@ The classes generated will actually have some behaviour added by extending the m
|
|
90
90
|
|
91
91
|
Provided you follow the standard rails rules for ids, for example:
|
92
92
|
|
93
|
-
if `user_defined_table1` contains `user_defined_table2_id` (
|
93
|
+
if `user_defined_table1` contains `user_defined_table2_id` or simply `table2_id` (if `table2` is part of the same domain `user_defined`), the introspection process will understand there is a relationship between the tables and create the ActiveRecord associations accordingly adding all the standard helper methods to the generated classes !
|
94
94
|
|
95
95
|
## To do
|
96
96
|
|
@@ -1,7 +1,11 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
# This class is in charge to analyse the relationships between the tables of the domain.
|
4
|
+
# It will then add association methods to the classes.
|
2
5
|
class DynamicModel::RelationsAnalyser
|
3
6
|
KEY_IDENTIFIER = /_id$/
|
4
7
|
|
8
|
+
#
|
5
9
|
attr_reader :alterations
|
6
10
|
|
7
11
|
def initialize(klasses)
|
@@ -40,7 +44,10 @@ class DynamicModel::RelationsAnalyser
|
|
40
44
|
|
41
45
|
def introspect_belongs_to
|
42
46
|
puts "Belongs_to analysis started."
|
47
|
+
# scoped_table_names_hash is a hash with keys made of table names (both scoped and unscoped)
|
48
|
+
# and the values are the associated classes.
|
43
49
|
scoped_table_names_hash = Hash[@domain.scoped_table_names.zip @domain.model_classes]
|
50
|
+
scoped_table_names_hash.merge! Hash[@domain.table_names.zip @domain.model_classes]
|
44
51
|
@klasses.each do |klass|
|
45
52
|
@alterations[klass] ||= {}
|
46
53
|
# Find attributes ending by "_id"
|
@@ -138,7 +145,7 @@ class DynamicModel::RelationsAnalyser
|
|
138
145
|
|
139
146
|
|
140
147
|
def add_belongs_to_behaviour(model, description)
|
141
|
-
field_name = description[:
|
148
|
+
field_name = description[:class].list_name.singularize
|
142
149
|
model.belongs_to field_name, :foreign_key => description[:key], :class_name => description[:class].name
|
143
150
|
puts " - belongs_to :#{field_name}, :foreign_key => #{description[:key]}, :class_name => #{description[:class].name}"
|
144
151
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: database_introspection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- L.Briais
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|