ahnnotate 0.2.0 → 0.3.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: 8c69ae3868972bae9fd2390bf305aba574c1a9522049ed1ce203b25b8423b9cb
4
- data.tar.gz: dd3d1e477e1351de18d99f54d1471ac1fc03c5a815a4eee0c78d104c3486aacd
3
+ metadata.gz: 13b084ef25894cf09c2f320a7eb570e77db859a8f9934fa2c7936eb0a84f2d7d
4
+ data.tar.gz: dc37cd9586705cfec747274976a36872b703220c2cb139b2611f3a30b3d8855f
5
5
  SHA512:
6
- metadata.gz: 6469c1d8fe2603f98757c149aa0d7e16e3a9460d635c8395a8a548268b743ae2c16bd3a958f34acf9f19cc4dd072c579bcae34f207953977d59483bd207fc9ff
7
- data.tar.gz: f2b2e026256a531b29eb2d3dc6d9b8950fa1ef90303b923bacdaa4f0e21d1d7d471d73e2be072058b5530a9e06e9c5bb8a0e62e574c45db2f46dfaa0e3260231
6
+ metadata.gz: '068b7d949adf95dec2a0b1b6fdab29b73664220e07ec7d0b6a6cd0475cf9db6fc9789b32d02ed3830ef617cb9041d0d67f9f8d41d188f74f203a42c9d1663fff'
7
+ data.tar.gz: 63280c4b766c9eb47bf2e4a7c9a9b37aaadac88ecb7355a3f44da1eea72d7ca7ea12bc6d38771c53b8c646fdfc894a025c6ed7f5ae7c13a1116531f9db3c4ba8
data/.gitignore CHANGED
@@ -6,3 +6,5 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /gemfiles/*.lock
10
+ /Gemfile.lock
data/.travis.yml CHANGED
@@ -4,4 +4,19 @@ language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
6
  - 2.5.3
7
+ - 2.1.10
8
+ gemfile:
9
+ - gemfiles/rails52.gemfile
10
+ - gemfiles/rails51.gemfile
11
+ - gemfiles/rails50.gemfile
12
+ - gemfiles/rails42.gemfile
13
+ - gemfiles/rails41.gemfile
7
14
  before_install: gem install bundler -v 1.17.1
15
+ matrix:
16
+ exclude:
17
+ - rvm: 2.1.10
18
+ gemfile: gemfiles/rails52.gemfile
19
+ - rvm: 2.1.10
20
+ gemfile: gemfiles/rails51.gemfile
21
+ - rvm: 2.1.10
22
+ gemfile: gemfiles/rails50.gemfile
data/Appraisals ADDED
@@ -0,0 +1,21 @@
1
+ appraise "rails52" do
2
+ gem "activerecord", "~> 5.2.2"
3
+ end
4
+
5
+ appraise "rails51" do
6
+ gem "activerecord", "~> 5.1.6"
7
+ end
8
+
9
+ appraise "rails50" do
10
+ gem "activerecord", "~> 5.0.7"
11
+ end
12
+
13
+ appraise "rails42" do
14
+ gem "activerecord", "~> 4.2.11"
15
+ end
16
+
17
+ appraise "rails41" do
18
+ gem "activerecord", "~> 4.1.16"
19
+ end
20
+
21
+ # vim: syntax=ruby
data/README.md CHANGED
@@ -1,13 +1,14 @@
1
1
  # Ahnnotate
2
2
 
3
- Ahnnotate comments on your ActiveRecord models with their respective schemas!
3
+ [Ahnnotate][rubygem] comments on your ActiveRecord models with their respective
4
+ schemas!
4
5
 
5
6
  Ahnnotate performs static analysis on your files to determine which files
6
7
  should be annotated. The primary goals of ahnnotate are ease of configuration
7
8
  and correctness.
8
9
 
9
10
  It's very similar to [annotate][annotate] and was inspired heavily by it.
10
- Annotate has more features than ahnnotate does; it may fit your needs much
11
+ Annotate has more features than ahnnotate does; it may fit your needs a bit
11
12
  better.
12
13
 
13
14
 
@@ -30,8 +31,7 @@ bundle
30
31
 
31
32
  Please use source control management software like git, mercurial, etc! The
32
33
  purpose of this software is to overwrite your source files. Although I'm pretty
33
- comfortable running this in my own projects, I've definitely made a couple bugs
34
- in my lifetime!
34
+ comfortable running this, I've definitely made a couple bugs in my lifetime!
35
35
 
36
36
 
37
37
  ### In a Rails app
@@ -45,7 +45,8 @@ bundle exec rake ahnnotate
45
45
  ```
46
46
 
47
47
  (Leaving out the `--fix` argument runs the command but doesn't make any changes
48
- to your filesystem. The rake task assumes that you do want to fix by default.)
48
+ to your filesystem. However, the rake task assumes that you do want to fix by
49
+ default.)
49
50
 
50
51
  Ahnnotate automatically runs after running migrations. This can be disabled,
51
52
  though by creating a `.ahnnotate.yml` configuration file and setting
@@ -116,3 +117,4 @@ The gem is available as open source under the terms of the [MIT License][mit].
116
117
  [annotate]: https://github.com/ctran/annotate_models
117
118
  [github]: https://github.com/zachahn/ahnnotate
118
119
  [mit]: https://opensource.org/licenses/MIT
120
+ [rubygem]: https://rubygems.org/gems/ahnnotate
data/ahnnotate.gemspec CHANGED
@@ -8,8 +8,10 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["Zach Ahn"]
9
9
  spec.email = ["engineering@zachahn.com"]
10
10
 
11
- spec.summary = %("Annotate" your models)
12
- spec.description = %(Heavily inspired by the `annotate` gem)
11
+ spec.summary = %(Ahnnotate comments on your ActiveRecord models with their respective schemas!)
12
+ spec.description = <<-DESC
13
+ Ahnnotate comments on your ActiveRecord models with their respective schemas!
14
+ DESC
13
15
  spec.license = "MIT"
14
16
 
15
17
  # Specify which files should be added to the gem when it is released.
@@ -25,7 +27,9 @@ Gem::Specification.new do |spec|
25
27
  spec.add_development_dependency "rake", "~> 10.0"
26
28
  spec.add_development_dependency "minitest", "~> 5.0"
27
29
  spec.add_development_dependency "sqlite3"
30
+ spec.add_development_dependency "pg"
28
31
  spec.add_development_dependency "pry"
32
+ spec.add_development_dependency "appraisal"
29
33
 
30
34
  spec.add_runtime_dependency "activerecord", ">= 4.0.0", "< 6"
31
35
  spec.add_runtime_dependency "parser"
data/bin/appraisal ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'appraisal' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("appraisal", "appraisal")
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.1.16"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 4.2.11"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 5.0.7"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 5.1.6"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 5.2.2"
6
+
7
+ gemspec path: "../"
data/lib/ahnnotate.rb CHANGED
@@ -1,9 +1,16 @@
1
+ require "yaml"
1
2
  require "active_record"
2
3
  require "parser/current"
3
4
  require "proc_party"
4
5
  require "stringio"
5
6
 
7
+ require "ahnnotate/refinement/dig"
8
+ require "ahnnotate/refinement/pathname_glob"
9
+ require "ahnnotate/refinement/yield_self"
10
+
11
+ require "ahnnotate/active_record_version"
6
12
  require "ahnnotate/column"
13
+ require "ahnnotate/command"
7
14
  require "ahnnotate/config"
8
15
  require "ahnnotate/error"
9
16
  require "ahnnotate/vfs"
@@ -12,7 +19,8 @@ require "ahnnotate/vfs_driver/hash"
12
19
  require "ahnnotate/vfs_driver/read_only_filesystem"
13
20
  require "ahnnotate/function/format"
14
21
  require "ahnnotate/function/main"
15
- require "ahnnotate/function/run"
22
+ require "ahnnotate/function/niam"
23
+ require "ahnnotate/function/strip_schema"
16
24
  require "ahnnotate/function/tabularize"
17
25
  require "ahnnotate/facet/models"
18
26
  require "ahnnotate/facet/models/main"
@@ -0,0 +1,19 @@
1
+ module Ahnnotate
2
+ class ActiveRecordVersion
3
+ class << self
4
+ def actual
5
+ @actual ||= Gem::Version.new(ActiveRecord::VERSION::STRING)
6
+ end
7
+
8
+ def five_and_up?
9
+ actual >= five
10
+ end
11
+
12
+ private
13
+
14
+ def five
15
+ @five ||= Gem::Version.new("5")
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/ahnnotate/cli.rb CHANGED
@@ -9,7 +9,13 @@ module Ahnnotate
9
9
  end
10
10
 
11
11
  def run(argv, config = nil)
12
- argv = argv.dup
12
+ argv =
13
+ if argv.is_a?(String)
14
+ require "shellwords"
15
+ Shellwords.split(argv)
16
+ else
17
+ argv.dup
18
+ end
13
19
 
14
20
  debug_options = argv.delete("--debug-opts") || argv.delete("--debug-options")
15
21
 
@@ -26,7 +32,11 @@ module Ahnnotate
26
32
  root = Pathname.new(Dir.pwd)
27
33
  config ||= Config.load(root: root)
28
34
 
29
- Function::Main.new(root, @options, config).call
35
+ if @options.remove?
36
+ Function::Niam.new(root, @options, config).call
37
+ else
38
+ Function::Main.new(root, @options, config).call
39
+ end
30
40
  end
31
41
 
32
42
  private
@@ -46,6 +56,10 @@ module Ahnnotate
46
56
  @options.fix = fix
47
57
  end
48
58
 
59
+ opts.on("--remove", "Remove annotations") do |remove|
60
+ @options.remove = remove
61
+ end
62
+
49
63
  opts.on("-h", "--help", "Prints this help message") do
50
64
  @options.exit = true
51
65
  puts opts
@@ -39,7 +39,14 @@ module Ahnnotate
39
39
  end
40
40
 
41
41
  if type == "boolean"
42
- return !ActiveModel::Type::Boolean::FALSE_VALUES.include?(@default)
42
+ default_is_false =
43
+ if ActiveRecordVersion.five_and_up?
44
+ ActiveModel::Type::Boolean::FALSE_VALUES.include?(@default)
45
+ else
46
+ ActiveRecord::ConnectionAdapters::Column::FALSE_VALUES.include?(@default)
47
+ end
48
+
49
+ return !default_is_false
43
50
  end
44
51
 
45
52
  @default
@@ -0,0 +1,29 @@
1
+ module Ahnnotate
2
+ module Command
3
+ def self.included(other)
4
+ other.class_eval do
5
+ attr_writer :vfs
6
+ end
7
+ end
8
+
9
+ def initialize(root, options, config)
10
+ @root = root
11
+ @options = options
12
+ @config = config
13
+ end
14
+
15
+ def vfs
16
+ @vfs ||= Vfs.new(vfs_driver)
17
+ end
18
+
19
+ private
20
+
21
+ def vfs_driver
22
+ if @options.fix?
23
+ VfsDriver::Filesystem.new(root: @root)
24
+ else
25
+ VfsDriver::ReadOnlyFilesystem.new(root: @root)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,5 @@
1
+ using Ahnnotate::Refinement::Dig
2
+
1
3
  module Ahnnotate
2
4
  class Config
3
5
  def self.load(root:)
@@ -19,6 +21,7 @@ module Ahnnotate
19
21
  "models" => {
20
22
  "enabled" => true,
21
23
  "path" => "app/models",
24
+ "extension" => ".rb",
22
25
  },
23
26
  },
24
27
  }
@@ -1,3 +1,5 @@
1
+ using Ahnnotate::Refinement::YieldSelf
2
+
1
3
  module Ahnnotate
2
4
  module Facet
3
5
  module Models
@@ -27,7 +29,8 @@ module Ahnnotate
27
29
  @model_nodes ||=
28
30
  begin
29
31
  model_path = @config["annotate", "models", "path"]
30
- model_files = @vfs.each_in(model_path)
32
+ model_extension = @config["annotate", "models", "extension"]
33
+ model_files = @vfs.each_in(model_path, model_extension)
31
34
  processor = Processor.new
32
35
  models = model_files.map do |path, contents|
33
36
  module_nodes = processor.call(contents)
@@ -117,6 +117,22 @@ module Ahnnotate
117
117
 
118
118
  super
119
119
  end
120
+
121
+ module ActiveRecord4Compatibility
122
+ class RelationDelegateClass
123
+ def initialize(*)
124
+ end
125
+ end
126
+
127
+ def relation_delegate_class(*)
128
+ RelationDelegateClass
129
+ end
130
+
131
+ def arel_table
132
+ end
133
+ end
134
+
135
+ include ActiveRecord4Compatibility
120
136
  end
121
137
  end
122
138
  end
@@ -14,22 +14,9 @@ module Ahnnotate
14
14
  private
15
15
 
16
16
  def strip_schema(content)
17
- matches = pattern.match(content)
17
+ @schema_stripper ||= StripSchema.new(comment: comment)
18
18
 
19
- if matches
20
- matches["post"]
21
- else
22
- content
23
- end
24
- end
25
-
26
- def pattern
27
- @pattern ||=
28
- begin
29
- newline = /\r?\n\r?/
30
-
31
- /\A#{comment}\s==\sSchema\sInfo#{newline}?(?:^#{comment}[^\n]*$#{newline})*#{newline}(?<post>.*)/m
32
- end
19
+ @schema_stripper.call(content)
33
20
  end
34
21
  end
35
22
  end
@@ -1,31 +1,24 @@
1
1
  module Ahnnotate
2
2
  module Function
3
3
  class Main
4
- def initialize(root, options, config)
5
- @root = root
6
- @options = options
7
- @config = config
8
- end
4
+ include Command
9
5
 
10
6
  def call
11
7
  if @config["boot"]
12
8
  eval @config["boot"]
13
9
  end
14
10
 
15
- vfs = Vfs.new(vfs_driver)
16
-
17
- runner = Run.new(@config, vfs)
18
- runner.call
11
+ Facet::Models.add(@config, tables_hash, vfs)
19
12
  end
20
13
 
21
14
  private
22
15
 
23
- def vfs_driver
24
- if @options.fix?
25
- VfsDriver::Filesystem.new(root: @root)
26
- else
27
- VfsDriver::ReadOnlyFilesystem.new(root: @root)
28
- end
16
+ def tables_hash
17
+ @tables_hash = tables.to_h
18
+ end
19
+
20
+ def tables
21
+ @tables ||= Tables.new
29
22
  end
30
23
  end
31
24
  end
@@ -0,0 +1,25 @@
1
+ module Ahnnotate
2
+ module Function
3
+ class Niam
4
+ include Command
5
+
6
+ def call
7
+ @config["annotate"].each do |facet_name, config|
8
+ if !config["enabled"]
9
+ next
10
+ end
11
+
12
+ schema_stripper = StripSchema.new(comment: "#")
13
+
14
+ vfs.each_in(config["path"], config["extension"]) do |path, content|
15
+ content_with_stripped_schema = schema_stripper.call(content)
16
+
17
+ if content_with_stripped_schema.size < content.size
18
+ vfs[path] = content_with_stripped_schema
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,32 @@
1
+ module Ahnnotate
2
+ module Function
3
+ class StripSchema
4
+ attr_reader :comment
5
+
6
+ def initialize(comment:)
7
+ @comment = comment
8
+ end
9
+
10
+ def call(content)
11
+ matches = pattern.match(content)
12
+
13
+ if matches
14
+ matches["post"]
15
+ else
16
+ content
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def pattern
23
+ @pattern ||=
24
+ begin
25
+ newline = /\r?\n\r?/
26
+
27
+ /\A#{comment}\s==\sSchema\sInfo(?:rmation)?#{newline}?(?:^#{comment}[^\n]*$#{newline})*#{newline}(?<post>.*)/m
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -21,6 +21,7 @@ module Ahnnotate
21
21
 
22
22
  attr_question :exit
23
23
  attr_question :fix
24
+ attr_question :remove
24
25
 
25
26
  def initialize(**args)
26
27
  args.each do |key, value|
@@ -19,26 +19,34 @@ namespace :db do
19
19
  end
20
20
 
21
21
  namespace :ahnnotate do
22
- desc "Run ahnnotate"
23
- task :all do
22
+ desc "Add annotations"
23
+ task :add do
24
24
  require "ahnnotate/cli"
25
- require "shellwords"
26
25
 
27
- # This should either be `rails` or `rake` (since newer versions of Rails
28
- # can call rake tasks with either executable)
29
- exe_name = File.basename($0)
26
+ argv = ENV.fetch("AHNNOTATE_ADD", "--fix")
30
27
 
31
- argv = ENV.fetch("COMMENTATE", "--fix")
32
- argv = Shellwords.split(argv)
28
+ puts "Adding annotations..."
33
29
 
34
- puts "Commentating models..."
30
+ cli = Ahnnotate::Cli.new(name: "ahnnotate")
31
+ cli.run(argv, $rake_ahnnotate_config)
32
+
33
+ puts "Done!"
34
+ end
35
+
36
+ desc "Remove annotations"
37
+ task :remove do
38
+ require "ahnnotate/cli"
39
+
40
+ argv = ENV.fetch("AHNNOTATE_REMOVE", "--fix --remove")
41
+
42
+ puts "Removing annotations..."
35
43
 
36
- cli = Ahnnotate::Cli.new(name: "#{exe_name} ahnnotate")
44
+ cli = Ahnnotate::Cli.new(name: "ahnnotate")
37
45
  cli.run(argv, $rake_ahnnotate_config)
38
46
 
39
47
  puts "Done!"
40
48
  end
41
49
  end
42
50
 
43
- desc "Run rake task `ahnnotate:all`"
44
- task ahnnotate: "ahnnotate:all"
51
+ desc "Run rake task `ahnnotate:add`"
52
+ task ahnnotate: "ahnnotate:add"
@@ -0,0 +1,39 @@
1
+ module Ahnnotate
2
+ module Refinement
3
+ module Dig
4
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.3.0")
5
+ refine Hash do
6
+ def dig(head, *tail)
7
+ value = self[head]
8
+
9
+ if tail.empty? || value.nil?
10
+ return value
11
+ end
12
+
13
+ if value.respond_to?(:dig) || value.is_a?(Hash) || value.is_a?(Array)
14
+ value.dig(*tail)
15
+ else
16
+ raise TypeError, "#{value.class} does not have #dig method"
17
+ end
18
+ end
19
+ end
20
+
21
+ refine Array do
22
+ def dig(head, *tail)
23
+ value = self.at(head)
24
+
25
+ if tail.empty? || value.nil?
26
+ return value
27
+ end
28
+
29
+ if value.respond_to?(:dig) || value.is_a?(Hash) || value.is_a?(Array)
30
+ value.dig(*tail)
31
+ else
32
+ raise TypeError, "#{value.class} does not have #dig method"
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,13 @@
1
+ module Ahnnotate
2
+ module Refinement
3
+ module PathnameGlob
4
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.5.0")
5
+ refine Pathname do
6
+ def glob(pattern)
7
+ Dir.glob(self.join(pattern)).map { |path| Pathname.new(path) }
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module Ahnnotate
2
+ module Refinement
3
+ module YieldSelf
4
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.5.0")
5
+ refine Object do
6
+ def yield_self
7
+ if !block_given?
8
+ return enum_for(:yield_self)
9
+ end
10
+
11
+ yield self
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -18,7 +18,7 @@ module Ahnnotate
18
18
  )
19
19
 
20
20
  output = StringIO.new
21
- output.puts "#{comment} == Schema Info"
21
+ output.puts "#{comment} == Schema Information"
22
22
  output.puts comment
23
23
  output.puts "#{comment} Table name: #{@name}"
24
24
  output.puts comment
@@ -15,7 +15,7 @@ module Ahnnotate
15
15
  enum_for(:each)
16
16
  end
17
17
 
18
- @connection.tables.each do |table_name|
18
+ @connection.public_send(data_sources_method_name).each do |table_name|
19
19
  primary_key = ActiveRecord::Base.get_primary_key(table_name)
20
20
 
21
21
  columns = @connection.columns(table_name).map do |c|
@@ -36,11 +36,16 @@ module Ahnnotate
36
36
  end
37
37
 
38
38
  indexes = @connection.indexes(table_name).map do |i|
39
+ comment =
40
+ if i.respond_to?(:comment)
41
+ i.comment
42
+ end
43
+
39
44
  Index.new(
40
45
  name: i.name,
41
46
  columns: i.columns,
42
47
  unique: i.unique,
43
- comment: i.comment
48
+ comment: comment
44
49
  )
45
50
  end
46
51
 
@@ -51,5 +56,14 @@ module Ahnnotate
51
56
  )
52
57
  end
53
58
  end
59
+
60
+ def data_sources_method_name
61
+ @data_sources_method_name ||=
62
+ if ActiveRecordVersion.five_and_up?
63
+ :data_sources
64
+ else
65
+ :tables
66
+ end
67
+ end
54
68
  end
55
69
  end
@@ -1,3 +1,3 @@
1
1
  module Ahnnotate
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/ahnnotate/vfs.rb CHANGED
@@ -42,7 +42,7 @@ module Ahnnotate
42
42
  @driver.each(&Proc.new)
43
43
  end
44
44
 
45
- def each_in(paths)
45
+ def each_in(paths, extensions = [])
46
46
  if !block_given?
47
47
  return enum_for(:each_in, paths)
48
48
  end
@@ -54,7 +54,17 @@ module Ahnnotate
54
54
  [paths]
55
55
  end
56
56
 
57
- @driver.each_in(paths, &Proc.new)
57
+ extensions = [extensions].flatten.compact
58
+
59
+ @driver.each_in(paths) do |path, content|
60
+ if extensions.any?
61
+ if !extensions.include?(File.extname(path))
62
+ next
63
+ end
64
+ end
65
+
66
+ yield(path, content)
67
+ end
58
68
  end
59
69
 
60
70
  private
@@ -1,3 +1,5 @@
1
+ using Ahnnotate::Refinement::PathnameGlob
2
+
1
3
  module Ahnnotate
2
4
  module VfsDriver
3
5
  class Filesystem
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ahnnotate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Ahn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-17 00:00:00.000000000 Z
11
+ date: 2019-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pg
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: pry
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: appraisal
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: activerecord
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -128,7 +156,10 @@ dependencies:
128
156
  - - ">="
129
157
  - !ruby/object:Gem::Version
130
158
  version: '0'
131
- description: Heavily inspired by the `annotate` gem
159
+ description: 'Ahnnotate comments on your ActiveRecord models with their respective
160
+ schemas!
161
+
162
+ '
132
163
  email:
133
164
  - engineering@zachahn.com
134
165
  executables:
@@ -138,19 +169,27 @@ extra_rdoc_files: []
138
169
  files:
139
170
  - ".gitignore"
140
171
  - ".travis.yml"
172
+ - Appraisals
141
173
  - Gemfile
142
- - Gemfile.lock
143
174
  - LICENSE.txt
144
175
  - README.md
145
176
  - Rakefile
146
177
  - ahnnotate.gemspec
178
+ - bin/appraisal
147
179
  - bin/console
148
180
  - bin/rake
149
181
  - bin/setup
150
182
  - exe/ahnnotate
183
+ - gemfiles/rails41.gemfile
184
+ - gemfiles/rails42.gemfile
185
+ - gemfiles/rails50.gemfile
186
+ - gemfiles/rails51.gemfile
187
+ - gemfiles/rails52.gemfile
151
188
  - lib/ahnnotate.rb
189
+ - lib/ahnnotate/active_record_version.rb
152
190
  - lib/ahnnotate/cli.rb
153
191
  - lib/ahnnotate/column.rb
192
+ - lib/ahnnotate/command.rb
154
193
  - lib/ahnnotate/config.rb
155
194
  - lib/ahnnotate/error.rb
156
195
  - lib/ahnnotate/facet/models.rb
@@ -162,12 +201,16 @@ files:
162
201
  - lib/ahnnotate/facet/models/standin.rb
163
202
  - lib/ahnnotate/function/format.rb
164
203
  - lib/ahnnotate/function/main.rb
165
- - lib/ahnnotate/function/run.rb
204
+ - lib/ahnnotate/function/niam.rb
205
+ - lib/ahnnotate/function/strip_schema.rb
166
206
  - lib/ahnnotate/function/tabularize.rb
167
207
  - lib/ahnnotate/index.rb
168
208
  - lib/ahnnotate/options.rb
169
209
  - lib/ahnnotate/rails.rake
170
210
  - lib/ahnnotate/railtie.rb
211
+ - lib/ahnnotate/refinement/dig.rb
212
+ - lib/ahnnotate/refinement/pathname_glob.rb
213
+ - lib/ahnnotate/refinement/yield_self.rb
171
214
  - lib/ahnnotate/table.rb
172
215
  - lib/ahnnotate/tables.rb
173
216
  - lib/ahnnotate/version.rb
@@ -198,5 +241,5 @@ rubyforge_project:
198
241
  rubygems_version: 2.7.6
199
242
  signing_key:
200
243
  specification_version: 4
201
- summary: '"Annotate" your models'
244
+ summary: Ahnnotate comments on your ActiveRecord models with their respective schemas!
202
245
  test_files: []
data/Gemfile.lock DELETED
@@ -1,55 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- ahnnotate (0.2.0)
5
- activerecord (>= 4.0.0, < 6)
6
- parser
7
- proc_party
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- activemodel (5.2.1.1)
13
- activesupport (= 5.2.1.1)
14
- activerecord (5.2.1.1)
15
- activemodel (= 5.2.1.1)
16
- activesupport (= 5.2.1.1)
17
- arel (>= 9.0)
18
- activesupport (5.2.1.1)
19
- concurrent-ruby (~> 1.0, >= 1.0.2)
20
- i18n (>= 0.7, < 2)
21
- minitest (~> 5.1)
22
- tzinfo (~> 1.1)
23
- arel (9.0.0)
24
- ast (2.4.0)
25
- coderay (1.1.2)
26
- concurrent-ruby (1.1.3)
27
- i18n (1.1.1)
28
- concurrent-ruby (~> 1.0)
29
- method_source (0.9.2)
30
- minitest (5.11.3)
31
- parser (2.5.3.0)
32
- ast (~> 2.4.0)
33
- proc_party (0.2.0)
34
- pry (0.12.2)
35
- coderay (~> 1.1.0)
36
- method_source (~> 0.9.0)
37
- rake (10.5.0)
38
- sqlite3 (1.3.13)
39
- thread_safe (0.3.6)
40
- tzinfo (1.2.5)
41
- thread_safe (~> 0.1)
42
-
43
- PLATFORMS
44
- ruby
45
-
46
- DEPENDENCIES
47
- bundler (~> 1.17)
48
- ahnnotate!
49
- minitest (~> 5.0)
50
- pry
51
- rake (~> 10.0)
52
- sqlite3
53
-
54
- BUNDLED WITH
55
- 1.17.1
@@ -1,24 +0,0 @@
1
- module Ahnnotate
2
- module Function
3
- class Run
4
- def initialize(config, vfs)
5
- @config = config
6
- @vfs = vfs
7
- end
8
-
9
- def call
10
- Facet::Models.add(@config, tables_hash, @vfs)
11
- end
12
-
13
- private
14
-
15
- def tables_hash
16
- @tables_hash = tables.to_h
17
- end
18
-
19
- def tables
20
- @tables ||= Tables.new
21
- end
22
- end
23
- end
24
- end