db_structure_writer 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 016052b9b868c4bfb0de9ae74274418380e509b2
4
+ data.tar.gz: e8a3ab71a7812b1f2cc113bf4513f3298d671311
5
+ SHA512:
6
+ metadata.gz: 84a418eada0aa8265f7ccad799d66f36dd4f33b36121be924bbe871e56d4c7890d7624a5666f7d02e1e61fec4060a65082d0a0fb552db7521d8c064bc7815357
7
+ data.tar.gz: af500d358cc451daf8ad52fe6311b8eba23a45f436f3f7e68afd47786917de016feaa8a9a552a82b48dec02321201a4798d26fe885f47e0a87228061a95b4e60
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in db_structure_writer.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 なりたけいすけ
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.
@@ -0,0 +1,29 @@
1
+ # DbStructureWriter
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'db_structure_writer'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install db_structure_writer
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'db_structure_writer'
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'db_structure_writer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "db_structure_writer"
8
+ spec.version = DbStructureWriter::VERSION
9
+ spec.authors = ["なりたけいすけ"]
10
+ spec.email = ["narikei1030@gmail.com"]
11
+ spec.description = 'this create HTML file describing the DB structure'
12
+ spec.summary = 'this create HTML file describing the DB structure'
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,9 @@
1
+ require "db_structure_writer/version"
2
+ require 'db_structure_writer/generate'
3
+ require 'db_structure_writer/template'
4
+ require 'db_structure_writer/railtie' if defined?(Rails)
5
+
6
+ module DbStructureWriter
7
+ end
8
+
9
+
@@ -0,0 +1,29 @@
1
+ module DbStructureWriter
2
+ module Generate
3
+
4
+ attr_accessor :tables
5
+
6
+ class << self
7
+
8
+ def html
9
+ str = Template.generate(table_list)
10
+ file_put(str)
11
+ end
12
+
13
+ private
14
+ def table_list
15
+ @tables ||= ActiveRecord::Base.connection.tables
16
+ end
17
+
18
+ def file_put(str)
19
+ puts 'file put'
20
+ file_path = "./db/#{Rails.application.class.parent_name}_db_tables.html".downcase
21
+ f = File.open(file_path, 'w')
22
+ f.puts str
23
+ f.close
24
+ p "generated #{file_path}"
25
+ end
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,10 @@
1
+ require 'db_structure_writer'
2
+ require 'rails'
3
+
4
+ module DbStructureWriter
5
+ class Railtie < Rails::Railtie
6
+ rake_tasks do
7
+ load "db_structure_writer/tasks.rake"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ require 'db_structure_writer'
2
+
3
+ namespace :db_structure_writer do
4
+
5
+ task :generate do
6
+ puts "html generate"
7
+ Rake::Task[:environment].invoke
8
+ DbStructureWriter::Generate.html
9
+ puts "Done!"
10
+ end
11
+
12
+ end
13
+
14
+ desc "DB html file generate"
15
+ task :db_structure_writer => "db_structure_writer:generate"
@@ -0,0 +1,81 @@
1
+ module DbStructureWriter
2
+ module Template
3
+
4
+ class << self
5
+ def generate(table_list)
6
+ str = '<html><body>'
7
+
8
+ str += "<h1>#{Rails.application.class.parent_name} DB tables</h1>"
9
+ str += disp_nav(table_list)
10
+
11
+ puts "total #{table_list.count} tables"
12
+ table_list.each do |table|
13
+ str += disp_table(table)
14
+ end
15
+
16
+ str += '</body></html>'
17
+ str
18
+ end
19
+
20
+ private
21
+ def disp_nav(table_list)
22
+ str = '<ul>'
23
+ table_list.each do |table|
24
+ str += "<li><a href=\"\##{table}\">#{table}</a></li>"
25
+ end
26
+ str += '</ul>'
27
+ str
28
+ end
29
+
30
+ def disp_table(table)
31
+ str = "<div id=#{table}>"
32
+ str += "<h2>#{table}</h2>"
33
+ begin
34
+ columns = Module.const_get(table.classify).columns
35
+
36
+ str += '<table border="1">'
37
+ str += table_head
38
+
39
+ columns.each do |column|
40
+ str += table_row(column)
41
+ end
42
+
43
+ str += "</table>"
44
+
45
+ puts " #{table} ok"
46
+ rescue
47
+ str += "<p>model not found</p>"
48
+ puts " #{table} ng"
49
+ end
50
+ str += '</div>'
51
+ str
52
+ end
53
+
54
+ def table_head
55
+ str = '<tr>'
56
+ str += '<th>name</th>'
57
+ str += '<th>primary</th>'
58
+ str += '<th>sql_type</th>'
59
+ str += '<th>type</th>'
60
+ str += '<th>limit</th>'
61
+ str += '<th>null</th>'
62
+ str += '<th>default</th>'
63
+ str += '</tr>'
64
+ str
65
+ end
66
+
67
+ def table_row(column)
68
+ str = '<tr>'
69
+ str += "<td>#{column.name}</td>"
70
+ str += "<td>#{'◯' if column.primary}</td>"
71
+ str += "<td>#{column.sql_type}</td>"
72
+ str += "<td>#{column.type}</td>"
73
+ str += "<td>#{column.limit}</td>"
74
+ str += "<td>#{'◯' if column.null}</td>"
75
+ str += "<td>#{column.default}</td>"
76
+ str += '</tr>'
77
+ end
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,3 @@
1
+ module DbStructureWriter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe DbStructureWriter do
4
+ it 'should have a version number' do
5
+ DbStructureWriter::VERSION.should_not be_nil
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'db_structure_writer'
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: db_structure_writer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - なりたけいすけ
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-13 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: this create HTML file describing the DB structure
56
+ email:
57
+ - narikei1030@gmail.com
58
+ executables:
59
+ - db_structure_writer
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - .rspec
65
+ - .travis.yml
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/db_structure_writer
71
+ - db_structure_writer.gemspec
72
+ - lib/db_structure_writer.rb
73
+ - lib/db_structure_writer/generate.rb
74
+ - lib/db_structure_writer/railtie.rb
75
+ - lib/db_structure_writer/tasks.rake
76
+ - lib/db_structure_writer/template.rb
77
+ - lib/db_structure_writer/version.rb
78
+ - spec/db_structure_writer_spec.rb
79
+ - spec/spec_helper.rb
80
+ homepage: ''
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.0.14
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: this create HTML file describing the DB structure
104
+ test_files:
105
+ - spec/db_structure_writer_spec.rb
106
+ - spec/spec_helper.rb