like_im_five 1.0.2 → 1.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
  SHA256:
3
- metadata.gz: 2ab66e2bdd265eb33d322213dd7d8e5ef400a457b3d835061d843cd68c4680be
4
- data.tar.gz: f4ca8559a1d5fcbe38b23e8a15dc2e1525a2d056f92f5b6020f79077847ccbdb
3
+ metadata.gz: 3d893513f8b9b91d64442372148cfb0cf59257b867527c17b61db544e44aa385
4
+ data.tar.gz: 3b015d58ad82f7d5dcadc6267e2a84404932a9d94871746ed937fe05886b2146
5
5
  SHA512:
6
- metadata.gz: 65103e508ac46ba5aacb228829742b4f2c88809dd297a65bb1c205922cf6a1a759c47417def97a9ecdb2f079bb0910b63bb07fcd5555c583775b357f32013339
7
- data.tar.gz: 7313c03645f5b359de041e6f64001a4283c9ad8fed6b342458662351567f3a7ca0106bedf1ffabd3e46fc4ecc7e32620bc212983b442f085cdcb057d9e06d67f
6
+ metadata.gz: 92a3f3ca4a75412b0f224af0483770893e85a09243aa4af8171e1662b24df14407870920a079a7925b921978090595d1fbc54616efe8fe0b15866de3a417e107
7
+ data.tar.gz: 547abee73e761a66fce0b944c165f1e12ed4dcda481ae5719083bd5f8f205abd5e80a92ca8b22aeaf93da1fd50c4403ce1fffacf55f1b7ae6ecf02edbca3d9ce
data/README.md CHANGED
@@ -46,20 +46,17 @@ In your DB development you have these objects:
46
46
 
47
47
  ```ruby
48
48
  => #<DummyApp::User id: 12 name: "Jean", city: "London", age: 20, created_at: "2019-12-30 22:45:33", updated_at: "2019-12-30 22:45:33">
49
- ```
50
- ```ruby
49
+
51
50
  => #<DummyApp::Article id: 1, dummy_app_user_id: 12, dummy_app_category_id: 1, title: "Subway Art 25th", body: "Anniversary Edition", created_at: "2019-12-30 22:45:33", updated_at: "2019-12-30 22:45:33">
52
- ```
53
- ```ruby
51
+
54
52
  => #<DummyApp::Category id: 1, dummy_app_topic_id: 3, label: "Graffiti", created_at: "2019-12-30 22:45:33", updated_at: "2019-12-30 22:45:33">
55
- ```
56
- ```ruby
53
+
57
54
  => #<DummyApp::Topic id: 3, title: "Culture", description: "Culture is beautiful", created_at: "2019-12-30 22:45:33", updated_at: "2019-12-30 22:45:33">
58
55
  ```
59
56
 
60
57
  You want to test your `article`, in your terminal you have to type the following command:
61
58
 
62
- `like_im_five 1 dummy_app_articles`
59
+ `like_im_five 1 "dummy_app_articles"`
63
60
 
64
61
  and it will generate a new file in your `/spec` folder named: `data.txt` containing factories:
65
62
 
@@ -74,18 +71,43 @@ That's it, just copy/paste it in your concerned spec.
74
71
 
75
72
  ## Corner cases
76
73
 
77
- - **UID**
74
+ - **UID**
78
75
  I you are using `UID` rather than traditional `ID` no worries, we handle it for you. Just type commande below:
79
76
 
80
- `like_im_five "ffe-230-opoifhhfru-333" dummy_app_articles`
77
+ `like_im_five "ffe-230-opoifhhfru-333" "dummy_app_articles"`
81
78
 
82
79
  - **Similarity detection to match table name with model**
83
- For some reason it can be useful to use `Inflection`, especially if you are not coding in english.
80
+ Sometimes you have to use `Inflection`, especially if you are not coding in english.
84
81
 
85
82
  If you named a table `vitraux` and your model `vitrail` we will match both to build your factory.
86
83
 
87
84
  *nb: if your model name is really to different than your table name it can fails to match.*
88
85
 
86
+ - **Namespaced table name**
87
+ If you have namespaced table name but using model name as foreign_key in association we will handle it for you.
88
+
89
+ e.g:
90
+
91
+ You have the following table with the foreign_key ``website_id``
92
+ ```
93
+ create_table "dummy_app_articles", force: :cascade do |t|
94
+ t.string "title"
95
+ ...
96
+ t.bigint "website_id"
97
+ t.index ["website_id"], name: "index_dummy_app_articles_on_website_id"
98
+ end
99
+ ```
100
+
101
+ but your ``website`` table looks like
102
+ ````
103
+ create_table "dummy_app_websites", force: :cascade do |t|
104
+ t.string "url"
105
+ t.datetime "created_at", null: false
106
+ t.datetime "updated_at", null: false
107
+ end
108
+ ````
109
+
110
+ Connect `website_id` with `dummy_app_websites` can be messy but that's fine.
89
111
 
90
112
  ## Contributing
91
113
 
@@ -17,6 +17,8 @@ class ExtractAssociatedObject
17
17
  next if value.nil?
18
18
 
19
19
  result = ActiveRecord::Base.connection.execute("SELECT * FROM #{table} WHERE id='#{value}'").to_a
20
+ next if result.blank?
21
+
20
22
  result[0].delete('updated_at')
21
23
  result[0].delete('created_at')
22
24
  associated_object << { table: table, attributes: result }
@@ -36,6 +38,8 @@ class ExtractAssociatedObject
36
38
  if table_not_exist?(table)
37
39
  table = find_closest_table_name(table)
38
40
  end
41
+ next if table.kind_of?(Array)
42
+
39
43
  tables_names << ["#{table}", column]
40
44
  end
41
45
  tables_names
@@ -49,9 +53,8 @@ class ExtractAssociatedObject
49
53
  schema_tables.each do |table_name|
50
54
  levenshtein = Class.new.extend(Gem::Text).method(:levenshtein_distance)
51
55
  similarity = levenshtein.call(table, table_name)
52
- next if similarity > 3
53
-
54
- return table_name
56
+ return table_name if similarity < 3
57
+ return table_name if table_name.split('_').include?(table)
55
58
  end
56
59
  end
57
60
  end
@@ -1,3 +1,3 @@
1
1
  module LikeImFive
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: like_im_five
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clément Morisset
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-08 00:00:00.000000000 Z
11
+ date: 2020-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails