arxutils 0.1.35 → 0.1.38

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0db660cdf41eaaaab3cc142711afb8186b10c06e
4
- data.tar.gz: 20a8b02d69969d52a37cfddda3c721d0d628762d
2
+ SHA256:
3
+ metadata.gz: 8843dd23f47002f43a70ea5b73ac8cf5d2306f5f0b989604ef7007afdf073472
4
+ data.tar.gz: 1e0877518f2f78e60126d34101a20dab3666c0fefe82961f2d696921ced18ccf
5
5
  SHA512:
6
- metadata.gz: 7e38ecbe696e36c4e4975fcf304beb86d49056edb6df241448232d7e8b987041f45514ece568c1449f4155fde058521c55a71e221e3de4f3d8a76bf5bd0e9f35
7
- data.tar.gz: bc11ab615060d8d3eaff76d5e582258adf766d78cde23852403ba4c3f05ae54440c2853f047675a59c8389a802cb9b3d648ca730aea8d49200a8c117dbf16ee7
6
+ metadata.gz: 51fdfe09bb56a1cc25146dd19095e7cc55664917db05da444e6bfe38fd40ea4611349399205e545c33558c4d24282050d5af075978f96fcb5749273e1d1b5ee7
7
+ data.tar.gz: dca19d84492fed1d8b617bcd6b1793315f140bc17b9eb31e22716c02baabf1ddc2071724b45194faa520d2311b28a8137a84ca8f75261caf5740615398f3750c
data/.gitignore CHANGED
@@ -1,9 +1,10 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
7
6
  /pkg/
8
7
  /spec/reports/
9
8
  /tmp/
9
+ vendor/
10
+ *.code-workspace
data/Gemfile.lock ADDED
@@ -0,0 +1,81 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ arxutils (0.1.37)
5
+ activerecord (< 7.0)
6
+ encx
7
+ sqlite3
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activemodel (6.1.6.1)
13
+ activesupport (= 6.1.6.1)
14
+ activerecord (6.1.6.1)
15
+ activemodel (= 6.1.6.1)
16
+ activesupport (= 6.1.6.1)
17
+ activesupport (6.1.6.1)
18
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ i18n (>= 1.6, < 2)
20
+ minitest (>= 5.1)
21
+ tzinfo (~> 2.0)
22
+ zeitwerk (~> 2.3)
23
+ ast (2.4.2)
24
+ concurrent-ruby (1.1.10)
25
+ diff-lcs (1.5.0)
26
+ encx (0.1.0)
27
+ i18n (1.12.0)
28
+ concurrent-ruby (~> 1.0)
29
+ json (2.6.2)
30
+ minitest (5.16.2)
31
+ parallel (1.22.1)
32
+ parser (3.1.2.1)
33
+ ast (~> 2.4.1)
34
+ rainbow (3.1.1)
35
+ rake (13.0.6)
36
+ regexp_parser (2.5.0)
37
+ rexml (3.2.5)
38
+ rspec (3.11.0)
39
+ rspec-core (~> 3.11.0)
40
+ rspec-expectations (~> 3.11.0)
41
+ rspec-mocks (~> 3.11.0)
42
+ rspec-core (3.11.0)
43
+ rspec-support (~> 3.11.0)
44
+ rspec-expectations (3.11.0)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.11.0)
47
+ rspec-mocks (3.11.1)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.11.0)
50
+ rspec-support (3.11.0)
51
+ rubocop (1.35.0)
52
+ json (~> 2.3)
53
+ parallel (~> 1.10)
54
+ parser (>= 3.1.2.1)
55
+ rainbow (>= 2.2.2, < 4.0)
56
+ regexp_parser (>= 1.8, < 3.0)
57
+ rexml (>= 3.2.5, < 4.0)
58
+ rubocop-ast (>= 1.20.1, < 2.0)
59
+ ruby-progressbar (~> 1.7)
60
+ unicode-display_width (>= 1.4.0, < 3.0)
61
+ rubocop-ast (1.21.0)
62
+ parser (>= 3.1.1.0)
63
+ ruby-progressbar (1.11.0)
64
+ sqlite3 (1.4.4)
65
+ tzinfo (2.0.5)
66
+ concurrent-ruby (~> 1.0)
67
+ unicode-display_width (2.2.0)
68
+ zeitwerk (2.6.0)
69
+
70
+ PLATFORMS
71
+ x64-mingw-ucrt
72
+
73
+ DEPENDENCIES
74
+ arxutils!
75
+ bundler
76
+ rake
77
+ rspec
78
+ rubocop
79
+
80
+ BUNDLED WITH
81
+ 2.3.7
data/SECURITY.md ADDED
@@ -0,0 +1,21 @@
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Use this section to tell people about which versions of your project are
6
+ currently being supported with security updates.
7
+
8
+ | Version | Supported |
9
+ | ------- | ------------------ |
10
+ | 5.1.x | :white_check_mark: |
11
+ | 5.0.x | :x: |
12
+ | 4.0.x | :white_check_mark: |
13
+ | < 4.0 | :x: |
14
+
15
+ ## Reporting a Vulnerability
16
+
17
+ Use this section to tell people how to report a vulnerability.
18
+
19
+ Tell them where to go, how often they can expect to get an update on a
20
+ reported vulnerability, what to expect if the vulnerability is accepted or
21
+ declined, etc.
data/arxutils.gemspec CHANGED
@@ -27,13 +27,19 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- spec.add_runtime_dependency "activesupport"
30
+ # spec.add_runtime_dependency "activesupport"
31
31
  # spec.add_runtime_dependency "erb"
32
- spec.add_runtime_dependency "activerecord"
32
+ # spec.add_runtime_dependency "activerecord" , "~> 7.0.2.3"
33
+ spec.add_runtime_dependency "activerecord" , "< 7.0"
33
34
  spec.add_runtime_dependency "sqlite3"
