ittan 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2aa223ec33157b2ed452cdb063aa466c092713bd
4
+ data.tar.gz: e504106253c81e8e748d17487c992b0eeb962faf
5
+ SHA512:
6
+ metadata.gz: 91d0b032f06681ff305edfcc20322555dc7e1d436df6d1acf40f5ed699b7470a07e711de7490b774aded99d48a68332bb53f3350c940242b08644d336f7d8850
7
+ data.tar.gz: a3183b810ac9f67d3e3f6518c96bf6e52fb74774d80c84507acec591126087c3b1358dcefe136c32c6b8a9153b3a518a78bb346d92f2cd8954ab31c5b6d9a63a
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/bundle
11
+ .idea
12
+ /db
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.3
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at wisdom1027@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'awesome_print'
4
+ gem 'thor'
5
+ gem 'faker'
6
+ gem 'tod'
7
+ gem 'activesupport'
8
+
9
+ # Specify your gem's dependencies in ittan.gemspec
10
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 syossan27
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 syossan27
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Ittan
2
+
3
+ ittan(一旦)は`schema.rb`からとりあえずseed情報を生成するGemです。
4
+
5
+ ※ seed_fuを想定しております
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ittan'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ittan
22
+
23
+ ## Usage
24
+
25
+ ```
26
+ $ bundle exec ittan
27
+ ```
28
+
29
+ ## Contributing
30
+
31
+ Welcome
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
36
+
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ittan"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/ittan ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "ittan"
4
+ Ittan::CLI.start
data/ittan.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ittan/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ittan"
8
+ spec.version = Ittan::VERSION
9
+ spec.authors = ["syossan27"]
10
+ spec.email = ["wisdom1027@gmail.com"]
11
+
12
+ spec.summary = %q{Generate database dummy seed data.}
13
+ spec.description = %q{Generate database dummy seed data.}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "thor", "~> 0.19.4"
26
+ end
data/lib/ittan/cli.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'thor'
2
+ require 'faker'
3
+ require 'tod'
4
+ require 'tod/core_extensions'
5
+ require 'active_support'
6
+ require 'active_support/core_ext'
7
+ require 'awesome_print'
8
+
9
+ module Ittan
10
+
11
+ class CLI < Thor
12
+ default_command :create
13
+
14
+ desc "create", "create dummy data."
15
+ # method_option :type, aliases: '-t', default: 'seed_fu', type: :string, desc: "Select seed type. (seed or seed_fu)"
16
+ def create(file_path = 'db/schema.rb')
17
+ begin
18
+ File.open(file_path) do |file|
19
+ file.read.split("create_table").each_with_index do |table_sentence, index|
20
+ next if index == 0 # skip comment
21
+
22
+ table_instance = Ittan::Table.new(table_sentence)
23
+ table_instance.create_fixtures_directory
24
+ table_instance.create_seed_file
25
+ end
26
+ end
27
+ rescue SystemCallError => e
28
+ puts %Q(class=[#{e.class}] message=[#{e.message}])
29
+ rescue IOError => e
30
+ puts %Q(class=[#{e.class}] message=[#{e.message}])
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,104 @@
1
+ module Ittan
2
+ class Table
3
+ attr_accessor :content, :name, :model_name, :fixtures_path, :seed_file_path
4
+
5
+ def initialize(table_sentence)
6
+ # divide table_name from column
7
+ @content = table_sentence.split("do |t|")
8
+ @name = @content.shift.match(/\"[a-zA-Z_]*\"/)[0].delete("\"")
9
+ @model_name = @name.classify
10
+
11
+ # input file
12
+ @fixtures_path = "db/fixtures"
13
+ @seed_file_path = "#{@fixtures_path}/#{@name}.rb"
14
+ end
15
+
16
+ def create_fixtures_directory
17
+ FileUtils.mkdir_p(@fixtures_path) unless FileTest.exist?(@fixtures_path)
18
+ end
19
+
20
+ def create_seed_file
21
+ return if FileTest.exist?(@seed_file_path)
22
+ begin
23
+ File.open(@seed_file_path, "w") do |seed_file|
24
+ seed_file.puts "#{@model_name}.seed(\n:id,\n{\n" # input file header
25
+ @content[0].split("\n").each do |row|
26
+ next unless row.include?("t.") # skip except column
27
+ input_dummy_data(row, seed_file)
28
+ end
29
+ seed_file.puts "},\n)"
30
+ end
31
+ rescue SystemCallError => e
32
+ puts %Q(class=[#{e.class}] message=[#{e.message}])
33
+ rescue IOError => e
34
+ puts %Q(class=[#{e.class}] message=[#{e.message}])
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def input_dummy_data(column, file)
41
+ column_name = column.match("\"[a-zA-Z0-9_]*\"")[0].delete("\"")
42
+ file.puts "#{column_name}: #{create_string_dummy(column)}," if column.include?('t.string')
43
+ file.puts "#{column_name}: #{create_text_dummy}," if column.include?('t.text')
44
+ file.puts "#{column_name}: #{create_integer_dummy(column)}," if column.include?('t.integer')
45
+ file.puts "#{column_name}: #{create_float_dummy(column)}," if column.include?('t.float')
46
+ file.puts "#{column_name}: #{create_decimal_dummy(column)}," if column.include?('t.decimal')
47
+ file.puts "#{column_name}: #{create_boolean_dummy}," if column.include?('t.boolean')
48
+ file.puts "#{column_name}: #{create_date_dummy}," if column.include?('t.date ')
49
+ file.puts "#{column_name}: #{create_time_dummy}," if column.include?('t.time')
50
+ file.puts "#{column_name}: #{create_datetime_dummy}," if column.include?('t.datetime')
51
+ end
52
+
53
+ def create_string_dummy(column)
54
+ limit = column.match("(limit: )[0-9]*") { |match_data| match_data[0].delete("^0-9").to_i }
55
+ limit_random = rand(1..limit)
56
+ "\"#{Faker::Lorem.characters(limit_random)}\""
57
+ end
58
+
59
+ def create_text_dummy
60
+ "\"#{Faker::Lorem.sentence}\""
61
+ end
62
+
63
+ def create_integer_dummy(column)
64
+ limit = column.match("(limit: )[0-9]*") { |match_data| match_data[0].delete("^0-9").to_i }
65
+ limit_random = rand(1..limit)
66
+ Faker::Number.number(limit_random)
67
+ end
68
+
69
+ def create_float_dummy(column)
70
+ limit = column.match("(limit: )[0-9]*") { |match_data| match_data[0].delete("^0-9").to_i }
71
+ limit_random = rand(1..limit)
72
+ Faker::Number.decimal(limit_random)
73
+ end
74
+
75
+ def create_decimal_dummy(column)
76
+ precision = column.match("(precision: )[0-9]*") { |match_data| match_data[0].delete("^0-9").to_i }
77
+ scale = column.match("(scale: )[0-9]*") { |match_data| match_data[0].delete("^0-9").to_i }
78
+ if scale.nil?
79
+ integer_part = rand(1..precision - 1)
80
+ decimal_part = precision - integer_part
81
+ else
82
+ decimal_part = scale
83
+ integer_part = precision - decimal_part
84
+ end
85
+ Faker::Number.decimal(integer_part, decimal_part)
86
+ end
87
+
88
+ def create_date_dummy
89
+ "\"Faker::Date.between(Date.today, Date.today)\""
90
+ end
91
+
92
+ def create_time_dummy
93
+ "\"#{Time.now.to_time_of_day}\""
94
+ end
95
+
96
+ def create_datetime_dummy
97
+ "\"#{Faker::Time.between(DateTime.now, DateTime.now)}\""
98
+ end
99
+
100
+ def create_boolean_dummy
101
+ Faker::Boolean.boolean
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,3 @@
1
+ module Ittan
2
+ VERSION = "0.1.0"
3
+ end
data/lib/ittan.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "ittan/version"
2
+ require "ittan/cli"
3
+ require "ittan/table"
4
+
5
+ module Ittan
6
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ittan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - syossan27
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-07 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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'
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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.19.4
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.19.4
69
+ description: Generate database dummy seed data.
70
+ email:
71
+ - wisdom1027@gmail.com
72
+ executables:
73
+ - ittan
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - LICENSE
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - exe/ittan
89
+ - ittan.gemspec
90
+ - lib/ittan.rb
91
+ - lib/ittan/cli.rb
92
+ - lib/ittan/table.rb
93
+ - lib/ittan/version.rb
94
+ homepage: ''
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.4.5.1
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Generate database dummy seed data.
118
+ test_files: []