hanami-annotate 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2f1e577b155812c324b26d125feb30ac2cde08952131431aa20dbf3f7cac847
4
- data.tar.gz: e6631c0f8e45ffa02039146e325113fc679fc21dd3c3defaeb159d49228545ec
3
+ metadata.gz: 1fd9e83cb2481fa586dd19604185e1397e51d1aa4c43700edc0cf7641c450607
4
+ data.tar.gz: 4ea986b5752d2f61b450e66742ca5ec3da5d31ec4ccf176d6c417def1d6bd171
5
5
  SHA512:
6
- metadata.gz: 26bc811e851c41c703b6b4561f7af24bd1c07d02ae33afb11fea692ac2d9f59db4a6740e65cccc0a9fe1b4fdee026bbe06701aae21f542a73e41b321c6103ef6
7
- data.tar.gz: f7abe6ee820f13190c53b7e68c97e001e87c175f82c56279e3611cae4f0c68cc6bf335473c7ff7190bb2326e4b77bec990c7b8cabd23627d57895b4a9f1593a2
6
+ metadata.gz: aa45d50cdb4ef48b7a4efcf7007210387a8f85648181b3d540f80b8963fb5a570959086c1c11562149e576d3e39d3ed46ed70cc16d45cddc5f74ec8617ca8685
7
+ data.tar.gz: ef0a50f5607732b8237dbca41193cf19f559e78e3c0613cd3e08b9053cd06427e2180fdb34081ade8b183eae5d7c609303a7cf8b6fc66e5594a9100ecebf42c5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hanami-annotate (0.1.0)
4
+ hanami-annotate (0.1.1)
5
5
  dry-inflector (~> 0.1.2)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -29,16 +29,16 @@ $ bundle exec hanami annotate
29
29
  and already annotations has added. Just like a below
30
30
 
31
31
  ```ruby
32
- # Table "public.users"
33
- # Column | Type | Modifiers
34
- #------------+-----------------------------+----------------------------------------------------
35
- # id | integer | not null default nextval('users_id_seq'::regclass)
36
- # name | text | not null
37
- # email | text | not null
38
- # created_at | timestamp without time zone | not null
39
- # updated_at | timestamp without time zone | not null
40
- #Indexes:
41
- # "users_pkey" PRIMARY KEY, btree (id)
32
+ # Table "public.users"
33
+ # Column | Type | Modifiers
34
+ # ------------+-----------------------------+----------------------------------------------------
35
+ # id | integer | not null default nextval('users_id_seq'::regclass)
36
+ # name | text | not null
37
+ # email | text | not null
38
+ # created_at | timestamp without time zone | not null
39
+ # updated_at | timestamp without time zone | not null
40
+ # Indexes:
41
+ # "users_pkey" PRIMARY KEY, btree (id)
42
42
  #
43
43
  class UserRepository < Hanami::Repository
44
44
  end
@@ -3,6 +3,13 @@ require 'dry/inflector'
3
3
  module Hanami
4
4
  module Annotate
5
5
  module CLI
6
+ # Generate annotation for Hanami entities and repositories
7
+ #
8
+ # usage:
9
+ # $ bundle exec hanami annotate
10
+ #
11
+ # @todo add support for mysql and sqlite3 etc..
12
+ #
6
13
  class Generate < Hanami::CLI::Command
7
14
  def call(*)
8
15
  postgres
@@ -12,10 +19,7 @@ module Hanami
12
19
 
13
20
  comment = commentize(table_info)
14
21
 
15
- files = \
16
- Dir[Hanami.root.join('lib', '*', '{entities,repositories}', '*')]
17
- .grep(Regexp.new(Dry::Inflector.new.singularize(table)))
18
-
22
+ remove_head_comments(entity_and_repository_path(table))
19
23
  adds_comments(files, comment)
20
24
  end
21
25
  end
@@ -30,8 +34,12 @@ module Hanami
30
34
  end
31
35
  end
32
36
 
37
+ def entity_and_repository_path(table)
38
+ Dir[Hanami.root.join('lib', '*', '{entities,repositories}', '*')]
39
+ .grep(Regexp.new(Dry::Inflector.new.singularize(table)))
40
+ end
41
+
33
42
  def adds_comments(files, comment)
34
- remove_head_comment(files)
35
43
  files.each do |file|
36
44
  content = ''
37
45
  File.open(file) { |f| content += f.read }
@@ -45,24 +53,26 @@ module Hanami
45
53
  end.join
46
54
  end
47
55
 
48
- def remove_head_comment(files)
56
+ def remove_head_comments(files)
49
57
  files.each do |file|
50
- index = 0
51
58
  comment_removed_content = ''
52
59
  File.open(file) do |f|
53
60
  raw_content = f.read
54
61
 
55
62
  lines = raw_content.each_line.to_a
56
- index = lines.index do |line|
57
- line.strip[0] != '#'
58
- end
59
-
63
+ index = non_comment_line_number(lines)
60
64
  comment_removed_content = lines[index..-1].join
61
65
  end
62
66
 
63
67
  File.open(file, 'w') { |f| f.puts(comment_removed_content) }
64
68
  end
65
69
  end
70
+
71
+ def non_comment_line_number(lines)
72
+ lines.index do |line|
73
+ line.strip[0] != '#'
74
+ end
75
+ end
66
76
  end
67
77
  end
68
78
  end
@@ -1,5 +1,5 @@
1
1
  module Hanami
2
2
  module Annotate
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-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
  - ippachi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-02 00:00:00.000000000 Z
11
+ date: 2018-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-inflector