35
+ #spec.add_runtime_dependency "mysql2" , "~> 0.4.1"
36
+ spec.add_runtime_dependency "mysql2"
34
37
  spec.add_runtime_dependency "encx"
35
38
 
36
- spec.add_development_dependency "bundler", "~> 1.10"
37
- spec.add_development_dependency "rake", "~> 10.0"
39
+ # spec.add_development_dependency "bundler", "~> 2.3.7"
40
+ # spec.add_development_dependency "rake", ">= 12.3.3"
41
+ spec.add_development_dependency "bundler"
42
+ spec.add_development_dependency "rake"
38
43
  spec.add_development_dependency "rspec"
44
+ spec.add_development_dependency "rubocop"
39
45
  end
data/lib/arxutils/arx.rb CHANGED
@@ -2,10 +2,15 @@
2
2
  require 'erb'
3
3
 
4
4
  module Arxutils
5
+ # スキーマ設定に基づき、テンプレートから変換する
5
6
  class Arx
7
+ # スキーマ設定配列を、テンプレートで参照可能になるように展開する
6
8
  def initialize( data , fname )
9
+ # テンプレートファイルへのパス
7
10
  @fname = fname
8
- # 以下のものの配列
11
+
12
+ # スキーマ設定配列
13
+ # スキーマ設定とは以下をキーにもつハッシュである
9
14
  # :flist
10
15
  # :classname
11
16
  # :classname_downcase
@@ -15,6 +20,7 @@ module Arxutils
15
20
  # :relation
16
21
  @data = data
17
22
 
23
+ # スキーマ設定の:itemsの値を展開後格納するためのStructクラス
18
24
  @@field ||= Struct.new("Field" , :name, :type, :null )
19
25
 
20
26
  if @data[:items]
@@ -24,6 +30,7 @@ module Arxutils
24
30
  end
25
31
  end
26
32
 
33
+ # テンプレートファイルを元にした変換結果を返す
27
34
  def create
28
35
  contents = File.open( @fname ).read
29
36
  erb = ERB.new(contents)
@@ -1,17 +1,22 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Arxutils
4
+ # モジュールArxutils内でのユーティリティクラス
4
5
  class Arxutils
5
- def Arxutils.dirname
6
- File.dirname( __FILE__ )
7
- end
8
-
9
- def Arxutils.templatedir
6
+ # モジュールArxutils内のテンプレートファイル格納ディレクトリへのパスを返す
7
+ def self.templatedir
10
8
  File.join( Arxutils.dirname , ".." , "template" )
11
9
  end
12
10
 
13
- def Arxutils.configdir
11
+ # モジュールArxutils内の構成情報格納ディレクトリへのパスを返す
12
+ def self.configdir
14
13
  File.join( Arxutils.dirname , ".." , 'config' )
15
14
  end
15
+
16
+ private
17
+ # モジュールArxutils内のlib/arxutilsディレクトリへのパスを返す
18
+ def self.dirname
19
+ File.dirname( __FILE__ )
20
+ end
16
21
  end
17
22
  end
@@ -1,49 +1,89 @@
1
1
  #! -*- encoding : UTF-8 -*-
2
+ # coding: utf-8
2
3
  require 'fileutils'
3
4
  require 'yaml'
4
5
  require 'active_record'
5
- require 'sqlite3'
6
+
7
+ begin
8
+ require 'sqlite3'
9
+ rescue
10
+
11
+ end
12
+
13
+ begin
14
+ require 'mysql2'
15
+ rescue StandardError => ex
16
+ #p 1
17
+ rescue Exception => ex
18
+ #p 2
19
+ end
6
20
 
7
21
  module Arxutils
22
+ # DB操作用ユーティリティクラス
8
23
  module Dbutil
24
+ # DB格納ディレクトリ名
9
25
  DB_DIR = 'db'
26
+ # migrate用スクリプト格納ディレクトリ名
10
27
  MIGRATE_DIR = 'migrate'
28
+ # SQLITE3用DB構成名
11
29
  DBCONFIG_SQLITE3 = 'sqlite3'
30
+ # MYSQL用DB構成名
12
31
  DBCONFIG_MYSQL = 'mysql'
32
+ # DB構成格納用ディレクトリ名
13
33
  CONFIG_DIR = 'config'
34
+ # データベース用ログファイル名
14
35
  DATABASELOG = 'database.log'
15
-
36
+
37
+ # DB接続までの初期化を行う
16
38
  class Dbinit
17
- attr_accessor :dbconfig_dest_path , :dbconfig_src_path , :dbconfig_src_fname , :dbconfig_dest_fname , :migrate_dir
18
-
19
- def initialize( migrate_base_dir , src_config_dir , dbconfig , log_fname, forced = false )
20
- @db_dir = dbconfig[:db_dir]
39
+ # 生成するDB構成情報ファイルパス
40
+ attr_accessor :dbconfig_dest_path
41
+ # 参照用DB構成情報ファイル名
42
+ attr_accessor :dbconfig_src_fname
43
+ # migrate用スクリプトの出力先ディレクトリ名
44
+ attr_accessor :migrate_dir
45
+
46
+ # DB接続までの初期化に必要なディレクトリの確認、作成
47
+ def initialize( db_dir , migrate_base_dir , src_config_dir , dbconfig , env, log_fname, opts )
48
+ # DB格納ディレクトリ名
49
+ @db_dir = db_dir
50
+ # DB構成ファイルのテンプレート格納ディレクトリ
21
51
  @src_config_dir = src_config_dir
52
+ # DB構成ファイルの出力先ディレクトリ
22
53
  @dest_config_dir = "config"
23
- @dbconfig_dest_fname = "#{dbconfig[:kind]}.yaml"
24
- @dbconfig_src_fname = "#{dbconfig[:kind]}.tmpl"
54
+ # DB構成ファイル名
55
+ @dbconfig_dest_fname = "#{dbconfig}.yaml"
56
+ # DB構成ファイル用テンプレートファイル名
57
+ @dbconfig_src_fname = "#{dbconfig}.tmpl"
58
+ # DB構成ファイルへのパス
25
59
  @dbconfig_dest_path = File.join( @dest_config_dir , @dbconfig_dest_fname)
