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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c32fa3c7c828aa41da8e575479a8d6156d06f6911890e704d605621760f8f3e
4
- data.tar.gz: 12d8857e51cf0ad0cc4f2819230236cce845eb54c41704551b81d2bec6422086
3
+ metadata.gz: 8f47508ed24d0bf2374190e00d9f23032797e1fac1740d91283d392eb970ed8c
4
+ data.tar.gz: c76db1996bb2cee959f473c063c30b280077fc7b3fe64cd7c592b99eca4e7dd9
5
5
  SHA512:
6
- metadata.gz: 71314f7a69db717c1d689468a1045e4fe5520a24ad98c2723081716b88e46f4268c5eb2949916c5f312016f90c5f103382cdf91adc2280132dd370aa90e0925d
7
- data.tar.gz: 191e243909d986426a9b31679d247ffb8c79bbd69f65dd0543459e625e891ed1bd6acd2622c6630ec8efe5f971e6916e9b2428ea22f45046e70e89142e4df43b
6
+ metadata.gz: d92baaa7dee1ebde3c1f5713e235a5f78ab4c3ea3f546e03f0de0fdacff286e493ddc7f94cbc18031341a98c009740300930004fd7eca0aa39fe87721be1f29d
7
+ data.tar.gz: ff3d7e4fc5b3e448de8e2b08feff317f20c7e4e7fc920e86dae9859fb7c0843df8d7c2f945decb886ac48c364ec85d46cc250155553cf491a8c93f22f432bf6e
@@ -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
- desc "annotate", "annotate your code"
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 is not a model' unless klass < ActiveRecord::Base
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
- File.open(file_path, 'r') do |file|
25
- file.puts "# Columns: #{column_names.join(', ')}"
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
- puts 'annotate your model'
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AwesomeAnnotate
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  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.0
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-04-30 00:00:00.000000000 Z
11
+ date: 2024-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor