columns 0.0.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 +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +1 -0
- data/bin/columns +34 -0
- data/columns.gemspec +28 -0
- data/lib/columns/extended_content.rb +15 -0
- data/lib/columns/model_cleaner.rb +17 -0
- data/lib/columns/model_data.rb +39 -0
- data/lib/columns/model_writer.rb +30 -0
- data/lib/columns/raw_data.rb +13 -0
- data/lib/columns/regex.rb +17 -0
- data/lib/columns/table.rb +47 -0
- data/lib/columns/version.rb +3 -0
- data/lib/columns.rb +11 -0
- data/spec/extended_content_spec.rb +13 -0
- data/spec/fixtures/schema.rb +43 -0
- data/spec/fixtures/user_cleaned +4 -0
- data/spec/fixtures/user_filled +7 -0
- data/spec/model_cleaner_spec.rb +23 -0
- data/spec/model_data_spec.rb +20 -0
- data/spec/model_writer_spec.rb +34 -0
- data/spec/raw_data_spec.rb +18 -0
- data/spec/spec_helper.rb +50 -0
- data/spec/table_spec.rb +40 -0
- data/spec/version_spec.rb +8 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2fb05fd5b271d2da52b43da4de35438a74802cc0
|
4
|
+
data.tar.gz: c2a54c11f138608d8905798d32f91b75e360cc20
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bbf3877d98afc1460945b9641b0153c582763522b87668fc5459dbb9c2d485e608abe1d75657d2c1f45234675b03246ad28e6e7ec293b33574abd69adec95b0a
|
7
|
+
data.tar.gz: 830ff6fafe2c9961be383205715ee7989dde535d117d8c049995ed2d9ff755c3c04e467594a197301cd3fff22db58cfc34ac98563ce719bb79591ea6f3fd0289
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 lkdjiin
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Columns
|
2
|
+
|
3
|
+
Annotates activerecord models using `db/schema.rb`.
|
4
|
+
|
5
|
+
This is an alternative to the annotate gem for non rails apps.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'columns'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install columns
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
$ cd your_project
|
24
|
+
|
25
|
+
Once you have generate a `db/schema.rb`, just type
|
26
|
+
|
27
|
+
$ columns
|
28
|
+
|
29
|
+
to annotate your models.
|
30
|
+
|
31
|
+
Note that models must to reside in `app/models`.
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/[my-github-username]/columns/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/columns
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'columns'
|
4
|
+
|
5
|
+
# find all tables in the schema
|
6
|
+
schema_file = File.expand_path('./db/schema.rb')
|
7
|
+
|
8
|
+
unless File.exists?(schema_file)
|
9
|
+
puts "COLUMNS ERROR : #{schema_file} doesn't exist!"
|
10
|
+
exit 1
|
11
|
+
end
|
12
|
+
table = Columns::Table.new(File.read(schema_file))
|
13
|
+
|
14
|
+
# create RawData for each tables
|
15
|
+
raw_data_objects = []
|
16
|
+
table.names.each do |name|
|
17
|
+
raw_data_objects << Columns::RawData.new(name, table.content_for(name))
|
18
|
+
end
|
19
|
+
|
20
|
+
# create ModelData from each RawData
|
21
|
+
model_data_objects = raw_data_objects.map do |o|
|
22
|
+
Columns::ModelData.new(o)
|
23
|
+
end
|
24
|
+
|
25
|
+
# clean all models using ModelCleaner
|
26
|
+
# write all models using ModelData
|
27
|
+
writer = Columns::ModelWriter.new
|
28
|
+
model_data_objects.each do |o|
|
29
|
+
path = File.expand_path('./app/models/' + o.name + '.rb')
|
30
|
+
Columns::ModelCleaner.clean(path)
|
31
|
+
writer.add_info(o)
|
32
|
+
end
|
33
|
+
|
34
|
+
|
data/columns.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'columns/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "columns"
|
7
|
+
spec.version = Columns::VERSION
|
8
|
+
spec.authors = ["lkdjiin"]
|
9
|
+
spec.email = ["xavier.nayrac@gmail.com"]
|
10
|
+
spec.summary = %q{Annotates activerecord models using `db/schema.rb`.}
|
11
|
+
spec.homepage = ""
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.required_ruby_version = ['>=2.0.0', '<2.2.0']
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6.0"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec", '~>3.0.0'
|
24
|
+
spec.add_development_dependency "reek", '~>1.3.7'
|
25
|
+
spec.add_development_dependency "coco"
|
26
|
+
|
27
|
+
spec.requirements << 'sed'
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Columns
|
2
|
+
|
3
|
+
# Extends a content (column names and types) with some meta data.
|
4
|
+
class ExtendedContent
|
5
|
+
|
6
|
+
# Public: Get the extended content.
|
7
|
+
#
|
8
|
+
# content - The String content (from a ModelData object).
|
9
|
+
#
|
10
|
+
# Returns the String extended content.
|
11
|
+
def self.from(content)
|
12
|
+
"# == Schema Information\n#\n#{content}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Columns
|
2
|
+
|
3
|
+
# Public: This class is responsible of removing a possible schema info
|
4
|
+
# from a ruby model file. Note that it isn't any attempt to actually
|
5
|
+
# check if we really deals with a model.
|
6
|
+
class ModelCleaner
|
7
|
+
|
8
|
+
# Public: Removes schema info.
|
9
|
+
#
|
10
|
+
# file_path - An absolute String file name.
|
11
|
+
#
|
12
|
+
# Returns nothing.
|
13
|
+
def self.clean(file_path)
|
14
|
+
%x( sed -i -e '/# == Schema Info/,$d' #{file_path} > /dev/null 2>&1 )
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Columns
|
2
|
+
|
3
|
+
# Public: Stores data about a model.
|
4
|
+
#
|
5
|
+
# Model name
|
6
|
+
# ----------
|
7
|
+
# Usually a table is named with a plural, like 'users'. The
|
8
|
+
# corresponding model name is in singular, like 'user'.
|
9
|
+
#
|
10
|
+
# Model content
|
11
|
+
# -------------
|
12
|
+
# We want a «ready to paste» content.
|
13
|
+
#
|
14
|
+
# So, for example, if the raw content is:
|
15
|
+
#
|
16
|
+
# integer "foo"
|
17
|
+
#
|
18
|
+
# what we want is something like this:
|
19
|
+
#
|
20
|
+
# # integer "foo"
|
21
|
+
class ModelData
|
22
|
+
|
23
|
+
# Public: Get the model's name. For a model `app/models/user.rb`,
|
24
|
+
# the model's name will be `user`.
|
25
|
+
attr_reader :name
|
26
|
+
|
27
|
+
attr_reader :content
|
28
|
+
|
29
|
+
def initialize(raw_data)
|
30
|
+
# Ok, this is really idiot, I know, I know. Must use inflectors in
|
31
|
+
# the future.
|
32
|
+
@name = raw_data.name[0...-1]
|
33
|
+
|
34
|
+
contents = raw_data.content.split("\n")
|
35
|
+
contents.map! {|line| "# #{line.gsub(/^\s*t\./, '')}\n" }
|
36
|
+
@content = contents.join
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Columns
|
2
|
+
|
3
|
+
# Public: Add schema info to the end of a ruby model.
|
4
|
+
class ModelWriter
|
5
|
+
|
6
|
+
def initialize(path: './app/models/')
|
7
|
+
@path = path
|
8
|
+
end
|
9
|
+
|
10
|
+
def add_info(model_data)
|
11
|
+
@model_data = model_data
|
12
|
+
ensure_file_end_with_empty_line
|
13
|
+
if File.exists?(model_path)
|
14
|
+
File.open(model_path, 'a') do |file|
|
15
|
+
file.puts(ExtendedContent.from(@model_data.content))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def model_path
|
23
|
+
File.expand_path(File.join(@path, @model_data.name) + '.rb')
|
24
|
+
end
|
25
|
+
|
26
|
+
def ensure_file_end_with_empty_line
|
27
|
+
%x( sed -i -e '$a\\' #{model_path} > /dev/null 2>&1 )
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Columns
|
2
|
+
|
3
|
+
# Public: Utility methods related to regular expressions.
|
4
|
+
module Regex
|
5
|
+
|
6
|
+
# Public: Find a table name if it exists.
|
7
|
+
#
|
8
|
+
# string - The String to scan for a table name.
|
9
|
+
#
|
10
|
+
# Returns a String table name or nil.
|
11
|
+
def self.table_name(string)
|
12
|
+
string.match(/create_table\s*"(\w\w*)"/) {|matchdata| matchdata[1] }
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Columns
|
2
|
+
|
3
|
+
# Public: Represents data for the tables found in schema.
|
4
|
+
class Table
|
5
|
+
|
6
|
+
# Public:
|
7
|
+
#
|
8
|
+
# schema - The db/schema.rb as a String.
|
9
|
+
def initialize(schema)
|
10
|
+
# Records the original schema file. TODO See if it's really needed.
|
11
|
+
@schema = schema
|
12
|
+
@schema_lines = schema.split("\n")
|
13
|
+
end
|
14
|
+
|
15
|
+
# Public: Find the table names.
|
16
|
+
#
|
17
|
+
# Returns an Array of String.
|
18
|
+
def names
|
19
|
+
@schema_lines.map {|line| Regex.table_name(line) }.compact
|
20
|
+
end
|
21
|
+
|
22
|
+
# Public: Get the column names and types for a given table.
|
23
|
+
#
|
24
|
+
# name - The String name of the desired table.
|
25
|
+
#
|
26
|
+
# Returns a String with the raw content of the given table section
|
27
|
+
# from the schema file.
|
28
|
+
#
|
29
|
+
# TODO Sure it's better to parse the schema only once in #initialize.
|
30
|
+
def content_for(name)
|
31
|
+
found = false
|
32
|
+
result = ''
|
33
|
+
@schema_lines.each do |line|
|
34
|
+
if Regex.table_name(line) == name
|
35
|
+
found = true
|
36
|
+
next
|
37
|
+
end
|
38
|
+
if found
|
39
|
+
break if line =~ /\w*end$/
|
40
|
+
result << line + "\n"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
result
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/lib/columns.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "columns/version"
|
2
|
+
require "columns/table"
|
3
|
+
require "columns/regex"
|
4
|
+
require "columns/raw_data"
|
5
|
+
require "columns/model_data"
|
6
|
+
require "columns/model_cleaner"
|
7
|
+
require "columns/model_writer"
|
8
|
+
require "columns/extended_content"
|
9
|
+
|
10
|
+
module Columns
|
11
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ExtendedContent do
|
4
|
+
|
5
|
+
it 'add meta data to the content' do
|
6
|
+
content = "# foo integer\n"
|
7
|
+
extended_content = ExtendedContent.from(content)
|
8
|
+
expect(extended_content).to eq %q(# == Schema Information
|
9
|
+
#
|
10
|
+
# foo integer
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead
|
2
|
+
# of editing this file, please use the migrations feature of Active Record to
|
3
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your
|
6
|
+
# database schema. If you need to create the application database on another
|
7
|
+
# system, you should be using db:schema:load, not running all the migrations
|
8
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
9
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
10
|
+
#
|
11
|
+
# It's strongly recommended that you check this file into your version control system.
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define(version: 20140522124819) do
|
14
|
+
|
15
|
+
# These are extensions that must be enabled in order to support this database
|
16
|
+
enable_extension "plpgsql"
|
17
|
+
|
18
|
+
create_table "assignments", force: true do |t|
|
19
|
+
t.integer "foo"
|
20
|
+
t.string "bar"
|
21
|
+
end
|
22
|
+
|
23
|
+
add_index "assignments", ...
|
24
|
+
add_index "assignments", ...
|
25
|
+
|
26
|
+
create_table "products", force: true do |t|
|
27
|
+
end
|
28
|
+
|
29
|
+
# Bla bla bla
|
30
|
+
# Bla bla bla
|
31
|
+
# Bla bla bla
|
32
|
+
|
33
|
+
create_table "users", force: true do |t|
|
34
|
+
t.integer "id", null: false
|
35
|
+
t.string "name"
|
36
|
+
end
|
37
|
+
|
38
|
+
create_table "users_3", id: false, force: true do |t|
|
39
|
+
t.string "name"
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ModelCleaner do
|
4
|
+
|
5
|
+
before do
|
6
|
+
create_user_rb
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
remove_user_rb
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'cleans a ruby model' do
|
14
|
+
ModelCleaner.clean(user_rb_path)
|
15
|
+
expect(user_rb_file).to eq user_cleaned_file
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'silently fail if the file does not exist' do
|
19
|
+
expect{
|
20
|
+
ModelCleaner.clean('~/does_not_exist_file_123412341234.rb')
|
21
|
+
}.not_to raise_error
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ModelData do
|
4
|
+
|
5
|
+
before do
|
6
|
+
table = Table.new(schema_file)
|
7
|
+
raw = RawData.new('assignments', table.content_for('assignments'))
|
8
|
+
@subject = ModelData.new(raw)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'provides the name of the model' do
|
12
|
+
expect(@subject.name).to eq 'assignment'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'provides a «ready to paste» column names/types' do
|
16
|
+
content = "# integer \"foo\"\n# string \"bar\"\n"
|
17
|
+
expect(@subject.content).to eq content
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ModelWriter do
|
4
|
+
|
5
|
+
before do
|
6
|
+
remove_user_rb
|
7
|
+
create_clean_user_rb
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'writes schema info to the end of a file' do
|
11
|
+
writer = ModelWriter.new(path: fixtures_path)
|
12
|
+
data = instance_double(ModelData, name: 'user', content: "# foo integer\n")
|
13
|
+
|
14
|
+
writer.add_info(data)
|
15
|
+
|
16
|
+
expect(user_rb_file).to eq user_filled_file
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'IO errors' do
|
20
|
+
|
21
|
+
let(:unknown_file) { File.join(fixtures_path, 'unknown.rb') }
|
22
|
+
|
23
|
+
after { FileUtils.rm_f(unknown_file) }
|
24
|
+
|
25
|
+
it 'silently fail if the file does not exist' do
|
26
|
+
writer = ModelWriter.new(path: fixtures_path)
|
27
|
+
data = instance_double(ModelData, name: 'unknown', content: "\n")
|
28
|
+
|
29
|
+
expect{ writer.add_info(data) }.not_to raise_error
|
30
|
+
expect(File.exists?(unknown_file)).to eq false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RawData do
|
4
|
+
|
5
|
+
before do
|
6
|
+
table = Table.new(schema_file)
|
7
|
+
@subject = RawData.new('assignments', table.content_for('assignments'))
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'stores the raw table name' do
|
11
|
+
expect(@subject.name).to eq 'assignments'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'stores the raw content of the table' do
|
15
|
+
content = " t.integer \"foo\"\n t.string \"bar\"\n"
|
16
|
+
expect(@subject.content).to eq content
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'coco'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
require_relative '../lib/columns'
|
5
|
+
include Columns
|
6
|
+
|
7
|
+
def fixtures_path
|
8
|
+
File.expand_path(File.dirname(__FILE__) + '/fixtures')
|
9
|
+
end
|
10
|
+
|
11
|
+
def schema_file
|
12
|
+
file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/schema.rb')
|
13
|
+
File.read(file_path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def user_rb_path
|
17
|
+
File.expand_path(File.dirname(__FILE__) + '/fixtures/user.rb')
|
18
|
+
end
|
19
|
+
|
20
|
+
def user_rb_file
|
21
|
+
file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/user.rb')
|
22
|
+
File.read(file_path)
|
23
|
+
end
|
24
|
+
|
25
|
+
def user_cleaned_file
|
26
|
+
file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/user_cleaned')
|
27
|
+
File.read(file_path)
|
28
|
+
end
|
29
|
+
|
30
|
+
def user_filled_file
|
31
|
+
file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/user_filled')
|
32
|
+
File.read(file_path)
|
33
|
+
end
|
34
|
+
|
35
|
+
def remove_user_rb
|
36
|
+
file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/user.rb')
|
37
|
+
FileUtils.rm_f(file_path)
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_user_rb
|
41
|
+
src = File.expand_path(File.dirname(__FILE__) + '/fixtures/user_filled')
|
42
|
+
dest = File.expand_path(File.dirname(__FILE__) + '/fixtures/user.rb')
|
43
|
+
FileUtils.cp(src, dest)
|
44
|
+
end
|
45
|
+
|
46
|
+
def create_clean_user_rb
|
47
|
+
src = File.expand_path(File.dirname(__FILE__) + '/fixtures/user_cleaned')
|
48
|
+
dest = File.expand_path(File.dirname(__FILE__) + '/fixtures/user.rb')
|
49
|
+
FileUtils.cp(src, dest)
|
50
|
+
end
|
data/spec/table_spec.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Table do
|
4
|
+
|
5
|
+
before { @table = Table.new(schema_file) }
|
6
|
+
|
7
|
+
it 'find the right count of tables in the schema' do
|
8
|
+
expect(@table.names.size).to eq 4
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'find the right count of tables in a fake schema' do
|
12
|
+
schema = "create_table \"foos\"\nt.integer \"foo\"\nend"
|
13
|
+
expect(Table.new(schema).names.size).to eq 1
|
14
|
+
end
|
15
|
+
|
16
|
+
it "find the right table's names in the schema" do
|
17
|
+
names = ['assignments', 'products', 'users', 'users_3']
|
18
|
+
@table.names.each do |name|
|
19
|
+
expect(names.include?(name)).to be true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "find the right table's names in a fake schema" do
|
24
|
+
schema = "create_table \"foos\"\nt.integer \"foo\"\nend"
|
25
|
+
expect(Table.new(schema).names.first).to eq 'foos'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'find the content of a table in a fake schema' do
|
29
|
+
schema = "create_table \"foos\"\nt.integer \"foo\"\nend"
|
30
|
+
content = Table.new(schema).content_for('foos')
|
31
|
+
expect(content).to eq "t.integer \"foo\"\n"
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'find the content of a table in the schema' do
|
35
|
+
content = @table.content_for('assignments')
|
36
|
+
expected = " t.integer \"foo\"\n t.string \"bar\"\n"
|
37
|
+
expect(content).to eq expected
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: columns
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- lkdjiin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.6.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.6.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: reek
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.3.7
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.3.7
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: coco
|
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'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- xavier.nayrac@gmail.com
|
86
|
+
executables:
|
87
|
+
- columns
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/columns
|
98
|
+
- columns.gemspec
|
99
|
+
- lib/columns.rb
|
100
|
+
- lib/columns/extended_content.rb
|
101
|
+
- lib/columns/model_cleaner.rb
|
102
|
+
- lib/columns/model_data.rb
|
103
|
+
- lib/columns/model_writer.rb
|
104
|
+
- lib/columns/raw_data.rb
|
105
|
+
- lib/columns/regex.rb
|
106
|
+
- lib/columns/table.rb
|
107
|
+
- lib/columns/version.rb
|
108
|
+
- spec/extended_content_spec.rb
|
109
|
+
- spec/fixtures/schema.rb
|
110
|
+
- spec/fixtures/user_cleaned
|
111
|
+
- spec/fixtures/user_filled
|
112
|
+
- spec/model_cleaner_spec.rb
|
113
|
+
- spec/model_data_spec.rb
|
114
|
+
- spec/model_writer_spec.rb
|
115
|
+
- spec/raw_data_spec.rb
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
- spec/table_spec.rb
|
118
|
+
- spec/version_spec.rb
|
119
|
+
homepage: ''
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 2.0.0
|
132
|
+
- - "<"
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: 2.2.0
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements:
|
141
|
+
- sed
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.2.0.rc.1
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Annotates activerecord models using `db/schema.rb`.
|
147
|
+
test_files:
|
148
|
+
- spec/extended_content_spec.rb
|
149
|
+
- spec/fixtures/schema.rb
|
150
|
+
- spec/fixtures/user_cleaned
|
151
|
+
- spec/fixtures/user_filled
|
152
|
+
- spec/model_cleaner_spec.rb
|
153
|
+
- spec/model_data_spec.rb
|
154
|
+
- spec/model_writer_spec.rb
|
155
|
+
- spec/raw_data_spec.rb
|
156
|
+
- spec/spec_helper.rb
|
157
|
+
- spec/table_spec.rb
|
158
|
+
- spec/version_spec.rb
|