60
+ # DB構成ファイル用テンプレートファイルへのパス
26
61
  @dbconfig_src_path = File.join(@src_config_dir , @dbconfig_src_fname)
62
+ # 環境の指定
63
+ @env = env
64
+ # DB用ログファイル名
27
65
  @log_fname = log_fname
28
-
66
+
29
67
  if @db_dir and @log_fname
68
+ # DB用ログファイルへのパス
30
69
  @log_path = File.join( @db_dir , @log_fname )
70
+ # migrate用スクリプト格納ディレクトリへのパス
31
71
  @migrate_dir = File.join( @db_dir , migrate_base_dir )
32
72
  end
33
73
  FileUtils.mkdir_p( @db_dir ) if @db_dir
34
74
  FileUtils.mkdir_p( @migrate_dir ) if @migrate_dir
35
75
  FileUtils.mkdir_p( @dest_config_dir )
36
- if forced
76
+ # remigrateが指定されれば、migrate用スクリプトとDB構成ファイルを削除する
77
+ if opts["remigate"]
37
78
  FileUtils.rm( Dir.glob( File.join( @migrate_dir , "*"))) if @migrate_dir
38
79
  FileUtils.rm( Dir.glob( File.join( @dest_config_dir , "*")))
39
80
  end
40
81
  end
41
-
82
+
83
+ # DB接続し、DB用ログファイルの設定
42
84
  def setup
43
- puts ENV['ENV']
44
85
  dbconfig = YAML.load( File.read( @dbconfig_dest_path ) )
45
- puts dbconfig[ ENV['ENV'] ]
46
- ActiveRecord::Base.establish_connection(dbconfig[ENV['ENV']])
86
+ ActiveRecord::Base.establish_connection(dbconfig[@env])
47
87
  ActiveRecord::Base.logger = Logger.new( @log_path )
48
88
  end
49
89
  end
@@ -1,19 +1,21 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  require 'arxutils/dbutil/dbinit'
4
-
5
4
  require 'date'
6
5
  require 'pp'
7
6
 
8
7
  module Arxutils
9
8
  module Dbutil
9
+ # DB接続時に、現在日時も取得したい場合のユーティリティクラス
10
10
  class DbMgr
11
- def DbMgr.init( migrate_dir , config_dir , dbconfig, log_fname, forced = false )
12
- dbinit = Dbinit.new( migrate_dir , config_dir , dbconfig, log_fname, forced )
13
- DbMgr.setup( dbinit )
11
+ # Dbinitクラスのインスタンス生成とDB接続、現在日時取得
12
+ def self.init( db_dir , migrate_dir , config_dir , dbconfig, env , log_fname, opts )
13
+ dbinit = Dbinit.new( db_dir, migrate_dir , config_dir , dbconfig, env , log_fname, opts )
14
+ self.setup( dbinit )
14
15
  end
15
-
16
- def DbMgr.setup( dbinit )
16
+
17
+ # DB接続、現在日時取得
18
+ def self.setup( dbinit )
17
19
  @@ret ||= nil
18
20
  unless @@ret
19
21
  begin
@@ -28,42 +30,6 @@ module Arxutils
28
30
 
29
31
  @@ret
30
32
  end
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
33
  end
68
34
  end
69
35
  end
data/lib/arxutils/hier.rb CHANGED
@@ -1,25 +1,61 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  module Arxutils
4
+ # 階層処理
4
5
  class HierOp
5
- def initialize( hier_symbol , base_klass , hier_klass , current_klass )
6
+ # 階層処理を付加したいフィールド名(未使用か?)
7
+ attr_reader :field_name
8
+ # '/'が区切り文字の文字列で階層処理を実現するクラスの階層構造を表す文字列を持つメソッド/アトリビュートを表すシンボル
9
+ attr_reader :hier_symbol
10
+ # '/'が区切り文字の文字列で階層処理を実現するクラスのクラス名(DB中のテーブルに対応するActiveRecordの子クラス)
11
+ # シンボルhier_symbolで指定できるメソッド/アトリビュート(string)を持つ。
12
+ # nameというメソッド/アトリビュート(string)を持つ。"'/'を区切り文字として持つ階層を表す文字列
13
+ # registerメソッドを呼び出す時は、hier_symbolのみを指定してcreate出来なければならない(そうでなければSQLの制約違反発生)
14
+ attr_reader :base_klass
15
+ # '/'が区切り文字の文字列で階層処理を実現するクラスのカレントに対応するクラス名(DB中のテーブルに対応するActiveRecordの子クラス)
16
+ attr_reader :current_klass
17
+ # '/'が区切り文字の文字列で階層処理を実現するクラスのインバリッドに対応するクラス名(DB中のテーブルに対応するActiveRecordの子クラス)
18
+ attr_reader :invalid_klass
19
+ # IDの親子関係で階層処理を実現するクラス名(DB中のテーブルに対応するActiveRecordの子クラス)
20
+ # parent_id(integer) , child_id(integer) , leve(integer)というメソッド/アトリビュートを持つ
21
+ attr_reader :hier_klass
22
+
23
+ # 初期化
24
+ def initialize( field_name, hier_symbol , hier_name, base_klass , hier_klass , current_klass , invalid_klass )
25
+ # 階層処理を付加したいフィールド名
26
+ @field_name = field_name
27
+ # '/'が区切り文字の文字列で階層処理を実現するクラスの階層構造を表す文字列を持つメソッド/アトリビュートを表すシンボ
6
28
  @hier_symbol = hier_symbol
29
+ # '/'が区切り文字の文字列で階層処理を実現するクラスのクラス名(DB中のテーブルに対応するActiveRecordの子クラス)
7
30
  @base_klass = base_klass
