ca-data_store 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
+ SHA256:
3
+ metadata.gz: 7622bb5830322bb8c45acb3f200669cdddce1d9ed4feeb0550ff2c467b62571b
4
+ data.tar.gz: e5077c55aa5e0d8431789961b9ed7a8f0b94b90a6526ebf5f01f007b02732c05
5
+ SHA512:
6
+ metadata.gz: 324ef196904f35ab508e0fa2090fe2f6b1540c4503046b97862939b94a3830532139eefeba61bd792fa8ced8341183b0b7e8bfe00e97a163ffc9a126e771a813
7
+ data.tar.gz: 58b8b3ec687b3329d74f3f2ec41532eb1eaddc67f0ca11fab05171c9a6691e7271ada3b0335a12bfd57a696c1de412590d83239b48dcec642fb8985428e8c7fb
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in ca-data_store.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,74 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ca-data_store (0.1.0)
5
+ teLogger
6
+ toolrack
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ base58 (0.2.3)
12
+ devops_assist (0.3.0)
13
+ git_cli
14
+ git_cli_prompt
15
+ gvcs
16
+ teLogger
17
+ toolrack
18
+ tty-prompt
19
+ diff-lcs (1.5.0)
20
+ git_cli (0.10.0)
21
+ gvcs
22
+ ptools (~> 1.4.0)
23
+ teLogger
24
+ toolrack
25
+ git_cli_prompt (0.3.1)
26
+ teLogger
27
+ toolrack
28
+ tty-prompt
29
+ gvcs (0.1.0)
30
+ pastel (0.8.0)
31
+ tty-color (~> 0.5)
32
+ ptools (1.4.2)
33
+ rake (13.0.6)
34
+ rspec (3.11.0)
35
+ rspec-core (~> 3.11.0)
36
+ rspec-expectations (~> 3.11.0)
37
+ rspec-mocks (~> 3.11.0)
38
+ rspec-core (3.11.0)
39
+ rspec-support (~> 3.11.0)
40
+ rspec-expectations (3.11.0)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.11.0)
43
+ rspec-mocks (3.11.1)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.11.0)
46
+ rspec-support (3.11.0)
47
+ teLogger (0.2.0)
48
+ tlogger (0.26.3)
49
+ toolrack (0.18.6)
50
+ base58
51
+ tlogger
52
+ tty-color (0.6.0)
53
+ tty-cursor (0.7.1)
54
+ tty-prompt (0.23.1)
55
+ pastel (~> 0.8)
56
+ tty-reader (~> 0.8)
57
+ tty-reader (0.9.0)
58
+ tty-cursor (~> 0.7)
59
+ tty-screen (~> 0.8)
60
+ wisper (~> 2.0)
61
+ tty-screen (0.8.1)
62
+ wisper (2.0.1)
63
+
64
+ PLATFORMS
65
+ x86_64-linux
66
+
67
+ DEPENDENCIES
68
+ ca-data_store!
69
+ devops_assist
70
+ rake (~> 13.0)
71
+ rspec (~> 3.0)
72
+
73
+ BUNDLED WITH
74
+ 2.2.28
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Ca::DataStore
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`. 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'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ca-data_store
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.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
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
+ 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"
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,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
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/ca/data_store/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ca-data_store"
7
+ spec.version = Ca::DataStore::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_development_dependency 'devops_assist'
37
+
38
+ # Uncomment to register a new dependency of your gem
39
+ # spec.add_dependency "example-gem", "~> 1.0"
40
+
41
+ # For more information and examples about making a new gem, checkout our
42
+ # guide at: https://bundler.io/guides/creating_gem.html
43
+ end
@@ -0,0 +1,74 @@
1
+
2
+ require_relative 'provider'
3
+
4
+ module Ca
5
+ module DataStore
6
+
7
+ #
8
+ # All method from this model is prefixed with cads_
9
+ # to separate the call with included/extended class.
10
+ # Notably case in mind is ActiveRecord
11
+ #
12
+ module Model
13
+ include TR::CondUtils
14
+
15
+ include TeLogger::TeLogHelper
16
+ teLogger_tag :cads_model
17
+
18
+ module ClassMethods
19
+
20
+ def cads_find(*args, &block)
21
+ Provider.instance.provider.handle(:find, self, *args, &block)
22
+ end
23
+
24
+ # unstable relationship between mid and potential keys inside data store such as ActiveRecord
25
+ # The name cannot be same and it is up to user to define or link if there is
26
+ #def cads_find_by_mid(*args, &block)
27
+ # Provider.instance.provider.handle(:find_by_mid, self, *args, &block)
28
+ #end
29
+
30
+ def cads_find_all(*args, &block)
31
+ Provider.instance.provider.handle(:find_all, self, *args, &block)
32
+ end
33
+
34
+ def cads_schema(*args, &block)
35
+ Provider.instance.provider.handle(:schema, self, *args, &block)
36
+ end
37
+
38
+ end # ClassMethods
39
+ def self.included(klass)
40
+ klass.extend(ClassMethods)
41
+ end
42
+
43
+ def Model.init(*args, &block)
44
+ Provider.instance.provider.handle(:init, *args, &block)
45
+ end
46
+
47
+ def Model.reset(*args, &block)
48
+ Provider.instance.provider.handle(:reset, *args, &block)
49
+ end
50
+
51
+ attr_accessor :mid, :ts_created, :ts_updated, :cads_new_record
52
+
53
+ def cads_save(*args, &block)
54
+ if is_cads_new_record? and is_empty?(@mid)
55
+ @mid = SecureRandom.hex(16)
56
+ end
57
+ Provider.instance.provider.handle(:save, self, *args, &block)
58
+ end
59
+
60
+ def cads_delete(*args, &block)
61
+ Provider.instance.provider.handle(:delete, self, *args, &block)
62
+ end
63
+
64
+ def is_cads_new_record?(*args, &block)
65
+ @cads_new_record = Provider.instance.provider.handle(:is_new_record?, self, *args, &block)
66
+ @cads_new_record = true if is_empty?(@cads_new_record) or not is_bool?(@cads_new_record)
67
+ @cads_new_record
68
+ end
69
+
70
+
71
+ end # Model
72
+
73
+ end # DataStore
74
+ end #Ca
@@ -0,0 +1,92 @@
1
+
2
+ require 'singleton'
3
+
4
+ module Ca
5
+
6
+ module DataStore
7
+
8
+ class ProviderException < StandardError; end
9
+
10
+ class Provider
11
+ include Singleton
12
+ include TR::CondUtils
13
+
14
+ include TeLogger::TeLogHelper
15
+ teLogger_tag :datastore
16
+
17
+ def register(prov)
18
+ raise ProviderException, "Provider cannot be nil" if prov.nil?
19
+ raise ProviderException, "Provider must have name" if not prov.respond_to?(:provider_name)
20
+
21
+ add_provider(prov)
22
+ end
23
+
24
+ def default_provider=(prov)
25
+ raise ProviderException, "Nil provider is not supported" if prov.nil?
26
+
27
+ case prov
28
+ when String
29
+ if is_provider_registered?(prov)
30
+ @defaultProvider = find_provider(prov)
31
+ else
32
+ raise ProviderException, "Given provider '#{prov}' to set as default has yet to be registered."
33
+ end
34
+ else
35
+ if prov.respond_to?(:provider_name)
36
+ add_provider(prov) if not is_provider_registered?(prov.provider_name)
37
+ @defaultProvider = prov
38
+ else
39
+ raise ProviderException, "Given provider to set as default does not have name"
40
+ end
41
+ end
42
+
43
+ @defaultProvider
44
+ end
45
+ def default_provider
46
+ @defaultProvider
47
+ end
48
+
49
+
50
+ def find_provider(prov)
51
+ if not_empty?(prov)
52
+ providers[prov]
53
+ else
54
+ raise ProviderException, "Cannot find nil empty provider"
55
+ end
56
+ end
57
+
58
+ def provider
59
+ raise ProviderException, "No provider is registered" if is_providers_empty?
60
+
61
+ if is_empty?(default_provider)
62
+ providers.values.first
63
+ else
64
+ default_provider
65
+ end
66
+ end
67
+
68
+
69
+ private
70
+ def add_provider(prov)
71
+ providers[prov.provider_name] = prov
72
+ teLogger.debug "Provider '#{prov.provider_name}' registered"
73
+ end
74
+
75
+ def is_provider_registered?(provName)
76
+ providers.keys.include?(provName)
77
+ end
78
+
79
+ def is_providers_empty?
80
+ providers.empty?
81
+ end
82
+
83
+ def providers
84
+ if @providers.nil?
85
+ @providers = {}
86
+ end
87
+ @providers
88
+ end
89
+
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ca
4
+ module DataStore
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "data_store/version"
4
+
5
+ require_relative 'data_store/provider'
6
+ require_relative 'data_store/model'
7
+
8
+ module Ca
9
+ module DataStore
10
+ class Error < StandardError; end
11
+
12
+ class ProviderException < StandardError; end
13
+ class DuplicatedIndex < StandardError; end
14
+ # Your code goes here...
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ca-data_store
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: devops_assist
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: ''
56
+ email:
57
+ - cameronian0@protonmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".rspec"
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - ca-data_store.gemspec
70
+ - lib/ca/data_store.rb
71
+ - lib/ca/data_store/model.rb
72
+ - lib/ca/data_store/provider.rb
73
+ - lib/ca/data_store/version.rb
74
+ homepage: ''
75
+ licenses: []
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 2.4.0
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubygems_version: 3.2.22
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: ''
96
+ test_files: []