ca-data_store-ar 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +143 -0
- data/README.md +35 -0
- data/Rakefile +18 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/ca-data_store-ar.gemspec +51 -0
- data/exe/ar-migrate +10 -0
- data/lib/ca/data_store/ar/console_helper.rb +21 -0
- data/lib/ca/data_store/ar/migration/migration_helper.rb +89 -0
- data/lib/ca/data_store/ar/model_base.rb +18 -0
- data/lib/ca/data_store/ar/provider.rb +71 -0
- data/lib/ca/data_store/ar/version.rb +9 -0
- data/lib/ca/data_store/ar.rb +96 -0
- data/spec_test.db +0 -0
- data/tasks/cads_db_ar.rake +50 -0
- metadata +172 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e3e8938a7a318d55a5adb03552302987fba2cbc105a6a8c29d6725f13e862bd7
|
4
|
+
data.tar.gz: 7e2d43ea21124098a2fc519daac37f2e0a92d3a2db609bfabe5219c9290ea282
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6150ce8d0a0bec4c620ba3cbaaadcebb480588044f69d6975617d786ede572817532ad97f780175858f80505076592e075c022021502c57fecfab32107392a2f
|
7
|
+
data.tar.gz: e688d93aa01a1e2b4be21a62416129589b8fd15bf14ad648ee11a1020c012ca47895951da2ac632509d9c5064ba2d9de0feac61f23f511b9aa578543c2532ef3
|
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in ca-data_store-ar.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 13.0"
|
9
|
+
|
10
|
+
gem "rspec", "~> 3.0"
|
11
|
+
|
12
|
+
#gem 'ca-data_store', git: 'ca-data_store', branch: "master"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ca-data_store-ar (0.1.0)
|
5
|
+
activerecord
|
6
|
+
activesupport
|
7
|
+
ca-data_store
|
8
|
+
standalone_migrations
|
9
|
+
teLogger
|
10
|
+
toolrack
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: https://rubygems.org/
|
14
|
+
specs:
|
15
|
+
actionpack (7.0.3.1)
|
16
|
+
actionview (= 7.0.3.1)
|
17
|
+
activesupport (= 7.0.3.1)
|
18
|
+
rack (~> 2.0, >= 2.2.0)
|
19
|
+
rack-test (>= 0.6.3)
|
20
|
+
rails-dom-testing (~> 2.0)
|
21
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
22
|
+
actionview (7.0.3.1)
|
23
|
+
activesupport (= 7.0.3.1)
|
24
|
+
builder (~> 3.1)
|
25
|
+
erubi (~> 1.4)
|
26
|
+
rails-dom-testing (~> 2.0)
|
27
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
28
|
+
activemodel (7.0.3.1)
|
29
|
+
activesupport (= 7.0.3.1)
|
30
|
+
activerecord (7.0.3.1)
|
31
|
+
activemodel (= 7.0.3.1)
|
32
|
+
activesupport (= 7.0.3.1)
|
33
|
+
activesupport (7.0.3.1)
|
34
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
35
|
+
i18n (>= 1.6, < 2)
|
36
|
+
minitest (>= 5.1)
|
37
|
+
tzinfo (~> 2.0)
|
38
|
+
base58 (0.2.3)
|
39
|
+
builder (3.2.4)
|
40
|
+
ca-data_store (0.1.0)
|
41
|
+
teLogger
|
42
|
+
toolrack
|
43
|
+
concurrent-ruby (1.1.10)
|
44
|
+
crass (1.0.6)
|
45
|
+
devops_assist (0.3.0)
|
46
|
+
git_cli
|
47
|
+
git_cli_prompt
|
48
|
+
gvcs
|
49
|
+
teLogger
|
50
|
+
toolrack
|
51
|
+
tty-prompt
|
52
|
+
diff-lcs (1.5.0)
|
53
|
+
erubi (1.11.0)
|
54
|
+
git_cli (0.10.0)
|
55
|
+
gvcs
|
56
|
+
ptools (~> 1.4.0)
|
57
|
+
teLogger
|
58
|
+
toolrack
|
59
|
+
git_cli_prompt (0.3.1)
|
60
|
+
teLogger
|
61
|
+
toolrack
|
62
|
+
tty-prompt
|
63
|
+
gvcs (0.1.0)
|
64
|
+
i18n (1.12.0)
|
65
|
+
concurrent-ruby (~> 1.0)
|
66
|
+
loofah (2.18.0)
|
67
|
+
crass (~> 1.0.2)
|
68
|
+
nokogiri (>= 1.5.9)
|
69
|
+
method_source (1.0.0)
|
70
|
+
minitest (5.16.2)
|
71
|
+
nokogiri (1.13.8-x86_64-linux)
|
72
|
+
racc (~> 1.4)
|
73
|
+
pastel (0.8.0)
|
74
|
+
tty-color (~> 0.5)
|
75
|
+
ptools (1.4.2)
|
76
|
+
racc (1.6.0)
|
77
|
+
rack (2.2.4)
|
78
|
+
rack-test (2.0.2)
|
79
|
+
rack (>= 1.3)
|
80
|
+
rails-dom-testing (2.0.3)
|
81
|
+
activesupport (>= 4.2.0)
|
82
|
+
nokogiri (>= 1.6)
|
83
|
+
rails-html-sanitizer (1.4.3)
|
84
|
+
loofah (~> 2.3)
|
85
|
+
railties (7.0.3.1)
|
86
|
+
actionpack (= 7.0.3.1)
|
87
|
+
activesupport (= 7.0.3.1)
|
88
|
+
method_source
|
89
|
+
rake (>= 12.2)
|
90
|
+
thor (~> 1.0)
|
91
|
+
zeitwerk (~> 2.5)
|
92
|
+
rake (13.0.6)
|
93
|
+
rspec (3.11.0)
|
94
|
+
rspec-core (~> 3.11.0)
|
95
|
+
rspec-expectations (~> 3.11.0)
|
96
|
+
rspec-mocks (~> 3.11.0)
|
97
|
+
rspec-core (3.11.0)
|
98
|
+
rspec-support (~> 3.11.0)
|
99
|
+
rspec-expectations (3.11.0)
|
100
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
101
|
+
rspec-support (~> 3.11.0)
|
102
|
+
rspec-mocks (3.11.1)
|
103
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
104
|
+
rspec-support (~> 3.11.0)
|
105
|
+
rspec-support (3.11.0)
|
106
|
+
sqlite3 (1.4.4)
|
107
|
+
standalone_migrations (7.1.0)
|
108
|
+
activerecord (>= 4.2.7, < 7.1.0, != 5.2.3.rc1, != 5.2.3)
|
109
|
+
railties (>= 4.2.7, < 7.1.0, != 5.2.3.rc1, != 5.2.3)
|
110
|
+
rake (>= 10.0)
|
111
|
+
teLogger (0.2.0)
|
112
|
+
thor (1.2.1)
|
113
|
+
tlogger (0.26.3)
|
114
|
+
toolrack (0.18.6)
|
115
|
+
base58
|
116
|
+
tlogger
|
117
|
+
tty-color (0.6.0)
|
118
|
+
tty-cursor (0.7.1)
|
119
|
+
tty-prompt (0.23.1)
|
120
|
+
pastel (~> 0.8)
|
121
|
+
tty-reader (~> 0.8)
|
122
|
+
tty-reader (0.9.0)
|
123
|
+
tty-cursor (~> 0.7)
|
124
|
+
tty-screen (~> 0.8)
|
125
|
+
wisper (~> 2.0)
|
126
|
+
tty-screen (0.8.1)
|
127
|
+
tzinfo (2.0.4)
|
128
|
+
concurrent-ruby (~> 1.0)
|
129
|
+
wisper (2.0.1)
|
130
|
+
zeitwerk (2.6.0)
|
131
|
+
|
132
|
+
PLATFORMS
|
133
|
+
x86_64-linux
|
134
|
+
|
135
|
+
DEPENDENCIES
|
136
|
+
ca-data_store-ar!
|
137
|
+
devops_assist
|
138
|
+
rake (~> 13.0)
|
139
|
+
rspec (~> 3.0)
|
140
|
+
sqlite3
|
141
|
+
|
142
|
+
BUNDLED WITH
|
143
|
+
2.2.28
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Ca::DataStore::Ar
|
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/ca/data_store/ar`. 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 'ca-data_store-ar'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ca-data_store-ar
|
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 spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
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 the created tag, 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]/ca-data_store-ar.
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
|
6
|
+
require 'devops_assist'
|
7
|
+
|
8
|
+
RSpec::Core::RakeTask.new(:spec)
|
9
|
+
|
10
|
+
#require 'standalone_migrations'
|
11
|
+
##ENV["SCHEMA"] = File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, "schema.rb")
|
12
|
+
#ENV["SCHEMA"] = ''
|
13
|
+
#StandaloneMigrations::Tasks.load_tasks
|
14
|
+
|
15
|
+
require_relative './lib/ca/data_store/ar'
|
16
|
+
Ca::DataStore::Ar.load_tasks
|
17
|
+
|
18
|
+
task default: :spec
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "ca/data_store/ar"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/ca/data_store/ar/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "ca-data_store-ar"
|
7
|
+
spec.version = Ca::DataStore::Ar::VERSION
|
8
|
+
spec.authors = ["Ian"]
|
9
|
+
spec.email = ["cameronian0@protonmail.com"]
|
10
|
+
|
11
|
+
spec.summary = ""
|
12
|
+
spec.description = ""
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.required_ruby_version = ">= 2.4.0"
|
15
|
+
|
16
|
+
#spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
17
|
+
|
18
|
+
#spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
#spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
20
|
+
#spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
27
|
+
end
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_dependency 'teLogger'
|
34
|
+
spec.add_dependency 'toolrack'
|
35
|
+
|
36
|
+
spec.add_dependency 'activerecord'
|
37
|
+
spec.add_dependency 'activesupport'
|
38
|
+
|
39
|
+
spec.add_dependency "standalone_migrations"
|
40
|
+
|
41
|
+
spec.add_dependency 'ca-data_store'
|
42
|
+
|
43
|
+
spec.add_development_dependency "sqlite3"
|
44
|
+
spec.add_development_dependency "devops_assist"
|
45
|
+
|
46
|
+
# Uncomment to register a new dependency of your gem
|
47
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
48
|
+
|
49
|
+
# For more information and examples about making a new gem, checkout our
|
50
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
51
|
+
end
|
data/exe/ar-migrate
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
module Ca
|
5
|
+
module DataStore
|
6
|
+
module Ar
|
7
|
+
module MigrationHelper
|
8
|
+
include TR::CondUtils
|
9
|
+
include TeLogger::TeLogHelper
|
10
|
+
teLogger_tag :ar_mig
|
11
|
+
|
12
|
+
def default_migration_path
|
13
|
+
ActiveRecord::Migrator.migrations_paths.first.freeze
|
14
|
+
#'./db/migrate'.freeze
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_db(conf)
|
18
|
+
ActiveRecord::Base.establish_connection(conf)
|
19
|
+
|
20
|
+
ActiveRecord::Base.connection.create_database(conf['database']) if ActiveRecord::Base.connection.respond_to?(:create_database)
|
21
|
+
end
|
22
|
+
|
23
|
+
def migrate(conf)
|
24
|
+
ActiveRecord::Base.establish_connection(conf)
|
25
|
+
|
26
|
+
migPath = conf[:migration_spec_path] || File.expand_path(default_migration_path)
|
27
|
+
raise MigrateError, "Given migration spec path '#{migPath}' does not exist." if not File.exist?(migPath)
|
28
|
+
|
29
|
+
teLogger.debug "Migration spec path : #{migPath}"
|
30
|
+
# for AR <= 4
|
31
|
+
#ActiveRecord::Migrator.migrate(migPath)
|
32
|
+
# for AR >= 5
|
33
|
+
ActiveRecord::Base.connection.migration_context.migrate
|
34
|
+
dump_schema(conf)
|
35
|
+
end
|
36
|
+
|
37
|
+
def dump_schema(conf)
|
38
|
+
ActiveRecord::Base.establish_connection(conf)
|
39
|
+
require 'active_record/schema_dumper'
|
40
|
+
schemaDumpOut = conf[:schema_dump_path] || File.expand_path('./schema.rb')
|
41
|
+
File.open(schemaDumpOut,"w:utf-8") do |f|
|
42
|
+
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, f)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def drop_db(conf)
|
47
|
+
ActiveRecord::Base.establish_connection(conf)
|
48
|
+
ActiveRecord::Base.connection.drop_database(conf['database']) if ActiveRecord::Base.connection.respond_to?(:drop_database)
|
49
|
+
end
|
50
|
+
|
51
|
+
def generate_migration(conf, name, &block)
|
52
|
+
|
53
|
+
raise MigrateError, "Migration name is required" if is_empty?(name)
|
54
|
+
|
55
|
+
#name = "create_#{name.pluralize}"
|
56
|
+
|
57
|
+
migPath = conf[:migration_spec_path] || File.expand_path(default_migration_path)
|
58
|
+
FileUtils.mkdir_p(migPath) if not File.exist?(migPath)
|
59
|
+
|
60
|
+
timestamp = Time.now.strftime("%Y%m%d%H%M%S%6N")
|
61
|
+
# rails only take 14 characters as timestamp
|
62
|
+
timestamp = timestampt[0...14]
|
63
|
+
path = File.expand_path(File.join(migPath,"#{timestamp}_#{name}.rb"))
|
64
|
+
migration_class = name.split("_").map(&:capitalize).join
|
65
|
+
|
66
|
+
arVer = ActiveRecord.version.to_s
|
67
|
+
|
68
|
+
tv = arVer.split(".")[0..1]
|
69
|
+
|
70
|
+
File.open(path, 'w') do |file|
|
71
|
+
file.write <<-EOF
|
72
|
+
|
73
|
+
class #{migration_class} < ActiveRecord::Migration[#{tv.join('.')}]
|
74
|
+
def change
|
75
|
+
#{block ? block.call(:table_setup) : ""}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
EOF
|
79
|
+
end
|
80
|
+
|
81
|
+
teLogger.debug "Migration #{path} written"
|
82
|
+
|
83
|
+
path
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module Ca
|
4
|
+
module DataStore
|
5
|
+
module Ar
|
6
|
+
#
|
7
|
+
# just to cater the requirement for ActiveRecord
|
8
|
+
# so that each user of the library does not need
|
9
|
+
# to create this unless they want to open this class
|
10
|
+
# which in Ruby is totally up to developer
|
11
|
+
#
|
12
|
+
class Model < ActiveRecord::Base
|
13
|
+
primary_abstract_class
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
module Ca
|
5
|
+
module DataStore
|
6
|
+
module Ar
|
7
|
+
|
8
|
+
class Provider
|
9
|
+
include TR::CondUtils
|
10
|
+
|
11
|
+
include TeLogger::TeLogHelper
|
12
|
+
teLogger_tag :ar
|
13
|
+
|
14
|
+
def self.provider_name
|
15
|
+
"ActiveRecord Provider"
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.provider_key
|
19
|
+
:cads_ar
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.handle(*args, &block)
|
23
|
+
ops = args.first
|
24
|
+
case ops
|
25
|
+
when :init
|
26
|
+
conf = args[1]
|
27
|
+
ActiveRecord::Base.establish_connection(conf[:conn]) if not_empty?(conf[:conn])
|
28
|
+
ActiveRecord::Base.logger = teLogger
|
29
|
+
|
30
|
+
else
|
31
|
+
target = args[1]
|
32
|
+
params = args[2..-1]
|
33
|
+
|
34
|
+
case ops
|
35
|
+
when :save
|
36
|
+
target.save
|
37
|
+
when :delete
|
38
|
+
target.destroy
|
39
|
+
when :find
|
40
|
+
teLogger.debug "params : #{params.first}"
|
41
|
+
res = []
|
42
|
+
|
43
|
+
res = target.where(params.first) if not_empty?(params.first)
|
44
|
+
|
45
|
+
if block
|
46
|
+
res = block.call(:find_result, target, res)
|
47
|
+
end
|
48
|
+
|
49
|
+
res
|
50
|
+
when :find_all
|
51
|
+
res = target.all
|
52
|
+
if block
|
53
|
+
res = block.call(:find_all_result, target, res)
|
54
|
+
end
|
55
|
+
res
|
56
|
+
when :schema
|
57
|
+
# ignored
|
58
|
+
when :is_new_record?
|
59
|
+
target.new_record?
|
60
|
+
else
|
61
|
+
raise ProviderException, "Unknown operation '#{ops}'"
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'toolrack'
|
4
|
+
require 'teLogger'
|
5
|
+
|
6
|
+
require 'active_record'
|
7
|
+
require 'active_support'
|
8
|
+
|
9
|
+
require 'rake'
|
10
|
+
|
11
|
+
require 'ca/data_store'
|
12
|
+
|
13
|
+
require 'yaml'
|
14
|
+
|
15
|
+
require_relative "ar/version"
|
16
|
+
|
17
|
+
require_relative 'ar/provider'
|
18
|
+
|
19
|
+
require_relative 'ar/migration/migration_helper'
|
20
|
+
|
21
|
+
require_relative 'ar/model_base'
|
22
|
+
|
23
|
+
module Ca
|
24
|
+
module DataStore
|
25
|
+
module Ar
|
26
|
+
class Error < StandardError; end
|
27
|
+
class MigrateError < StandardError; end
|
28
|
+
# Your code goes here...
|
29
|
+
|
30
|
+
include TR::CondUtils
|
31
|
+
include TeLogger::TeLogHelper
|
32
|
+
teLogger_tag :ar
|
33
|
+
|
34
|
+
def Ar.load_tasks
|
35
|
+
Dir.glob(File.join(File.dirname(__FILE__),"..","..","..","tasks","*.rake")) do |rf|
|
36
|
+
fp = File.expand_path(rf)
|
37
|
+
load fp
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def Ar.load_model(path)
|
42
|
+
mpath = File.expand_path(path)
|
43
|
+
Dir.glob(File.join(mpath,"*.rb")) do |m|
|
44
|
+
require m
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def Ar.connect_database(confPath = "./config/database.yml")
|
49
|
+
# check if we are in Rails context
|
50
|
+
teLogger.debug "Root : #{root}"
|
51
|
+
if not_empty?(root)
|
52
|
+
railsConf = File.join(root, "config","database.yml")
|
53
|
+
if File.exist?(railsConf)
|
54
|
+
path = File.expand_path(railsConf)
|
55
|
+
else
|
56
|
+
path = File.expand_path(confPath)
|
57
|
+
end
|
58
|
+
|
59
|
+
else
|
60
|
+
path = File.expand_path(confPath)
|
61
|
+
end
|
62
|
+
|
63
|
+
if File.exist?(path)
|
64
|
+
File.open(path,"r") do |f|
|
65
|
+
@conf = YAML.load(f.read)
|
66
|
+
end
|
67
|
+
ActiveRecord::Base.establish_connection(@conf["development"])
|
68
|
+
else
|
69
|
+
teLogger.warn "Skipped ActiveRecord connection since config file not available"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def Ar.show_log(out = nil)
|
74
|
+
ActiveRecord::Base.logger = TeLogger::Tlogger.new(out)
|
75
|
+
end
|
76
|
+
|
77
|
+
def Ar.migration_path
|
78
|
+
File.join(File.dirname(__FILE__),"..","..","..","db","migrate")
|
79
|
+
end
|
80
|
+
|
81
|
+
def Ar.root=(root)
|
82
|
+
@arRoot = root
|
83
|
+
end
|
84
|
+
|
85
|
+
def Ar.root
|
86
|
+
@arRoot = "." if is_empty?(@arRoot)
|
87
|
+
@arRoot
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
Ca::DataStore::Provider.instance.register(Ca::DataStore::Ar::Provider)
|
96
|
+
|
data/spec_test.db
ADDED
File without changes
|
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
require 'rake'
|
3
|
+
require_relative '../lib/ca/data_store/ar'
|
4
|
+
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
class MigHelper
|
8
|
+
extend Ca::DataStore::Ar::MigrationHelper
|
9
|
+
end
|
10
|
+
|
11
|
+
namespace :cads_db_ar do
|
12
|
+
|
13
|
+
desc "Create new migration"
|
14
|
+
task :gen do
|
15
|
+
|
16
|
+
begin
|
17
|
+
name = ARGV[1] || raise("rake cads_db_ar:gen <name of the migration>")
|
18
|
+
path = MigHelper.generate_migration({}, name)
|
19
|
+
puts "Migration written to '#{path}'"
|
20
|
+
rescue Exception => ex
|
21
|
+
STDERR.puts ex.message
|
22
|
+
end
|
23
|
+
abort
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Migrate the database"
|
27
|
+
task :migrate do
|
28
|
+
|
29
|
+
confPath = './db/config.yml'
|
30
|
+
|
31
|
+
if not File.exist?(confPath)
|
32
|
+
STDOUT.print "Please provide config file path : "
|
33
|
+
path = STDIN.gets
|
34
|
+
confPath = File.expand_path(path)
|
35
|
+
raise("Given config file '#{confPath}' does not exist") if not File.exist?(confPath)
|
36
|
+
end
|
37
|
+
|
38
|
+
env = ENV['AR-ENV'] || 'development'
|
39
|
+
|
40
|
+
File.open(confPath,"r") do |f|
|
41
|
+
@conf = YAML.load(f.read)
|
42
|
+
end
|
43
|
+
|
44
|
+
p @conf
|
45
|
+
|
46
|
+
MigHelper.migrate(@conf[env])
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ca-data_store-ar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ian
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-09-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: teLogger
|
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: toolrack
|
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: activerecord
|
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: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: standalone_migrations
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: ca-data_store
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sqlite3
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: devops_assist
|
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'
|
125
|
+
description: ''
|
126
|
+
email:
|
127
|
+
- cameronian0@protonmail.com
|
128
|
+
executables:
|
129
|
+
- ar-migrate
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- ".rspec"
|
134
|
+
- Gemfile
|
135
|
+
- Gemfile.lock
|
136
|
+
- README.md
|
137
|
+
- Rakefile
|
138
|
+
- bin/console
|
139
|
+
- bin/setup
|
140
|
+
- ca-data_store-ar.gemspec
|
141
|
+
- exe/ar-migrate
|
142
|
+
- lib/ca/data_store/ar.rb
|
143
|
+
- lib/ca/data_store/ar/console_helper.rb
|
144
|
+
- lib/ca/data_store/ar/migration/migration_helper.rb
|
145
|
+
- lib/ca/data_store/ar/model_base.rb
|
146
|
+
- lib/ca/data_store/ar/provider.rb
|
147
|
+
- lib/ca/data_store/ar/version.rb
|
148
|
+
- spec_test.db
|
149
|
+
- tasks/cads_db_ar.rake
|
150
|
+
homepage: ''
|
151
|
+
licenses: []
|
152
|
+
metadata: {}
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: 2.4.0
|
162
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
requirements: []
|
168
|
+
rubygems_version: 3.2.22
|
169
|
+
signing_key:
|
170
|
+
specification_version: 4
|
171
|
+
summary: ''
|
172
|
+
test_files: []
|