arxutils 0.1.31
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/arxutils.gemspec +38 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/exe/arxutils +3 -0
- data/lib/arxutils/arx.rb +29 -0
- data/lib/arxutils/arxutils.rb +21 -0
- data/lib/arxutils/dbutil/dbinit.rb +46 -0
- data/lib/arxutils/dbutil/dbmgr.rb +69 -0
- data/lib/arxutils/migrate.rb +71 -0
- data/lib/arxutils/store/storecsv.rb +18 -0
- data/lib/arxutils/store/storedb.rb +25 -0
- data/lib/arxutils/store.rb +22 -0
- data/lib/arxutils/version.rb +3 -0
- data/lib/arxutils.rb +13 -0
- data/lib/config/mysql.tmpl +29 -0
- data/lib/config/sqlite3.tmpl +26 -0
- data/lib/template/base.tmpl +14 -0
- data/lib/template/current.tmpl +17 -0
- data/lib/template/invalid.tmpl +12 -0
- data/lib/template/noitem.tmpl +13 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fb417c5c9b978efc194c67ba2fe77dc9c7d513fd
|
4
|
+
data.tar.gz: b6222fe0eb3cbaacbb3c2fb36d772854c993b3de
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d114e775a16a5a73b328a802c221004dad54e8a2b7a5d4881fec1d4836fb69361c526a5e45a0dd4106dddb2f1b947274c1280b61509c051311ef0035da2abfb8
|
7
|
+
data.tar.gz: 25d2c83d30862cf07bc1fea7d17b1c2d22e481440cb476c8b094fc9561d6d329f8e1d2669454555226e744504370c5d453adbf4a762c36bc6d81b4a5f23f31f9
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Arxutils
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/arxutils`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'arxutils'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install arxutils
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec arxutils` to use the gem in this directory, ignoring other installed copies of this gem.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/arxutils.
|
36
|
+
|
data/Rakefile
ADDED
data/arxutils.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'arxutils/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "arxutils"
|
8
|
+
spec.version = Arxutils::VERSION
|
9
|
+
spec.authors = ["yasuo kominami"]
|
10
|
+
spec.email = ["ykominami@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{utility functions for ActiveRecord.}
|
13
|
+
spec.description = %q{utility functions for ActiveRecord.}
|
14
|
+
spec.homepage = ""
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
|
+
# delete this section to allow pushing this gem to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
# spec.files = `find .`.split
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
# spec.add_runtime_dependency "erb"
|
31
|
+
spec.add_runtime_dependency "activerecord"
|
32
|
+
spec.add_runtime_dependency "sqlite3"
|
33
|
+
spec.add_runtime_dependency "encx"
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_development_dependency "rspec"
|
38
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "arxutils"
|
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
data/exe/arxutils
ADDED
data/lib/arxutils/arx.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
module Arxutils
|
5
|
+
class Arx
|
6
|
+
def initialize( data , fname )
|
7
|
+
@fname = fname
|
8
|
+
# 以下のものの配列
|
9
|
+
# :flist
|
10
|
+
# :classname
|
11
|
+
# :classname_downcase
|
12
|
+
# :items
|
13
|
+
# フィールド名, 型, null許容 の配列
|
14
|
+
# :plural
|
15
|
+
@data = data
|
16
|
+
|
17
|
+
@@field ||= Struct.new("Field" , :name, :type, :null )
|
18
|
+
|
19
|
+
@data[:ary] = @data[:items].map{ |x| @@field.new( *x ) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def create
|
23
|
+
contents = File.open( @fname ).read
|
24
|
+
|
25
|
+
erb = ERB.new(contents)
|
26
|
+
erb.result(binding)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Arxutils
|
4
|
+
class Arxutils
|
5
|
+
def Arxutils.dirname
|
6
|
+
File.dirname( __FILE__ )
|
7
|
+
end
|
8
|
+
|
9
|
+
def Arxutils.templatedir
|
10
|
+
File.join( Arxutils.dirname , ".." , "template" )
|
11
|
+
end
|
12
|
+
|
13
|
+
def Arxutils.rakefile
|
14
|
+
File.join( Arxutils.dirname , ".." , 'Rakefile')
|
15
|
+
end
|
16
|
+
|
17
|
+
def Arxutils.configdir
|
18
|
+
File.join( Arxutils.dirname , ".." , 'config' )
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#! -*- encoding : UTF-8 -*-
|
2
|
+
require 'fileutils'
|
3
|
+
require 'yaml'
|
4
|
+
require 'active_record'
|
5
|
+
require 'sqlite3'
|
6
|
+
|
7
|
+
module Arxutils
|
8
|
+
module Dbutil
|
9
|
+
DB_DIR = 'db'
|
10
|
+
MIGRATE_DIR = 'db/migrate'
|
11
|
+
DBCONFIG_SQLITE3 = 'sqlite3'
|
12
|
+
DBCONFIG_MYSQL = 'mysql'
|
13
|
+
CONFIG_DIR = 'config'
|
14
|
+
DATABASELOG = 'database.log'
|
15
|
+
|
16
|
+
class Dbinit
|
17
|
+
attr_accessor :dbconfig_dest_path , :dbconfig_src_path , :dbconfig_src_fname , :dbconfig_dest_fname
|
18
|
+
|
19
|
+
def initialize( db_dir , migrate_dir , src_config_dir , dbconfig , log_fname, forced = false )
|
20
|
+
@db_dir = db_dir
|
21
|
+
@migrate_dir = migrate_dir
|
22
|
+
@src_config_dir = src_config_dir
|
23
|
+
@dest_config_dir = "config"
|
24
|
+
@dbconfig_dest_fname = "#{dbconfig}.yaml"
|
25
|
+
@dbconfig_src_fname = "#{dbconfig}.tmpl"
|
26
|
+
@dbconfig_dest_path = File.join( @dest_config_dir , @dbconfig_dest_fname)
|
27
|
+
@dbconfig_src_path = File.join(@src_config_dir , @dbconfig_src_fname)
|
28
|
+
@log_fname = log_fname
|
29
|
+
@log_path = File.join( @db_dir , @log_fname )
|
30
|
+
FileUtils.mkdir_p( @db_dir )
|
31
|
+
FileUtils.mkdir_p( @migrate_dir )
|
32
|
+
FileUtils.mkdir_p( @dest_config_dir )
|
33
|
+
if forced
|
34
|
+
FileUtils.rm( Dir.glob( File.join( @migrate_dir , "*")))
|
35
|
+
FileUtils.rm( Dir.glob( File.join( @dest_config_dir , "*")))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def setup
|
40
|
+
dbconfig = YAML.load( File.read( @dbconfig_dest_path ) )
|
41
|
+
ActiveRecord::Base.establish_connection(dbconfig[ENV['ENV']])
|
42
|
+
ActiveRecord::Base.logger = Logger.new( @log_path )
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'arxutils/dbutil/dbinit'
|
3
|
+
|
4
|
+
require 'date'
|
5
|
+
require 'pp'
|
6
|
+
|
7
|
+
module Arxutils
|
8
|
+
module Dbutil
|
9
|
+
class DbMgr
|
10
|
+
def DbMgr.init( db_dir , migrate_dir , config_dir , dbconfig, log_fname, forced = false )
|
11
|
+
dbinit = Dbinit.new( db_dir , migrate_dir , config_dir , dbconfig, log_fname, forced )
|
12
|
+
DbMgr.setup( dbinit )
|
13
|
+
end
|
14
|
+
|
15
|
+
def DbMgr.setup( dbinit )
|
16
|
+
@@ret ||= nil
|
17
|
+
unless @@ret
|
18
|
+
begin
|
19
|
+
dbinit.setup
|
20
|
+
@@ret = DateTime.now.new_offset
|
21
|
+
rescue => ex
|
22
|
+
pp ex.class
|
23
|
+
pp ex.message
|
24
|
+
pp ex.backtrace
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
@@ret
|
29
|
+
end
|
30
|
+
|
31
|
+
def DbMgr.conv_string(value , encoding)
|
32
|
+
if value.class == String
|
33
|
+
if value.encodingy != encoding
|
34
|
+
value.encode(encoding)
|
35
|
+
else
|
36
|
+
value
|
37
|
+
end
|
38
|
+
else
|
39
|
+
value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def DbMgr.conv_boolean( k , v )
|
44
|
+
ret = v
|
45
|
+
if k =~ /enable/
|
46
|
+
if v.class == String
|
47
|
+
case v
|
48
|
+
when 'T'
|
49
|
+
ret = true
|
50
|
+
when 'F'
|
51
|
+
ret = false
|
52
|
+
else
|
53
|
+
raise
|
54
|
+
end
|
55
|
+
elsif v.class == TrueClass
|
56
|
+
# do nothin
|
57
|
+
elsif v.class == FalseClass
|
58
|
+
# do nothin
|
59
|
+
else
|
60
|
+
p v.class
|
61
|
+
p v
|
62
|
+
raise
|
63
|
+
end
|
64
|
+
end
|
65
|
+
ret
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'arxutils'
|
3
|
+
|
4
|
+
require 'fileutils'
|
5
|
+
require 'active_record'
|
6
|
+
|
7
|
+
module Arxutils
|
8
|
+
class Migrate
|
9
|
+
attr_accessor :dbinit , :dbconfig_dest_path , :dbconfig_dest_fname , :dbconfig_src_path , :dbconfig_src_fname
|
10
|
+
|
11
|
+
def Migrate.migrate( data_ary , idx , dbconfig , forced )
|
12
|
+
src_config_dir = Arxutils.configdir
|
13
|
+
mig = Migrate.new(Dbutil::DB_DIR, Dbutil::MIGRATE_DIR , src_config_dir , dbconfig, Dbutil::DATABASELOG, forced )
|
14
|
+
mig.make_dbconfig( data_ary[idx] )
|
15
|
+
|
16
|
+
data_ary.reduce(0) do |next_num , x|
|
17
|
+
mig.make( next_num , x )
|
18
|
+
end
|
19
|
+
|
20
|
+
Dbutil::DbMgr.setup( mig.dbinit )
|
21
|
+
|
22
|
+
mig.migrate
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize( db_dir , migrate_dir , config_dir , dbconfig, log_fname, forced = false )
|
26
|
+
@dbinit = Dbutil::Dbinit.new( db_dir , migrate_dir , config_dir , dbconfig, log_fname, forced )
|
27
|
+
@dbconfig_dest_path = @dbinit.dbconfig_dest_path
|
28
|
+
@dbconfig_src_path = @dbinit.dbconfig_src_path
|
29
|
+
@dbconfig_src_fname = @dbinit.dbconfig_src_fname
|
30
|
+
|
31
|
+
@migrate_dir = migrate_dir
|
32
|
+
@src_path = Arxutils.templatedir
|
33
|
+
@src_config_path = Arxutils.configdir
|
34
|
+
end
|
35
|
+
|
36
|
+
def convert( data , src_dir , src_fname )
|
37
|
+
arx = Arx.new( data , File.join( src_dir, src_fname ) )
|
38
|
+
arx.create
|
39
|
+
end
|
40
|
+
|
41
|
+
def make_dbconfig( data )
|
42
|
+
content = convert( data , @src_config_path , @dbconfig_src_fname )
|
43
|
+
File.open( @dbconfig_dest_path , 'w' , {:encoding => Encoding::UTF_8}){ |f|
|
44
|
+
f.puts( content )
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def make( next_num , data )
|
49
|
+
data[:flist].reduce(next_num) do |idy , x|
|
50
|
+
idy += 10
|
51
|
+
content = convert( data , @src_path , "#{x}.tmpl" )
|
52
|
+
case x
|
53
|
+
when "base" , "noitem"
|
54
|
+
additional = ""
|
55
|
+
else
|
56
|
+
additional = x
|
57
|
+
end
|
58
|
+
fname = File.join( @migrate_dir , sprintf("%03d_create_%s%s.rb" , idy , additional , data[:classname_downcase]) )
|
59
|
+
p fname
|
60
|
+
File.open( fname , 'w' , {:encoding => Encoding::UTF_8}){ |f|
|
61
|
+
f.puts( content )
|
62
|
+
}
|
63
|
+
idy
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def migrate
|
68
|
+
ActiveRecord::Migrator.migrate(@migrate_dir , ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'csv'
|
3
|
+
|
4
|
+
module Arxutils
|
5
|
+
class Store
|
6
|
+
class StoreCsv
|
7
|
+
def initialize( hs )
|
8
|
+
@csv = CSV.open( hs[:csv_fname] , "w" ,
|
9
|
+
{ :encoding => hs[:encoding],
|
10
|
+
:headers => hs[:headers],
|
11
|
+
:force_quotes => hs[:force_quotes],
|
12
|
+
:write_headers => hs[:write_headers],
|
13
|
+
} )
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'arxutils'
|
3
|
+
|
4
|
+
module Arxutils
|
5
|
+
class Store
|
6
|
+
class StoreDb
|
7
|
+
def StoreDb.init( hs , block = nil )
|
8
|
+
ret = nil
|
9
|
+
register_time = Dbutil::DbMgr.init( hs["db_dir"] , hs["migrate_dir"] , hs["config_dir"], hs["dbconfig"] , hs["log_fname"] )
|
10
|
+
|
11
|
+
if block
|
12
|
+
ret = block.call( register_time )
|
13
|
+
end
|
14
|
+
ret
|
15
|
+
end
|
16
|
+
# hs
|
17
|
+
# :csv_fname
|
18
|
+
# :mode
|
19
|
+
# :encoding => 'UTF-8',
|
20
|
+
# :headers => @headers_s,
|
21
|
+
# :force_quotes => true,
|
22
|
+
# :write_headers => true,
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'arxutils/store/storedb'
|
3
|
+
require 'arxutils/store/storecsv'
|
4
|
+
|
5
|
+
module Arxutils
|
6
|
+
class Store
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
def Store.init( kind , hs , &block )
|
10
|
+
case kind
|
11
|
+
when :db
|
12
|
+
obj = StoreDb.init( hs , block )
|
13
|
+
when :csv
|
14
|
+
obj = StoreCsv.new( hs )
|
15
|
+
else
|
16
|
+
obj = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
obj
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/arxutils.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'arxutils/version'
|
2
|
+
require 'arxutils/arxutils'
|
3
|
+
require 'arxutils/arx'
|
4
|
+
require 'arxutils/dbutil/dbinit'
|
5
|
+
require 'arxutils/dbutil/dbmgr'
|
6
|
+
require 'arxutils/store'
|
7
|
+
require 'arxutils/store/storedb'
|
8
|
+
require 'arxutils/store/storecsv'
|
9
|
+
require 'arxutils/migrate'
|
10
|
+
|
11
|
+
|
12
|
+
module Arxutils
|
13
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
#
|
4
|
+
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
+
# gem 'sqlite3'
|
6
|
+
#
|
7
|
+
default_env: &default
|
8
|
+
adapter: mysql2
|
9
|
+
host: localhost
|
10
|
+
username: root
|
11
|
+
password:
|
12
|
+
database: <%= x.name %>
|
13
|
+
pool: 5
|
14
|
+
timeout: 5000
|
15
|
+
|
16
|
+
development:
|
17
|
+
<<: *default
|
18
|
+
database: <%= x.name %>_developement
|
19
|
+
|
20
|
+
# Warning: The database defined as "test" will be erased and
|
21
|
+
# re-generated from your development database when you run "rake".
|
22
|
+
# Do not set this db to the same as development or production.
|
23
|
+
test:
|
24
|
+
<<: *default
|
25
|
+
database: <%= x.name %>_test
|
26
|
+
|
27
|
+
production:
|
28
|
+
<<: *default
|
29
|
+
database: <%= x.name %>_production
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
#
|
4
|
+
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
+
# gem 'sqlite3'
|
6
|
+
#
|
7
|
+
default_env: &default
|
8
|
+
adapter: sqlite3
|
9
|
+
pool: 5
|
10
|
+
timeout: 5000
|
11
|
+
database: db/sqlite3.db
|
12
|
+
|
13
|
+
development:
|
14
|
+
<<: *default
|
15
|
+
database: db/development.sqlite3
|
16
|
+
|
17
|
+
# Warning: The database defined as "test" will be erased and
|
18
|
+
# re-generated from your development database when you run "rake".
|
19
|
+
# Do not set this db to the same as development or production.
|
20
|
+
test:
|
21
|
+
<<: *default
|
22
|
+
database: db/test.sqlite3
|
23
|
+
|
24
|
+
production:
|
25
|
+
<<: *default
|
26
|
+
database: db/production.sqlite3
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Create<%= @data[:classname] %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :<%= @data[:plural] %> do |t|
|
4
|
+
<% @data[:ary].each do |x| %>
|
5
|
+
t.column :<%= x.name %>, :<%= x.type %>, :null => <%= x.null %>
|
6
|
+
<% end %>
|
7
|
+
t.column :start_datetime, :datetime, :null => false
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.down
|
12
|
+
drop_table :<%= @data[:plural] %>
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateCurrent<%= @data[:classname_downcase] %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
execute <<-SQL
|
4
|
+
CREATE VIEW current<%= @data[:plural] %> AS SELECT id as org_id,
|
5
|
+
<% @data[:ary].each do |x| %>
|
6
|
+
<%= x.name %>,
|
7
|
+
<% end %>
|
8
|
+
start_datetime FROM <%= @data[:plural] %> where not exists (select * from invalid<%= @data[:plural] %> where invalid<%= @data[:plural] %>.org_id = <%= @data[:plural] %>.id )
|
9
|
+
SQL
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
execute <<-SQL
|
14
|
+
DROP VIEW current<%= @data[:plural] %>
|
15
|
+
SQL
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class CreateInvalid<%= @data[:classname_downcase] %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :invalid<%= @data[:plural] %> do |t|
|
4
|
+
t.column :org_id, :int, :null => false
|
5
|
+
t.column :end_datetime, :datetime, :null => true
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.down
|
10
|
+
drop_table :invalid<%= @data[:plural] %>
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Create<%= @data[:classname] %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :<%= @data[:plural] %> do |t|
|
4
|
+
<% @data[:ary].each do |x| %>
|
5
|
+
t.column :<%= x.name %>, :<%= x.type %>, :null => <%= x.null %>
|
6
|
+
<% end %>
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
drop_table :<%= @data[:plural] %>
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: arxutils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.31
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- yasuo kominami
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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: encx
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: utility functions for ActiveRecord.
|
98
|
+
email:
|
99
|
+
- ykominami@gmail.com
|
100
|
+
executables:
|
101
|
+
- arxutils
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- arxutils.gemspec
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- exe/arxutils
|
115
|
+
- lib/arxutils.rb
|
116
|
+
- lib/arxutils/arx.rb
|
117
|
+
- lib/arxutils/arxutils.rb
|
118
|
+
- lib/arxutils/dbutil/dbinit.rb
|
119
|
+
- lib/arxutils/dbutil/dbmgr.rb
|
120
|
+
- lib/arxutils/migrate.rb
|
121
|
+
- lib/arxutils/store.rb
|
122
|
+
- lib/arxutils/store/storecsv.rb
|
123
|
+
- lib/arxutils/store/storedb.rb
|
124
|
+
- lib/arxutils/version.rb
|
125
|
+
- lib/config/mysql.tmpl
|
126
|
+
- lib/config/sqlite3.tmpl
|
127
|
+
- lib/template/base.tmpl
|
128
|
+
- lib/template/current.tmpl
|
129
|
+
- lib/template/invalid.tmpl
|
130
|
+
- lib/template/noitem.tmpl
|
131
|
+
homepage: ''
|
132
|
+
licenses: []
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.4.8
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: utility functions for ActiveRecord.
|
154
|
+
test_files: []
|
155
|
+
has_rdoc:
|