awesome_annotate 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/awesome_annotate/cli.rb +27 -13
- data/lib/awesome_annotate/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f47508ed24d0bf2374190e00d9f23032797e1fac1740d91283d392eb970ed8c
|
4
|
+
data.tar.gz: c76db1996bb2cee959f473c063c30b280077fc7b3fe64cd7c592b99eca4e7dd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d92baaa7dee1ebde3c1f5713e235a5f78ab4c3ea3f546e03f0de0fdacff286e493ddc7f94cbc18031341a98c009740300930004fd7eca0aa39fe87721be1f29d
|
7
|
+
data.tar.gz: ff3d7e4fc5b3e448de8e2b08feff317f20c7e4e7fc920e86dae9859fb7c0843df8d7c2f945decb886ac48c364ec85d46cc250155553cf491a8c93f22f432bf6e
|
data/lib/awesome_annotate/cli.rb
CHANGED
@@ -1,30 +1,44 @@
|
|
1
|
+
require 'active_record'
|
1
2
|
require 'awesome_annotate'
|
2
3
|
require 'thor'
|
3
|
-
require 'active_record'
|
4
4
|
|
5
5
|
module AwesomeAnnotate
|
6
6
|
class CLI < Thor
|
7
|
-
|
8
|
-
def annotate
|
9
|
-
puts "annotate your code"
|
10
|
-
return 'annotate your code'
|
11
|
-
# AwesomeAnnotate::Annotator.new.annotate
|
12
|
-
end
|
7
|
+
include Thor::Actions
|
13
8
|
|
14
9
|
desc 'model [model name]', 'annotate your model'
|
15
10
|
def model(model_name)
|
11
|
+
rails_env_file = Pathname.new('./config/environment.rb')
|
12
|
+
abort "Rails application path is required" unless rails_env_file.exist?
|
13
|
+
|
14
|
+
apply rails_env_file.to_s
|
15
|
+
|
16
16
|
name = model_name.singularize.camelize
|
17
17
|
klass = Object.const_get(name)
|
18
18
|
|
19
|
-
puts 'This
|
19
|
+
return puts 'This model does not inherit activerecord' unless klass < ActiveRecord::Base
|
20
20
|
|
21
21
|
column_names = klass.column_names
|
22
|
-
model_dir = 'app/models'
|
23
|
-
file_path = "#{model_dir}/#{model_name}.rb"
|
24
|
-
|
25
|
-
|
22
|
+
model_dir = Pathname.new('app/models')
|
23
|
+
file_path = "#{model_dir.to_s}/#{model_name}.rb"
|
24
|
+
|
25
|
+
return puts "Model file not found" unless File.exist?(file_path)
|
26
|
+
|
27
|
+
insert_into_file file_path, :before => / class #{klass} \n|class #{klass} .*\n / do
|
28
|
+
"# Columns: #{column_names.join(', ')}\n"
|
26
29
|
end
|
27
|
-
|
30
|
+
|
31
|
+
puts "annotate #{model_name.pluralize} table columns in #{file_path}"
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def self.exit_on_failure?
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.source_root
|
41
|
+
Dir.pwd
|
28
42
|
end
|
29
43
|
end
|
30
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: awesome_annotate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- wisdom-plus
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|