neo_gruby-sequel 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/neo_gruby/sequel/db.rb +43 -0
- data/lib/neo_gruby/sequel/plugins/uuid_pk.rb +58 -0
- data/lib/neo_gruby/sequel/version.rb +1 -1
- metadata +3 -12
- data/.gitignore +0 -11
- data/.rspec +0 -3
- data/.travis.yml +0 -6
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -7
- data/LICENSE.txt +0 -21
- data/README.md +0 -44
- data/Rakefile +0 -6
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/neo_gruby-sequel.gemspec +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfa5d545b292cb15c1861da1f16253fae8b8cfd0fdd9c4a0ea21d3f30054266e
|
4
|
+
data.tar.gz: 5669b6f2219785ed8e521e521f01401f041139967091d821bbf02937ec53657d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2663c5c4357ea8a3f3bbdce5cece5dc6d646e83f0fc2bd5e1641eb4dd1bafe4fe59754fc7a119256a2afc9215b4d649b48c300cff032e5547dd77dbbe6e39fa4
|
7
|
+
data.tar.gz: b83c70ec8fd098878a7073318938f87e702f04f9f042397c92e241a5cb676e40aa11a8e5ee9890823101dc1a97b3b63fec1cd95a73a33eb576f73ecd859498f7
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'sequel'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module NeoGruby
|
5
|
+
module Sequel
|
6
|
+
module Db
|
7
|
+
class << self
|
8
|
+
attr_reader :conn
|
9
|
+
|
10
|
+
def start_connections
|
11
|
+
@conn ||= {}
|
12
|
+
config = YAML.load_file(NeoGruby.root.join('config', 'database.yml'))
|
13
|
+
config[NeoGruby.env].keys.each do |name|
|
14
|
+
@conn[name.to_sym] = establish_connection(config[NeoGruby.env][name])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def disconnect_all
|
19
|
+
@conn.keys.each do |name|
|
20
|
+
@conn[name].disconnect
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def establish_connection(config)
|
27
|
+
::Sequel.connect(config)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
NeoGruby::Registry.add :after_boot do
|
35
|
+
NeoGruby::Sequel::Db.start_connections
|
36
|
+
NeoGruby.db ||= NeoGruby::Sequel::Db.conn
|
37
|
+
end
|
38
|
+
|
39
|
+
NeoGruby::Registry.add :after_boot do
|
40
|
+
Dir[NeoGruby.root.join('app', 'models', '*.rb')].each do |f|
|
41
|
+
require f
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'uuidtools'
|
2
|
+
|
3
|
+
module NeoGruby
|
4
|
+
module Sequel
|
5
|
+
module Plugins
|
6
|
+
module UuidPk
|
7
|
+
class << self
|
8
|
+
def parse_id(value, to_raw = false)
|
9
|
+
value = UUIDTools::UUID.parse(value) if value.is_a?(String) && value.encoding.name != 'ASCII-8BIT'
|
10
|
+
value = UUIDTools::UUID.parse_int(value) if value.is_a? Integer
|
11
|
+
return(value.respond_to?(:raw) ? value.raw : value) if to_raw
|
12
|
+
value = UUIDTools::UUID.parse_raw(value) unless value.nil?
|
13
|
+
value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
|
19
|
+
def find(where)
|
20
|
+
if where.is_a? Hash
|
21
|
+
where[:id] = UuidPk.parse_id(where[:id], true) if where[:id]
|
22
|
+
where['id'] = UuidPk.parse_id(where['id'], true) if where['id']
|
23
|
+
end
|
24
|
+
|
25
|
+
super(where)
|
26
|
+
end
|
27
|
+
|
28
|
+
def where(params)
|
29
|
+
if params.is_a? Hash
|
30
|
+
params[:id] = UuidPk.parse_id(params[:id], true) if params[:id]
|
31
|
+
params['id'] = UuidPk.parse_id(params['id'], true) if params['id']
|
32
|
+
end
|
33
|
+
|
34
|
+
super(params)
|
35
|
+
end
|
36
|
+
|
37
|
+
def [](value)
|
38
|
+
super(UuidPk.parse_id(value, true))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module InstanceMethods
|
43
|
+
def before_validation
|
44
|
+
field = :id
|
45
|
+
meth = :"#{field}="
|
46
|
+
if respond_to?(field) && respond_to?(meth) && get_column_value(field).nil?
|
47
|
+
set_column_value(meth, UUIDTools::UUID.timestamp_create.raw)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def id
|
52
|
+
UuidPk.parse_id(super)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neo_gruby-sequel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Welington Sampaio
|
@@ -59,19 +59,10 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- ".gitignore"
|
63
|
-
- ".rspec"
|
64
|
-
- ".travis.yml"
|
65
|
-
- CODE_OF_CONDUCT.md
|
66
|
-
- Gemfile
|
67
|
-
- LICENSE.txt
|
68
|
-
- README.md
|
69
|
-
- Rakefile
|
70
|
-
- bin/console
|
71
|
-
- bin/setup
|
72
62
|
- lib/neo_gruby/sequel.rb
|
63
|
+
- lib/neo_gruby/sequel/db.rb
|
64
|
+
- lib/neo_gruby/sequel/plugins/uuid_pk.rb
|
73
65
|
- lib/neo_gruby/sequel/version.rb
|
74
|
-
- neo_gruby-sequel.gemspec
|
75
66
|
homepage: https://github.com/neolifehq/neogruby-sequel
|
76
67
|
licenses:
|
77
68
|
- MIT
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
2
|
-
|
3
|
-
## Our Pledge
|
4
|
-
|
5
|
-
In the interest of fostering an open and welcoming environment, we as
|
6
|
-
contributors and maintainers pledge to making participation in our project and
|
7
|
-
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
-
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
-
orientation.
|
11
|
-
|
12
|
-
## Our Standards
|
13
|
-
|
14
|
-
Examples of behavior that contributes to creating a positive environment
|
15
|
-
include:
|
16
|
-
|
17
|
-
* Using welcoming and inclusive language
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
19
|
-
* Gracefully accepting constructive criticism
|
20
|
-
* Focusing on what is best for the community
|
21
|
-
* Showing empathy towards other community members
|
22
|
-
|
23
|
-
Examples of unacceptable behavior by participants include:
|
24
|
-
|
25
|
-
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
-
advances
|
27
|
-
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
-
* Public or private harassment
|
29
|
-
* Publishing others' private information, such as a physical or electronic
|
30
|
-
address, without explicit permission
|
31
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
-
professional setting
|
33
|
-
|
34
|
-
## Our Responsibilities
|
35
|
-
|
36
|
-
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
-
behavior and are expected to take appropriate and fair corrective action in
|
38
|
-
response to any instances of unacceptable behavior.
|
39
|
-
|
40
|
-
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
-
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
-
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
-
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
-
threatening, offensive, or harmful.
|
45
|
-
|
46
|
-
## Scope
|
47
|
-
|
48
|
-
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
-
when an individual is representing the project or its community. Examples of
|
50
|
-
representing a project or community include using an official project e-mail
|
51
|
-
address, posting via an official social media account, or acting as an appointed
|
52
|
-
representative at an online or offline event. Representation of a project may be
|
53
|
-
further defined and clarified by project maintainers.
|
54
|
-
|
55
|
-
## Enforcement
|
56
|
-
|
57
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at welington.sampaio@icloud.com. All
|
59
|
-
complaints will be reviewed and investigated and will result in a response that
|
60
|
-
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
-
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
-
Further details of specific enforcement policies may be posted separately.
|
63
|
-
|
64
|
-
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
-
faith may face temporary or permanent repercussions as determined by other
|
66
|
-
members of the project's leadership.
|
67
|
-
|
68
|
-
## Attribution
|
69
|
-
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
-
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
-
|
73
|
-
[homepage]: https://contributor-covenant.org
|
74
|
-
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2020 Welington Sampaio
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
# NeoGruby::Sequel
|
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/neo_gruby/sequel`. 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 'neo_gruby-sequel'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle install
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install neo_gruby-sequel
|
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 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]/neo_gruby-sequel. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/neo_gruby-sequel/blob/master/CODE_OF_CONDUCT.md).
|
36
|
-
|
37
|
-
|
38
|
-
## License
|
39
|
-
|
40
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
41
|
-
|
42
|
-
## Code of Conduct
|
43
|
-
|
44
|
-
Everyone interacting in the NeoGruby::Sequel project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/neo_gruby-sequel/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "neo_gruby/sequel"
|
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(__FILE__)
|
data/bin/setup
DELETED
data/neo_gruby-sequel.gemspec
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require_relative 'lib/neo_gruby/sequel/version'
|
2
|
-
|
3
|
-
Gem::Specification.new do |spec|
|
4
|
-
spec.name = "neo_gruby-sequel"
|
5
|
-
spec.version = NeoGruby::Sequel::VERSION
|
6
|
-
spec.authors = ["Welington Sampaio"]
|
7
|
-
spec.email = ["welington.sampaio@icloud.com"]
|
8
|
-
|
9
|
-
spec.summary = %q{Implement Sequel routines to works with NeoGruby Framework}
|
10
|
-
# spec.description = %q{}
|
11
|
-
spec.homepage = "https://github.com/neolifehq/neogruby-sequel"
|
12
|
-
spec.license = "MIT"
|
13
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
-
|
15
|
-
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
16
|
-
|
17
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
-
spec.metadata["source_code_uri"] = "https://github.com/neolifehq/neogruby-sequel.git"
|
19
|
-
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
20
|
-
|
21
|
-
# Specify which files should be added to the gem when it is released.
|
22
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
-
end
|
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_dependency 'neo_gruby', '~> 0.2.0'
|
31
|
-
spec.add_dependency 'sequel', '~> 4.49.0'
|
32
|
-
spec.add_dependency 'uuidtools', '~> 2.1.5'
|
33
|
-
end
|