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: cb2ff4ce8131add8f4e7cfc4830240d8ba45df98
4
- data.tar.gz: 524b268bdb6f8f11bd6ef6798c00dbf5c5e34bff
3
+ metadata.gz: fd6b1e340f5f576df0fdc03f994f376069ace956
4
+ data.tar.gz: 0401ddeac82d36e2a54c214cea8cf9c303db3322
5
5
  SHA512:
6
- metadata.gz: ac56205a6698c903436d4d5935861abad37fce34a7fc0e3652b5f33def754270fb71af500e4dff03a77d9a5ac93efd6456e29787ca0036302cfc83f5d2fc397c
7
- data.tar.gz: 3f8fd05f31a29d3cecf0b72d29427c1d5c9121cb42736a96cde92a49bff786f62026ac59e1e6c893ca619dd28a989503bc0050be6026c5c040c703dc059edf70
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` (not yet implemented) or `table2_id`, the introspector 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 !
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
 
@@ -9,5 +9,6 @@ require 'database_introspection/dynamic_model/migration'
9
9
 
10
10
 
11
11
  module DatabaseIntrospection
12
- # Your code goes here...
12
+ # There is nothing to see there.
13
+ # Everything is under dynamic_model
13
14
  end
@@ -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[:key].gsub KEY_IDENTIFIER, ''
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
@@ -1,3 +1,3 @@
1
1
  module DatabaseIntrospection
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  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.9
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-17 00:00:00.000000000 Z
11
+ date: 2013-05-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler