active_record-annotate 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 184d08a11090e8bd9d9d4e83aff9323f13c003ec
4
+ data.tar.gz: 309a4a90edb9aea169198585ad1ec1ed247c8797
5
+ SHA512:
6
+ metadata.gz: 93170988da55b445e19743d7d627888c355df51861c14b72f78e71d42fffd5dc51f084481575e3b5402dc2daeaed5433d81fd4270db9dc3da37e81aa89dc80d0
7
+ data.tar.gz: 39fbba81d3b8b3d8de4f171c553a6272df9499f8c40c951c98d122dd096606519b6dd722f3fb5376e1d193b19f6473db5c4f591ff3f32b5b245d26f6fd9addae
@@ -2,3 +2,4 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
+ - 2.1.0
data/README.md CHANGED
@@ -6,15 +6,15 @@ ActiveRecord::Annotate is a simple ActiveRecord plugin for annotating your rails
6
6
 
7
7
  Trivial.
8
8
 
9
- ``` ruby
9
+ ```ruby
10
10
  # Gemfile
11
11
  group :development do
12
12
  # you don't want to annotate your models in production, do you?
13
- gem 'active_record-annotate', '~> 0.2'
13
+ gem 'active_record-annotate', '~> 0.3'
14
14
  end
15
15
  ```
16
16
 
17
- ``` sh
17
+ ```sh
18
18
  $ bundle
19
19
  ```
20
20
 
@@ -24,13 +24,13 @@ Gem adds a simple `db:annotate` rake task - it just writes the annotation to the
24
24
 
25
25
  Once you install the gem into your application it hooks `db:annotate` to run after each `db:migrate` / `db:rollback` to keep the annotations in sync with the DB schema, but if you added a new model without migrating (or just accidentally messed up with something) you can always run the annotation process by hand:
26
26
 
27
- ``` sh
27
+ ```sh
28
28
  $ rake db:annotate
29
29
  ```
30
30
 
31
31
  This is what a common annotation looks like:
32
32
 
33
- ``` ruby
33
+ ```ruby
34
34
  # create_table :documents, force: true do |t|
35
35
  # t.string :title
36
36
  # t.text :content
@@ -45,17 +45,29 @@ class Document < ActiveRecord::Base
45
45
  # ...
46
46
  ```
47
47
 
48
+ ### Configuration
49
+
50
+ The annotation process can be configured via the `ActiveRecord::Annotate.configure` block which is handy to keep in the initializer.
51
+
52
+ You can generate the basic initializer with a built-in generator:
53
+
54
+ ```sh
55
+ $ rails generate active_record:annotate:install
56
+ ```
57
+
58
+ It creates an initializer at `config/initializers/annotate.rb` which contains descriptive comments about all settings (currently just one setting, `yard`).
59
+
48
60
  ## Changelog
49
61
 
50
62
  * 0.1 Initial version with core functionality
51
63
  * 0.1.1 Support for several models per table
52
64
  * 0.2 Auto-annotation after `db:migrate` & `db:rollback`, basic output
65
+ * 0.3 Configuration and YARD code blocks support
53
66
 
54
67
  ## Roadmap
55
68
 
56
69
  * Cover everything with tests
57
70
  * Write YARD docs
58
- * Add some means to configure the annotation process (annotation format, a place to put it)
59
71
 
60
72
  ## Contributing
61
73
 
@@ -1,3 +1,4 @@
1
+ require 'active_record/annotate/configurator'
1
2
  require 'active_record/annotate/dumper'
2
3
  require 'active_record/annotate/file'
3
4
  require 'active_record/annotate/version'
@@ -14,7 +15,7 @@ module ActiveRecord
14
15
 
15
16
  file_paths_and_classes.each do |path, klass|
16
17
  file = File.new(path)
17
- file.annotate_with(annotation)
18
+ file.annotate_with(annotation, configurator)
18
19
 
19
20
  if file.changed?
20
21
  file.write
@@ -59,10 +60,18 @@ module ActiveRecord
59
60
  short_path.camelize.constantize
60
61
  end
61
62
 
63
+ def configure(&block)
64
+ configurator.tap(&block)
65
+ end
66
+
62
67
  private
63
68
  def models_dir
64
69
  Rails.root.join('app/models')
65
70
  end
71
+
72
+ def configurator
73
+ @configurator ||= Configurator.new
74
+ end
66
75
  end
67
76
  end
68
77
  end
@@ -0,0 +1,19 @@
1
+ module ActiveRecord
2
+ module Annotate
3
+ class Configurator
4
+ %w(yard).each do |setting|
5
+ attr_accessor setting
6
+ alias_method "#{setting}?", setting
7
+ end
8
+
9
+ def initialize
10
+ reset
11
+ end
12
+
13
+ private
14
+ def reset
15
+ @yard = false
16
+ end
17
+ end
18
+ end
19
+ end
@@ -15,7 +15,7 @@ module ActiveRecord
15
15
  end
16
16
 
17
17
  def process_annotation(string_io)
18
- string_io.string.split("\n").map do |line|
18
+ string_io.string.split(?\n).map do |line|
19
19
  line.tap do |line|
20
20
  # commenting out the line
21
21
  line[0] = '#'
@@ -9,7 +9,7 @@ module ActiveRecord
9
9
  @lines = @content.split(?\n)
10
10
  end
11
11
 
12
- def annotate_with(annotation)
12
+ def annotate_with(annotation, configurator)
13
13
  if @lines.first =~ /^\s*#.*coding/
14
14
  # encoding: utf-8 encountered on the first line
15
15
  encoding_line = @lines.shift
@@ -21,6 +21,11 @@ module ActiveRecord
21
21
  @lines.shift
22
22
  end
23
23
 
24
+ if configurator.yard?
25
+ backticks = '# ```'
26
+ annotation.unshift(backticks).push(backticks)
27
+ end
28
+
24
29
  @lines.unshift(*annotation, nil)
25
30
  @lines.unshift(encoding_line) unless encoding_line.nil?
26
31
  @lines.push(nil) # newline at the end of file
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Annotate
3
- VERSION = '0.2'
3
+ VERSION = '0.3'
4
4
  end
5
5
  end
@@ -0,0 +1,8 @@
1
+ class ActiveRecord::Annotate::InstallGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ desc 'Creates an ActiveRecord::Annotate initializer in config/initializers/annotate.rb'
5
+ def create_initializer
6
+ copy_file 'initializer.rb', 'config/initializers/annotate.rb'
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ require 'active_record/annotate'
2
+
3
+ ActiveRecord::Annotate.configure do |config|
4
+ # set this to true to wrap annotations in triple backticks (```)
5
+ # so YARD documentation can process the annotation as a code block
6
+ # config.yard = false
7
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveRecord::Annotate::Configurator do
4
+ describe "#initialize" do
5
+ it "resets all settings to their default values" do
6
+ expect(subject.yard).to be_false
7
+ end
8
+ end
9
+
10
+ describe "attr_accessors" do
11
+ it "read and write settings' values" do
12
+ expect(subject.yard).to be_false
13
+
14
+ subject.yard = true
15
+ expect(subject.yard).to be_true
16
+ end
17
+ end
18
+ end
@@ -46,6 +46,22 @@ end
46
46
  # t.integer :age, null: false, default: 0
47
47
  # end
48
48
 
49
+ class User < ActiveRecord::Base
50
+ has_many :posts
51
+ end
52
+ FILE
53
+ end
54
+
55
+ let(:expected_result_for_yard) do
56
+ <<-FILE
57
+ # encoding: utf-8
58
+ # ```
59
+ # create_table :users do |t|
60
+ # t.string :name
61
+ # t.integer :age, null: false, default: 0
62
+ # end
63
+ # ```
64
+
49
65
  class User < ActiveRecord::Base
50
66
  has_many :posts
51
67
  end
@@ -53,20 +69,36 @@ end
53
69
  end
54
70
 
55
71
  let(:file) { ActiveRecord::Annotate::File.new(file_path) }
72
+ let(:configurator) { ActiveRecord::Annotate::Configurator.new }
56
73
 
57
74
  describe "#annotate_with" do
58
75
  it "changes the lines adding the new annotation" do
59
- file.annotate_with(new_annotation)
76
+ file.annotate_with(new_annotation, configurator)
60
77
 
61
78
  processed_file_content = file.lines.join(?\n)
62
79
  expect(processed_file_content).to eq(expected_result)
63
80
  end
81
+
82
+ context "when yard setting is on" do
83
+ let(:configurator) do
84
+ ActiveRecord::Annotate::Configurator.new.tap do |configurator|
85
+ configurator.yard = true
86
+ end
87
+ end
88
+
89
+ it "adds triple backticks around the annotation" do
90
+ file.annotate_with(new_annotation, configurator)
91
+
92
+ processed_file_content = file.lines.join(?\n)
93
+ expect(processed_file_content).to eq(expected_result_for_yard)
94
+ end
95
+ end
64
96
  end
65
97
 
66
98
  describe "#changed?" do
67
99
  context "with an old annotation" do
68
100
  before(:each) do
69
- file.annotate_with(old_annotation)
101
+ file.annotate_with(old_annotation, configurator)
70
102
  end
71
103
 
72
104
  it "returns false" do
@@ -76,7 +108,7 @@ end
76
108
 
77
109
  context "with a new annotation" do
78
110
  before(:each) do
79
- file.annotate_with(new_annotation)
111
+ file.annotate_with(new_annotation, configurator)
80
112
  end
81
113
 
82
114
  it "returns true" do
@@ -87,7 +119,7 @@ end
87
119
 
88
120
  describe "#write" do
89
121
  before(:each) do
90
- file.annotate_with(new_annotation)
122
+ file.annotate_with(new_annotation, configurator)
91
123
  end
92
124
 
93
125
  it "writes the new contents to file" do
metadata CHANGED
@@ -1,126 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record-annotate
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
5
- prerelease:
4
+ version: '0.3'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Vsevolod Romashov
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-11-20 00:00:00.000000000 Z
11
+ date: 2014-02-07 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '3.2'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '3.2'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bundler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '1.3'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '1.3'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: guard-rspec
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: terminal-notifier-guard
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: pry
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - ">="
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - ">="
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: awesome_print
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - ">="
116
102
  - !ruby/object:Gem::Version
117
103
  version: '0'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - ">="
124
109
  - !ruby/object:Gem::Version
125
110
  version: '0'
126
111
  description: Adds a rake task which prepends each model file with an excerpt about
@@ -131,9 +116,9 @@ executables: []
131
116
  extensions: []
132
117
  extra_rdoc_files: []
133
118
  files:
134
- - .gitignore
135
- - .rspec
136
- - .travis.yml
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
137
122
  - Gemfile
138
123
  - Guardfile
139
124
  - LICENSE.txt
@@ -141,46 +126,44 @@ files:
141
126
  - Rakefile
142
127
  - active_record-annotate.gemspec
143
128
  - lib/active_record/annotate.rb
129
+ - lib/active_record/annotate/configurator.rb
144
130
  - lib/active_record/annotate/dumper.rb
145
131
  - lib/active_record/annotate/file.rb
146
132
  - lib/active_record/annotate/railtie.rb
147
133
  - lib/active_record/annotate/version.rb
134
+ - lib/generators/active_record/annotate/install/install_generator.rb
135
+ - lib/generators/active_record/annotate/install/templates/initializer.rb
148
136
  - lib/tasks/annotate.rake
137
+ - spec/active_record/annotate/configurator_spec.rb
149
138
  - spec/active_record/annotate/file_spec.rb
150
139
  - spec/active_record/annotate_spec.rb
151
140
  - spec/spec_helper.rb
152
141
  homepage: https://github.com/7even/active_record-annotate
153
142
  licenses:
154
143
  - MIT
144
+ metadata: {}
155
145
  post_install_message:
156
146
  rdoc_options: []
157
147
  require_paths:
158
148
  - lib
159
149
  required_ruby_version: !ruby/object:Gem::Requirement
160
- none: false
161
150
  requirements:
162
- - - ! '>='
151
+ - - ">="
163
152
  - !ruby/object:Gem::Version
164
153
  version: '0'
165
- segments:
166
- - 0
167
- hash: 3616105738017822554
168
154
  required_rubygems_version: !ruby/object:Gem::Requirement
169
- none: false
170
155
  requirements:
171
- - - ! '>='
156
+ - - ">="
172
157
  - !ruby/object:Gem::Version
173
158
  version: '0'
174
- segments:
175
- - 0
176
- hash: 3616105738017822554
177
159
  requirements: []
178
160
  rubyforge_project:
179
- rubygems_version: 1.8.23
161
+ rubygems_version: 2.2.0
180
162
  signing_key:
181
- specification_version: 3
163
+ specification_version: 4
182
164
  summary: ActiveRecord models annotator based on rails' schema dumper
183
165
  test_files:
166
+ - spec/active_record/annotate/configurator_spec.rb
184
167
  - spec/active_record/annotate/file_spec.rb
185
168
  - spec/active_record/annotate_spec.rb
186
169
  - spec/spec_helper.rb