8
- @hier_klass = hier_klass
31
+ # '/'が区切り文字の文字列で階層処理を実現するクラスのカレントに対応するクラス名(DB中のテーブルに対応するActiveRecordの子クラス)
9
32
  @current_klass = current_klass
33
+ # '/'が区切り文字の文字列で階層処理を実現するクラスのインバリッドに対応するクラス名(DB中のテーブルに対応するActiveRecordの子クラス)
34
+ @invalid_klass = invalid_klass
35
+ # IDの親子関係で階層処理を実現するクラス名(DB中のテーブルに対応するActiveRecordの子クラス)
36
+ # print_id(integer), child_id(integer), level(integer)
37
+ @hier_klass = hier_klass
10
38
  end
11
-
39
+
40
+ # 指定した階層(階層を/で区切って表現)のアイテムをbase_klassから削除
12
41
  def delete( hier )
13
42
  # 子として探す
14
43
  id = nil
15
- row_item = @base_klass.find_by( { @hier_symbol => hier } )
16
- if row_item
17
- id = row_item.id
18
- delete_at( id )
44
+ base = @base_klass.find_by( { @hier_symbol => hier } )
45
+ if base
46
+ delete_at( base.org_id )
47
+ @base_klass.delete_at( base.id )
19
48
  end
20
49
  id
21
50
  end
22
51
 
52
+ def delete_by_id( id )
53
+ base = @base_klass.find_by( org_id: id )
54
+ delete_at( id )
55
+ @base_klass.delete_at( base.id )
56
+ end
57
+
58
+ # 文字列で指定した階層を移動
23
59
  def move( src_hier , dest_parent_hier )
24
60
  # dest_parent_hierがsrc_hierの子であれば(=src_hierがdest_parent_hierの先頭からの部分文字列である)何もせずエラーを返す
25
61
  escaped = Regexp.escape( src_hier )
@@ -29,12 +65,12 @@ module Arxutils
29
65
  if ret
30
66
  return false
31
67
  end
32
-
68
+
33
69
  src_row_item = @base_klass.where( name: src_hier )
34
70
  src_num = src_row_item.id
35
- # srcが子である(tblでは項目を一意に指定できる)tblでの項目を得る
71
+ # srcが子である(tblでは項目を一意に指定できる)tblでの項目を得る
36
72
  src_row = @hire_klass.find_by( child_id: src_num )
37
-
73
+
38
74
  dest_parent_row_item = @base_klass.find_by( name: dest_parent_hier )
39
75
  unless dest_parent_row_item
40
76
  dest_parent_num = register( dest_parent_hier )
@@ -42,20 +78,22 @@ module Arxutils
42
78
  dest_parent_num = dest_parent_row_item.id
43
79
  end
44
80
  dest_parent_level = get_level_by_child( dest_parent_num )
45
-
81
+
46
82
  # srcの親をdest_parentにする
47
83
  src_row.parent_id = dest_parent_num
48
-
84
+ src_row.save
49
85
  # destに移動後のsrcの子のレベルを調整する
50
86
  level_adjust( src_row , dest_parent_level )
51
87
  # destに移動後のsrcのhierを再設定
52
88
  set_hier( src_row_item , make_hier( dest_parent_row_item.name , get_name( src_row_item ) ) )
89
+ src_row_item.save
53
90
  # destに移動後のsrcの子のhierを調整する
54
91
  hier_adjust( src_row_item )
55
92
 
56
93
  true
57
94
  end
58
95
 
96
+ # 配列で指定した階層を親の階層としてhier_klassに登録
59
97
  def register_parent( hier_ary , child_num , level )
60
98
  hier_ary.pop
61
99
  parent_hier_ary = hier_ary
@@ -64,13 +102,13 @@ module Arxutils
64
102
  hs = { parent_id: parent_num , child_id: child_num , level: level }
65
103
  @hier_klass.create( hs )
66
104
  end
67
-
105
+
106
+ # 文字列で指定した階層(/を区切り文字として持つ)をhier_klassに登録
68
107
  def register( hier )
69
108
  hier_ary = hier.split('/')
70
109
  level = get_level_by_array( hier_ary )
71
110
 
72
111
  # もしhier_aryがnilだけを1個持つ配列、または空文字列だけを1個もつ配列であれば、hier_nameは空文字列になる
73
-
74
112
  item_row = @current_klass.find_by( {@hier_symbol => hier} )
75
113
  unless item_row
76
114
  # @base_klassがhierだけでcreateできる場合は(他にフィールドがnot_nullでないか)、ここに来てもよい。
@@ -101,42 +139,47 @@ module Arxutils
101
139
  end
102
140
  new_num
103
141
  end
104
-
142
+
105
143
  private
106
-
144
+
145
+ # IDで指定した階層を削除
107
146
  def delete_at( num )
108
147
  # 子として探す
109
- row = @hier_klass.find_by( child_id: num )
110
- level = row.level
111
- parent_id = row.parent_id
112
- row_item = @base_klass.find( num )
113
-
114
- parent_item_row = @base_klass.find( parent_id )
115
- parent_hier = parent_item_row.name
148
+ hier = @hier_klass.find_by( child_id: num )
149
+ level = hier.level
150
+ parent_id = hier.parent_id
151
+ base = @base_klass.find_by( ord_id: num )
152
+
153
+ parent_base = @base_klass.find_by( ord_id: parent_id )
154
+ parent_hier_string = parent_base.__send__ @hier_symbol
116
155
 
117
156
  # 属する子を探す
118
- child_rows = @hier_klass.where( parent_id: num )
157
+ children_hier = @hier_klass.where( parent_id: num )
119
158
  # 属する子の階層レベルを調整する(削除するのでlevel - 1になる)
120
- child_rows.map{ |x| level_adjust( x , level - 1 ) }
159
+ children_hier.map{ |x| level_adjust( x , level - 1 ) }
121
160
  # 属する子の親を、親の親にする
