who_am_i 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/gemfiles/rails32.gemfile.lock +1 -1
- data/gemfiles/rails40.gemfile.lock +1 -1
- data/gemfiles/rails41.gemfile.lock +1 -1
- data/gemfiles/rails42.gemfile.lock +1 -1
- data/gemfiles/rails50.gemfile.lock +1 -1
- data/gemfiles/rails51.gemfile.lock +1 -1
- data/lib/who_am_i/extracted_class.rb +9 -0
- data/lib/who_am_i/function/annotate_models.rb +5 -2
- data/lib/who_am_i/function/load_inflections.rb +13 -0
- data/lib/who_am_i/function/main.rb +1 -0
- data/lib/who_am_i/function/resolve_class_relationships.rb +2 -1
- data/lib/who_am_i/function/resolve_table.rb +66 -0
- data/lib/who_am_i/version.rb +1 -1
- data/lib/who_am_i.rb +2 -1
- metadata +4 -3
- data/lib/who_am_i/function/resolve_tables.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55880585cfea925d0d39e6e92d909fbaa8a16344
|
4
|
+
data.tar.gz: 5fd295e65e97840d2f053402b778cad610543a22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d85064a47d41c6e03597ccc893bcfb5860f88a027a0c95051acb665b6a9a0fc41d6b5db037b666e8cfd1b3fce1746abe73eaa2cdca12e2cd8eda34643cd4035
|
7
|
+
data.tar.gz: 8c242e8b3ce144068ca7cbb9c80103fde3597731936702cca4ae3382a2898f73784baee06afd40d083910bbc57c52eacbfdb1ae12827ec535659c58aa6317331
|
@@ -23,6 +23,7 @@ module WhoAmI
|
|
23
23
|
self.claimed_superclass = claimed_superclass
|
24
24
|
self.table_name = table_name
|
25
25
|
self.abstract_class = abstract_class
|
26
|
+
@skipped_because = []
|
26
27
|
end
|
27
28
|
|
28
29
|
def activerecord?
|
@@ -45,6 +46,14 @@ module WhoAmI
|
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
49
|
+
def skipped?
|
50
|
+
@skipped_because.size > 0
|
51
|
+
end
|
52
|
+
|
53
|
+
def skip(reason)
|
54
|
+
@skipped_because.push(reason)
|
55
|
+
end
|
56
|
+
|
48
57
|
alias_method :to_s, :class_name
|
49
58
|
end
|
50
59
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module WhoAmI
|
2
2
|
module Function
|
3
3
|
class AnnotateModels
|
4
|
-
using Refinement::YieldSelf
|
5
4
|
include ProcParty
|
6
5
|
|
7
6
|
def initialize(config, tables)
|
@@ -14,10 +13,14 @@ module WhoAmI
|
|
14
13
|
.flat_map(&Ls.new)
|
15
14
|
.flat_map(&ParseModel.new)
|
16
15
|
.tap(&ExtractModelData.new)
|
17
|
-
.
|
16
|
+
.select(&:activerecord?)
|
18
17
|
.reject(&:abstract_class?)
|
18
|
+
.each(&ResolveTable.new(@tables))
|
19
|
+
.reject(&:skipped?)
|
19
20
|
.each(&ComputeComment.new)
|
21
|
+
.reject(&:skipped?)
|
20
22
|
.each(&ComputeContent.new)
|
23
|
+
.reject(&:skipped?)
|
21
24
|
.each(&WriteModel.new)
|
22
25
|
end
|
23
26
|
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module WhoAmI
|
2
|
+
module Function
|
3
|
+
class ResolveTable
|
4
|
+
include ProcParty
|
5
|
+
|
6
|
+
def initialize(known_tables)
|
7
|
+
@known_tables = known_tables
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(extracted_class)
|
11
|
+
set_table_name_for(extracted_class)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def set_table_name_for(extracted_class)
|
17
|
+
if extracted_class.abstract_class?
|
18
|
+
return
|
19
|
+
end
|
20
|
+
|
21
|
+
if extracted_class.table_name
|
22
|
+
return
|
23
|
+
end
|
24
|
+
|
25
|
+
if extracted_class.resolved_superclass
|
26
|
+
if !extracted_class.resolved_superclass.abstract_class?
|
27
|
+
set_table_name_for(extracted_class.resolved_superclass)
|
28
|
+
|
29
|
+
extracted_class.table_name =
|
30
|
+
extracted_class.resolved_superclass.table_name
|
31
|
+
|
32
|
+
return
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
extracted_class.table_name =
|
37
|
+
guess_table_from(extracted_class.class_name)
|
38
|
+
|
39
|
+
if extracted_class.table_name.nil?
|
40
|
+
extracted_class.skip("no table could be determined")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def guess_table_from(class_name)
|
45
|
+
loop do
|
46
|
+
guess =
|
47
|
+
class_name
|
48
|
+
.underscore
|
49
|
+
.pluralize
|
50
|
+
.sub(%r{\A/}, "")
|
51
|
+
.sub(%r{/}, "_")
|
52
|
+
|
53
|
+
if @known_tables.include?(guess)
|
54
|
+
break guess
|
55
|
+
end
|
56
|
+
|
57
|
+
if class_name !~ /::/
|
58
|
+
break
|
59
|
+
end
|
60
|
+
|
61
|
+
class_name = class_name.split("::", 2).last
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/who_am_i/version.rb
CHANGED
data/lib/who_am_i.rb
CHANGED
@@ -17,13 +17,14 @@ require "who_am_i/function/remove_annotation"
|
|
17
17
|
require "who_am_i/function/main"
|
18
18
|
require "who_am_i/function/load_config"
|
19
19
|
require "who_am_i/function/get_tables"
|
20
|
+
require "who_am_i/function/load_inflections"
|
20
21
|
require "who_am_i/function/annotate_models"
|
21
22
|
require "who_am_i/function/ls"
|
22
23
|
require "who_am_i/function/parse_model"
|
23
24
|
require "who_am_i/function/extract_model_data"
|
24
25
|
require "who_am_i/function/resolve_class_relationships"
|
25
26
|
require "who_am_i/function/resolve_active_record"
|
26
|
-
require "who_am_i/function/
|
27
|
+
require "who_am_i/function/resolve_table"
|
27
28
|
require "who_am_i/function/compute_comment"
|
28
29
|
require "who_am_i/function/compute_content"
|
29
30
|
require "who_am_i/function/write_model"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: who_am_i
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Ahn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -242,13 +242,14 @@ files:
|
|
242
242
|
- lib/who_am_i/function/extract_model_data.rb
|
243
243
|
- lib/who_am_i/function/get_tables.rb
|
244
244
|
- lib/who_am_i/function/load_config.rb
|
245
|
+
- lib/who_am_i/function/load_inflections.rb
|
245
246
|
- lib/who_am_i/function/ls.rb
|
246
247
|
- lib/who_am_i/function/main.rb
|
247
248
|
- lib/who_am_i/function/parse_model.rb
|
248
249
|
- lib/who_am_i/function/remove_annotation.rb
|
249
250
|
- lib/who_am_i/function/resolve_active_record.rb
|
250
251
|
- lib/who_am_i/function/resolve_class_relationships.rb
|
251
|
-
- lib/who_am_i/function/
|
252
|
+
- lib/who_am_i/function/resolve_table.rb
|
252
253
|
- lib/who_am_i/function/write_model.rb
|
253
254
|
- lib/who_am_i/rake.rb
|
254
255
|
- lib/who_am_i/refinement/yield_self.rb
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module WhoAmI
|
2
|
-
module Function
|
3
|
-
class ResolveTables
|
4
|
-
include ProcParty
|
5
|
-
|
6
|
-
def call(extracted_classes)
|
7
|
-
extracted_classes.each do |extracted_class|
|
8
|
-
if !extracted_class.table_name.nil?
|
9
|
-
next
|
10
|
-
end
|
11
|
-
|
12
|
-
extracted_class.table_name =
|
13
|
-
if Kernel.const_defined?(extracted_class.class_name)
|
14
|
-
Kernel.const_get(extracted_class.class_name).table_name
|
15
|
-
else
|
16
|
-
extracted_class.class_name
|
17
|
-
.underscore
|
18
|
-
.pluralize
|
19
|
-
.sub(%r{\A/}, "")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|