122
- child_rows.map{ |x|
161
+ children_hier.map{ |x|
123
162
  x.parent_id = parent_id
163
+ x.save
124
164
  }
125
165
  # 属する子のhierを調整する
126
- child_rows.map{ |x|
127
- child_item_row = @base_klass.find( x.child_id )
128
- name = get_name( child_item_row )
129
- child_item_row.name = make_hier( parent_hier , name )
130
- hier_adjust( child_item_row )
166
+ children_hier.map{ |x|
167
+ child_base = @base_klass.find_by( org_id: x.child_id )
168
+ name = get_name( child_base )
169
+ child_base.hier = make_hier( parent_hier , name )
170
+ child_base.save
171
+ hier_adjust( child_base )
131
172
  }
132
173
  end
133
174
 
175
+ # 配列で指定した階層のレベルを得る
134
176
  def get_level_by_array( hier_ary )
135
177
  level = hier_ary.size - 1
136
178
  level = 0 if level < 0
137
179
  level
138
180
  end
139
181
 
182
+ # 階層を表すデータ構造から階層の名前を得る
140
183
  def get_name( items_row )
141
184
  name = ""
142
185
  if items_row
@@ -145,34 +188,39 @@ module Arxutils
145
188
  name
146
189
  end
147
190
 
148
- def hier_adjust( item_row )
149
- parent_hier = item_row.name
150
- parent_num = item_row.id
191
+ # 階層を表すデータ構造で指定された階層の下部階層の名前を調整する
192
+ def hier_adjust( base )
193
+ parent_hier_string = base.__send__ @hier_symbol
194
+ parent_num = base.org_id
151
195
 
152
196
  tbl_rows = @hier_klass.where( parent_id: parent_num )
153
197
  if tbl_rows.size > 0
154
198
  tbl_rows.map{|x|
155
199
  child_num = x.child_id
156
- item_row = @base_klass.find( child_num )
157
- item_row.name = make_hier( parent_hier , get_name( item_row ) )
200
+ item_row = @base_klass.find_by( org_id: child_num )
201
+ item_row.hier = make_hier( parent_hier_string , get_name( item_row ) )
202
+ item_row.save
158
203
  hier_adjust( item_row )
159
204
  }
160
205
  end
161
206
  end
162
-
207
+
163
208
  # 指定項目と、その子のlevelを調整
164
209
  def level_adjust( row , parent_level )
165
210
  row.level = parent_level + 1
211
+ row.save
166
212
  child_rows = @hier_klass.where( parent_id: row.id )
167
213
  if child_rows.size > 0
168
214
  child_rows.map{ |x| level_adjust( x , row.level ) }
169
215
  end
170
- end
216
+ end
171
217
 
218
+ # IDで指定された階層のレベルを得る
172
219
  def get_level_by_child( num )
173
220
  @hier_klass.find_by( child_id: num ).level
174
221
  end
175
222
 
223
+ # 文字列で指定された親の階層の下の子の名前から、子の名前を作成
176
224
  def make_hier( parent_hier , name )
177
225
  [ parent_hier , name ].join('/')
178
226
  end
@@ -6,30 +6,39 @@ require 'active_support'
6
6
  require 'active_record'
7
7
  require 'pp'
8
8
 
9
+ # ActiveRecord用ユーティリティモジュール
9
10
  module Arxutils
11
+ ##
12
+ # migrateに必要なファイルをテンプレートから作成し、migarteを実行する
10
13
  class Migrate
11
- attr_accessor :dbinit , :dbconfig_dest_path , :dbconfig_dest_fname , :dbconfig_src_path , :dbconfig_src_fname
12
-
13
- def Migrate.migrate( data_ary , relation_def_fpath , module_name, count_classname_downcase , count_field , dbconfig , forced )
14
- src_config_dir = Arxutils.configdir
15
- mig = Migrate.new( Dbutil::MIGRATE_DIR , src_config_dir , dbconfig, Dbutil::DATABASELOG, forced )
16
- # dbconfigのテンプレートは内容が固定である。convertを呼び出し、Arxのインスタンスを作成するときに、適切なdata_aryの要素を与える必要がある(ただしテンプレートへの埋め込みには用いられない
17
- mig.make_dbconfig( dbconfig )
18
-
19
- data_ary.reduce(0) { |next_num , x|
20
- mig.make( next_num , x )
21
- }
14
+ # migrate用スクリプトファイル名の先頭の番号の間隔
15
+ FILENAME_COUNTER_STEP = 10
22
16
 
23
- content_array = data_ary.map { |x|
24
- mig.make_relation( x , "count", "end_count_id" )
25
- }.select{ |x| x.size > 0 }
26
- need_count_class_plural = content_array.reduce([]){ |s,x|
27
- s << x[:need_count_class_plural] if x[:need_count_class_plural] != nil
28
- s
17
+ # migrateに必要なファイルをテンプレートから作成し、migarteを実行する
18
+ def self.migrate( db_dir , src_config_dir , log_fname, migrate_dir, env, db_scheme_ary , dbconfig , opts )
19
+ log_file_name = sprintf("%s-%s" , dbconfig.to_s , log_fname )
20
+ mig = Migratex.new( db_dir , migrate_dir , src_config_dir , dbconfig, env, log_file_name, opts )
21
+ # DB構成情報の生成
22
+ # dbconfigのテンプレートは内容が固定である。
23
+ if( opts["makeconfig"] )
24
+ mig.make_dbconfig( opts )
25
+ return
26
+ end
27
+ # スキーマ設定配列から、migrate用のスクリプトを作成する
28
+ db_scheme_ary.map{ |x| mig.make_script_group(x) }.flatten(1).each_with_index{|data , index|
29
+ idy = (index + 1) * FILENAME_COUNTER_STEP
30
+ mig.output_script( idy , *data )
29
31
  }
30
- if content_array.size > 0
32
+ # スキーマ設定配列から、relationのmigrate用のスクリプトの内容(ハッシュ形式)の配列を作成する
33
+ content_array = db_scheme_ary.map { |x|
34
+ mig.make_relation( x , "count" )
35
+ }.select{ |x| x.size > 0 }
36
+ # 複数形のクラス名を集める
37
+ need_count_class_plural = content_array.select{ |x| x[:need_count_class_plural] != nil }.map{ |x| x[:need_count_class_plural] }
38
+
39
+ # relationのmigrateが必要であれば、それをテンプレートファイルから作成して、スクリプトの内容として追加する
40
+ if content_array.find{|x| x != nil}
31
41
  data_count = {count_classname: "Count" ,
32
- count_field: count_field,
33
42
  need_count_class_plural: need_count_class_plural,
34
43
  }
35
44
  ary = content_array.collect{|x| x[:content] }.flatten
@@ -37,89 +46,123 @@ module Arxutils
37
46
  ary.unshift( count_content )
38
47
  content_array = ary
39
48
  end
40
- File.open( relation_def_fpath , 'w' , {:encoding => Encoding::UTF_8}){ |f|
41
- f.puts("module #{module_name}")
42
- content_array.map{ |content|
43
- f.puts( content )
44
- f.puts( "\n" )
45
- }
46
- f.puts("end")
47
- }
48
-
49
- Dbutil::DbMgr.setup( mig.dbinit )
49
+ # relationのスクリプトを作成
50
+ mig.output_relation_script( content_array , opts[:relation] )
50
51
 
52
+ # データベース接続とログ設定
53
+ ::Arxutils::Dbutil::DbMgr.setup( mig.dbinit )
54
+
55
+ # migrateを実行する
51
56
  mig.migrate
52
57
  end
53
-
54
- def initialize( migrate_base_dir , config_dir , dbconfig, log_fname, forced = false )
55
- @dbinit = Dbutil::Dbinit.new( migrate_base_dir , config_dir , dbconfig, log_fname, forced )
56
- @dbconfig_dest_path = @dbinit.dbconfig_dest_path
57
- @dbconfig_src_path = @dbinit.dbconfig_src_path
58
- @dbconfig_src_fname = @dbinit.dbconfig_src_fname
59
-
60
- @migrate_dir = @dbinit.migrate_dir
61
- @src_path = Arxutils.templatedir
62
- @src_config_path = Arxutils.configdir
63
- end
64
58
 
65
- def convert_count_class_relation( data , src_fname )
66
- convert( data , @src_path , src_fname )
67
- end
59
+ # migrate用のスクリプトの内容をテンプレートから作成し、ファイルに出力し、migrateを実行する
60
+ class Migratex
61
+ # DB接続までの初期化を行うDbinitクラスのインスタンス
62
+ attr_reader :dbinit
68
63
 
69
- def convert( data , src_dir , src_fname )
70
- arx = Arx.new( data , File.join( src_dir, src_fname ) )
71
- arx.create
72
- end
73
-
74
- def make_dbconfig( data )
75
- content = convert( data , @src_config_path , @dbconfig_src_fname )
76
- File.open( @dbconfig_dest_path , 'w' , {:encoding => Encoding::UTF_8}){ |f|
77
- f.puts( content )
78
- }
79
- end
64
+ # migrate用のスクリプトの生成、migrateの実行を行うmigratexの生成
65
+ def initialize( db_dir , migrate_base_dir , src_config_dir , dbconfig, env, log_fname, opts )
66
+ # DB接続までの初期化を行うDbinitクラスのインスタンス
67
+ @dbinit = Dbutil::Dbinit.new( db_dir , migrate_base_dir , src_config_dir , dbconfig, env, log_fname, opts )
68
+ # 生成するDB構成情報ファイルパス
69
+ @dbconfig_dest_path = @dbinit.dbconfig_dest_path
70
+ # 参照用DB構成情報ファイル名
71
+ @dbconfig_src_fname = @dbinit.dbconfig_src_fname
80
72
 
81
- def make_relation( data , count_classname_downcase , count_field )
82
- if data[:classname_downcase] != count_classname_downcase
83
- data[:flist].reduce( { content: [], need_count_class: nil } ){ |s, x|
84
- case x
85
- when "base" , "noitem"
86
- name_base = "relation"
87
- data[:relation] = [] unless data[:relation]
88
- else
89
- data[:count_classname_downcase] = count_classname_downcase
90
- data[:count_field] = count_field
91
- name_base = "relation_#{x}"
92
- s[:need_count_class_plural] ||= data[:plural]
93
- end
94
- content = convert( data , @src_path , "#{name_base}.tmpl" )
95
- s[:content] << content
96
- s
73
+ # migrate用スクリプトの出力先ディレクトリ名
74
+ @migrate_dir = @dbinit.migrate_dir
75
+ # テンプレートファイル格納ディレクトリ名
76
+ @src_path = Arxutils.templatedir
77
+ # 構成ファイル格納ディレクトリ
78
+ @src_config_path = Arxutils.configdir
79
+ end
80
+
81
+ # Countクラス用のrelationのスクリプトの内容に変換
82
+ def convert_count_class_relation( data , src_fname )
83
+ convert( data , @src_path , src_fname )
84
+ end
85
+
86
+ # テンプレートファイルからスクリプトの内容に変換
87
+ def convert( data , src_dir , src_fname )
88
+ arx = Arx.new( data , File.join( src_dir, src_fname ) )
89
+ # 指定テンプレートファイルからスクリプトの内容に作成
90
+ arx.create
91
+ end
92
+
93
+ # データベース構成ファイルをテンプレートから生成する
94
+ def make_dbconfig( data )
95
+ content = convert( data , @src_config_path , @dbconfig_src_fname )
96
+ File.open( @dbconfig_dest_path , 'w' , {:encoding => Encoding::UTF_8}){ |f|
97
+ f.puts( content )
97
98
  }
98
- else
99
- {}
100
99
  end
101
- end
102
-
103
- def make( next_num , data )
104
- data[:flist].reduce(next_num) do |idy , x|
105
- idy += 10
106
- content = convert( data , @src_path , "#{x}.tmpl" )
107
- case x
108
- when "base" , "noitem"
109
- additional = ""
100
+
101
+ # 英子文字で表現したクラス名が、countを表していなければ、relationを
102
+ # 英子文字で表現したクラス名が、countを表していれが、空のハッシュを返す
103
+ # スキーマでbase, noitem以外のフィールドが指定されていれば、そのフィールドに対するrelationの設定の内容を返す
104
+ def make_relation( data , count_classname_downcase )
105
+ if data[:classname_downcase] != count_classname_downcase
106
+ # 指定フィールドのフィールド名に対応したテンプレートファイルを用いて、relation設定を作成
107
+ data[:flist].reduce( { content: [], need_count_class: nil } ){ |s, field_name|
108
+ case field_name
109
+ when "base" , "noitem"
110
+ name_base = "relation"
111
+ # data[:relation]がnilに設定されていたら改めて空の配列を設定
112
+ data[:relation] = [] unless data[:relation]
113
+ else
114
+ data[:count_classname_downcase] = count_classname_downcase
115
+ name_base = "relation_#{field_name}"
116
+ s[:need_count_class_plural] ||= data[:plural]
117
+ end
118
+ # テンプレートファイルからスクリプトの内容を作成
119
+ content = convert( data , @src_path , "#{name_base}.tmpl" )
120
+ s[:content] << content
121
+ s
122
+ }
110
123
  else
111
- additional = x
124
+ {}
112
125
  end
113
- fname = File.join( @migrate_dir , sprintf("%03d_create_%s%s.rb" , idy , additional , data[:classname_downcase]) )
114
- File.open( fname , 'w' , {:encoding => Encoding::UTF_8}){ |f|
115
- f.puts( content )
126
+ end
127
+
128
+ # スキーマ設定からmigarte用スクリプトの内容を生成
129
+ def make_script_group( data )
130
+ data[:flist].map{ |kind| [kind, convert( data , @src_path , "#{kind}.tmpl" ), data[:classname_downcase]]}
131
+ end
132
+
133
+ # migrationのスクリプトをファイル出力する
134
+ def output_script( idy, kind , content , classname_downcase )
135
+ case kind
136
+ when "base" , "noitem"
137
+ additional = ""
138
+ else
139
+ additional = kind
140
+ end
141
+ fname = File.join( @migrate_dir , sprintf("%03d_create_%s%s.rb" , idy , additional , classname_downcase) )
142
+ File.open( fname , 'w' , **{:encoding => Encoding::UTF_8}){ |f|
143
+ f.puts( content )
144
+ }
145
+ end
146
+
147
+ # relationのスクリプトをファイル出力する
148
+ def output_relation_script( content_array , opts )
149
+ dir = opts[:dir]
150
+ fname = opts[:filename]
151
+ fpath = File.join( dir , fname )
152
+ File.open( fpath , "w" ){ |file|
153
+ opts[:module].map{|mod| file.puts("module #{mod}")}
154
+ content_array.map{|x|
155
+ file.puts x
156
+ file.puts ""
157
+ }
158
+ opts[:module].map{|mod| file.puts("end")}
116
159
  }
117
- idy
118
160
  end
119
- end
120
161
 
121
- def migrate
122
- ActiveRecord::Migrator.migrate(@migrate_dir , ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
162
+ # migrateを実行する
163
+ def migrate
164
+ ActiveRecord::Migrator.migrate(@migrate_dir , ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
165
+ end
123
166
  end
124
167
  end
125
168
  end
@@ -1,51 +1,68 @@
1
1
  module Arxutils
2
+ # 簡易的なトランザクション処理
2
3
  class TransactState
3
- attr_accessor :ids , :state
4
-
4
+ # 対象ID群
5
+ attr_reader :ids
6
+ # 状態
7
+ attr_accessor :state
8
+
9
+ #初期化
5
10
  def initialize
11
+ # 対象ID群
6
12
  @ids = []
13
+ # 状態
7
14
  @state = :NONE
8
15
  end
9
16
 
17
+ # :TRACE状態の時のみ対象IDとして追加
10
18
  def add( xid )
11
19
  @ids << xid if @state == :TRACE
12
20
  end
13
21
 
22
+ # 対象ID群をクリア
14
23
  def clear
15
24
  @ids = []
16
25
  end
17
26
 
27
+ # 処理の必要性の確認
18
28
  def need?
19
29
  @ids.size > 0
20
30
  end
21
31
 
22
32
  end
23
33
 
34
+ # 複数の簡易的なトランザクション処理
24
35
  class TransactStateGroup
36
+ # 初期化
25
37
  def initialize( *names )
26
38
  @state = :NONE
27
39
  @inst = {}
28
40
  names.map{|x| @inst[x] = TransactState.new }
29
41
  end
30
-
42
+
43
+ # 処理の必要性の確認
31
44
  def need?
32
45
  @state != :NONE
33
46
  end
34
-
47
+
48
+ # 状態の一括設定
35
49
  def set_all_inst_state
36
50
  @inst.map{|x| x[1].state = @state }
37
51
  end
38
-
52
+
53
+ # 状態を:TRACEに一括設定
39
54
  def trace
40
55
  @state = :TRACE
41
56
  set_all_inst_state
42
57
  end
43
-
58
+
59
+ # 状態を:NONEに一括設定
44
60
  def reset
45
61
  @state = :NONE
46
62
  set_all_inst_state
47
63
  end
48
-
64
+
65
+ # 指定名の状態を返す
49
66
  def method_missing(name , lang = nil)
50
67
  @inst[name]
51
68
  end
@@ -1,3 +1,4 @@
1
1
  module Arxutils
2
- VERSION = "0.1.35"
2
+ # バージョン番号
3
+ VERSION = "0.1.38"
3
4
  end
data/lib/arxutils.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'bigdecimal'
1
2
  require 'active_support'
2
3
  require 'active_support/core_ext'
3
4
  require 'active_record'
@@ -6,14 +7,9 @@ require 'arxutils/arxutils'
6
7
  require 'arxutils/arx'
7
8
  require 'arxutils/transactstate'
8
9
  require 'arxutils/hier'
9
- require 'arxutils/misc'
10
10
  require 'arxutils/dbutil/dbinit'
11
11
  require 'arxutils/dbutil/dbmgr'
12
- require 'arxutils/store'
13
- require 'arxutils/store/storedb'
14
- require 'arxutils/store/storecsv'
15
12
  require 'arxutils/migrate'
16
13
 
17
-
18
14
  module Arxutils
19
15
  end
@@ -1,5 +1,5 @@
1
- # SQLite version 3.x
2
- # gem install sqlite3
1
+ # MySQL
2
+ # gem install mysql2
3
3
  #
4
4
  # Ensure the SQLite 3 gem is defined in your Gemfile
5
5
  # gem 'sqlite3'
@@ -7,7 +7,7 @@
7
7
  default_env: &default
8
8
  adapter: mysql2
9
9
  host: localhost
10
- username: root
10
+ username:
11
11
  password:
12
12
  database: <%= @data[:dbname] %>
13
13
  pool: 5
@@ -1,3 +1,3 @@
1
1
  class <%= @data[:classname] %> < ActiveRecord::Base
2
2
  <% @data[:relation].each do |x| %> <%= x %>
3
- <% end %> end
3
+ <% end %> end
@@ -1,4 +1,3 @@
1
1
  class <%= @data[:count_classname] %> < ActiveRecord::Base
2
2
  <% @data[:need_count_class_plural].each do |x| %> has_many :invalid<%= x %>
3
3
  <% end %> end
4
-
@@ -1,3 +1,3 @@
1
1
  class Current<%= @data[:classname_downcase] %> < ActiveRecord::Base
2
2
  belongs_to :<%= @data[:classname_downcase] %> , foreign_key: 'org_id'
3
- end
3
+ end
@@ -1,4 +1,4 @@
1
1
  class Invalid<%= @data[:classname_downcase] %> < ActiveRecord::Base
2
2
  belongs_to :<%= @data[:classname_downcase] %> , foreign_key: 'org_id'
3
3
  belongs_to :<%= @data[:count_classname_downcase] %> , foreign_key: '<%= @data[:count_field] %>'
4
- end
4
+ end
metadata CHANGED
@@ -1,31 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arxutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.35
4
+ version: 0.1.38
5
5
  platform: ruby
6
6
  authors:
7
7
  - yasuo kominami
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-12 00:00:00.000000000 Z
11
+ date: 2022-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activesupport
14
+ name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "<"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '7.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "<"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '7.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: activerecord
28
+ name: sqlite3
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: sqlite3
42
+ name: mysql2
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -70,30 +70,30 @@ dependencies:
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '1.10'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '1.10'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '10.0'
89
+ version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '10.0'
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rspec
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: utility functions for ActiveRecord.
112
126
  email:
113
127
  - ykominami@gmail.com
@@ -120,8 +134,10 @@ files:
120
134
  - ".rspec"
121
135
  - ".travis.yml"
122
136
  - Gemfile
137
+ - Gemfile.lock
123
138
  - README.md
124
139
  - Rakefile
140
+ - SECURITY.md
125
141
  - arxutils.gemspec
126
142
  - bin/console
127
143
  - bin/setup
@@ -133,10 +149,6 @@ files:
133
149
  - lib/arxutils/dbutil/dbmgr.rb
134
150
  - lib/arxutils/hier.rb
135
151
  - lib/arxutils/migrate.rb
136
- - lib/arxutils/misc.rb
137
- - lib/arxutils/store.rb
138
- - lib/arxutils/store/storecsv.rb
139
- - lib/arxutils/store/storedb.rb
140
152
  - lib/arxutils/transactstate.rb
141
153
  - lib/arxutils/version.rb
142
154
  - lib/config/mysql.tmpl
@@ -152,7 +164,7 @@ files:
152
164
  homepage: ''
153
165
  licenses: []
154
166
  metadata: {}
155
- post_install_message:
167
+ post_install_message:
156
168
  rdoc_options: []
157
169
  require_paths:
158
170
  - lib
@@ -167,9 +179,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
179
  - !ruby/object:Gem::Version
168
180
  version: '0'
169
181
  requirements: []
170
- rubyforge_project:
171
- rubygems_version: 2.6.4
172
- signing_key:
182
+ rubygems_version: 3.3.7
183
+ signing_key:
173
184
  specification_version: 4
174
185
  summary: utility functions for ActiveRecord.
175
186
  test_files: []
data/lib/arxutils/misc.rb DELETED
@@ -1,44 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- module Arxutils
4
- def load_file( in_file )
5
- File.open( in_file , "r" , { :encoding => 'UTF-8' } )
6
- end
7
-
8
- def normalize_to_integer( *args )
9
- args.map{ |x|
10
- if x != nil and x !~ /^\s*$/
11
- x.to_i
12
- else
13
- nil
14
- end
15
- }
16
- end
17
-
18
- def update_integer( model , hs )
19
- value_hs = hs.reduce({}){ |hsx,item|
20
- val = model.send(item[0])
21
- if val == nil or val < item[1]
22
- hsx[ item[0] ] = item[1]
23
- end
24
- hsx
25
- }
26
- if value_hs.size > 0
27
- begin
28
- model.update(value_hs)
29
- rescue => ex
30
- puts ex.message
31
- end
32
- end
33
- end
34
-
35
- def capture_queries(&block)
36
- queries = []
37
- ActiveSupport::Notifications.subscribe('sql.active_record') do |_name, _start, _finish, _id, payload|
38
- queries << payload
39
- end
40
- yield block
41
- ActiveSupport::Notifications.unsubscribe('sql.active_record')
42
- queries
43
- end
44
- end
@@ -1,18 +0,0 @@
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
-
@@ -1,25 +0,0 @@
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["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
@@ -1,22 +0,0 @@
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