logs_maino 0.1.0
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 +7 -0
- data/.env +4 -0
- data/.gitignore +56 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +34 -0
- data/README.md +40 -0
- data/Rakefile +39 -0
- data/bin/console +7 -0
- data/bin/setup +8 -0
- data/db/migrate/001_create_logs.rb +14 -0
- data/lib/config/db.rb +14 -0
- data/lib/logs_maino/version.rb +3 -0
- data/lib/logs_maino.rb +17 -0
- data/lib/models/log.rb +28 -0
- data/lib/models.rb +3 -0
- data/lib/modules/callable.rb +7 -0
- data/lib/modules/resources.rb +8 -0
- data/lib/processor.rb +16 -0
- data/lib/repositories/log.rb +18 -0
- data/lib/repositories.rb +3 -0
- data/lib/services/log/store.rb +17 -0
- data/lib/services.rb +3 -0
- data/logs_maino.gemspec +25 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1db66c23fdcc0a32dd8b13afc2761c6d12149441a4eeb2c7fe387e04f2641787
|
4
|
+
data.tar.gz: b944e4ebaa2c058ccdafdb8329f35cb66d7c896ebaa07c3f2f700e54cd2d11c3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b414c3d13585065ce52d6a59b92031713e757e82e045fbdb4355af07cb912aacadfb6cb2788d117bd7121100084c22c6fe688bfd59d774a3e1e64770da5aff3b
|
7
|
+
data.tar.gz: 7d556fa2a19b58980b17ec50cbb33452514d0926a16dd04987ca86855c660c42a73fa353af21772b31cd26d26f4ce68ea4bc4a4fbe7b549bcb0b6931da98fa7e
|
data/.env
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
# .rubocop-https?--*
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
logs_maino (0.1.0)
|
5
|
+
sequel
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
bigdecimal (3.1.8)
|
11
|
+
coderay (1.1.3)
|
12
|
+
dotenv (3.1.2)
|
13
|
+
method_source (1.1.0)
|
14
|
+
pg (1.5.6)
|
15
|
+
pry (0.14.2)
|
16
|
+
coderay (~> 1.1)
|
17
|
+
method_source (~> 1.0)
|
18
|
+
rake (12.3.3)
|
19
|
+
sequel (5.82.0)
|
20
|
+
bigdecimal
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
dotenv
|
27
|
+
logs_maino!
|
28
|
+
pg (~> 1.5, >= 1.5.4)
|
29
|
+
pry (~> 0.14.2)
|
30
|
+
rake (~> 12.0)
|
31
|
+
sequel (~> 5.72)
|
32
|
+
|
33
|
+
BUNDLED WITH
|
34
|
+
2.1.4
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# LogsMaino
|
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/logs_maino`. 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 'logs_maino'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install logs_maino
|
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. 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]/logs_maino. 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]/logs_maino/blob/master/CODE_OF_CONDUCT.md).
|
36
|
+
|
37
|
+
|
38
|
+
## Code of Conduct
|
39
|
+
|
40
|
+
Everyone interacting in the LogsMaino project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/logs_maino/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "bundler/setup"
|
5
|
+
require "logs_maino"
|
6
|
+
require 'pry'
|
7
|
+
rescue LoadError
|
8
|
+
puts('You must `gem install bundler` and `bundle install` to run rake tasks')
|
9
|
+
end
|
10
|
+
|
11
|
+
desc('Open an irb session')
|
12
|
+
task :console do
|
13
|
+
sh 'bin/console'
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
DB_CONFIG = {
|
18
|
+
adapter: 'postgres',
|
19
|
+
host: ENV['POSTGRES_HOST'],
|
20
|
+
user: ENV['POSTGRES_USER'],
|
21
|
+
password: ENV['POSTGRES_PASSWORD']
|
22
|
+
}.freeze
|
23
|
+
|
24
|
+
namespace :db do
|
25
|
+
desc('Run migrations')
|
26
|
+
task :migrate, [:version] do |_t, args|
|
27
|
+
require 'sequel/core'
|
28
|
+
Sequel.extension :migration
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
DB = Sequel.connect(
|
33
|
+
DB_CONFIG.merge(database: ENV['POSTGRES_DB'])
|
34
|
+
)
|
35
|
+
|
36
|
+
version = args[:version].to_i if args[:version]
|
37
|
+
Sequel::Migrator.run(DB, 'db/migrate', target: version)
|
38
|
+
end
|
39
|
+
end
|
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
DB.run 'CREATE EXTENSION IF NOT EXISTS "uuid-ossp";'
|
4
|
+
|
5
|
+
Sequel.migration do
|
6
|
+
change do
|
7
|
+
create_table :logs do
|
8
|
+
primary_key :id, :uuid, default: Sequel.function(:uuid_generate_v4), type: :uuid
|
9
|
+
DateTime :created_at, default: Sequel::CURRENT_TIMESTAMP, index: true
|
10
|
+
String :status, null: false, default: 'pending'
|
11
|
+
jsonb :data, default: '{}'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/config/db.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Postgres + jsonb
|
4
|
+
# https://sequel.jeremyevans.net/rdoc-plugins/files/lib/sequel/extensions/pg_json_ops_rb.html
|
5
|
+
|
6
|
+
DB = Sequel.connect(
|
7
|
+
adapter: 'postgres',
|
8
|
+
host: ENV['POSTGRES_HOST'],
|
9
|
+
user: ENV['POSTGRES_USER'],
|
10
|
+
password: ENV['POSTGRES_PASSWORD'],
|
11
|
+
database: ENV['POSTGRES_DB']
|
12
|
+
)
|
13
|
+
|
14
|
+
Sequel.extension :pg_json
|
data/lib/logs_maino.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "logs_maino/version"
|
2
|
+
require 'dotenv'
|
3
|
+
Dotenv.load
|
4
|
+
require 'sequel'
|
5
|
+
require_relative 'config/db'
|
6
|
+
require_relative 'models'
|
7
|
+
require_relative 'repositories'
|
8
|
+
require_relative 'modules/callable'
|
9
|
+
require_relative 'modules/resources'
|
10
|
+
require_relative 'services'
|
11
|
+
require_relative 'processor'
|
12
|
+
|
13
|
+
|
14
|
+
module LogsMaino
|
15
|
+
class Error < StandardError; end
|
16
|
+
# Your code goes here...
|
17
|
+
end
|
data/lib/models/log.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Models
|
2
|
+
class Log
|
3
|
+
attr_accessor :id, :created_at, :status, :data
|
4
|
+
|
5
|
+
def initialize(attrs = {})
|
6
|
+
attrs.each do |key, value|
|
7
|
+
self.send("#{key}=", value) if respond_to?("#{key}=")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def attributes_hash
|
12
|
+
instance_variables.each_with_object({}) do |var, hash|
|
13
|
+
hash[var.to_s.delete('@').to_sym] = instance_variable_get(var)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def data=(data)
|
18
|
+
@data = jsonb(data)
|
19
|
+
end
|
20
|
+
|
21
|
+
def jsonb(json)
|
22
|
+
return if json.blank?
|
23
|
+
return json if json.is_a?(String)
|
24
|
+
|
25
|
+
Sequel&.pg_json(json)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/models.rb
ADDED
data/lib/processor.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
class Processor
|
2
|
+
extend Resources
|
3
|
+
extend Callable
|
4
|
+
|
5
|
+
register 'log_store', Services::Log::Store
|
6
|
+
|
7
|
+
def initialize(payload)
|
8
|
+
@resource = payload[:resource]
|
9
|
+
@params = payload[:params]
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute
|
13
|
+
service = Resources::REGISTERED[@resource]
|
14
|
+
service.call(@params)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Repositories
|
2
|
+
class Log
|
3
|
+
def initialize(repository = DB[:logs], model = Models::Log)
|
4
|
+
@repository = repository
|
5
|
+
@model = model
|
6
|
+
end
|
7
|
+
|
8
|
+
def find(id)
|
9
|
+
attrs = @repository.first(id: id)
|
10
|
+
@model.new(attrs)
|
11
|
+
end
|
12
|
+
|
13
|
+
def store(attrs)
|
14
|
+
id = @repository.insert(@model.new(attrs).attributes_hash)
|
15
|
+
find(id)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/repositories.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Services
|
2
|
+
module Log
|
3
|
+
class Store
|
4
|
+
extend Callable
|
5
|
+
attr_accessor :params, :repository
|
6
|
+
|
7
|
+
def initialize(params, repository = Repositories::Log.new)
|
8
|
+
@params = params
|
9
|
+
@repository = repository
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute
|
13
|
+
repository.store(params)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/services.rb
ADDED
data/logs_maino.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'lib/logs_maino/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "logs_maino"
|
5
|
+
spec.version = LogsMaino::VERSION
|
6
|
+
spec.authors = ["David Schnee"]
|
7
|
+
spec.email = ["david.schnee@maino.com.br"]
|
8
|
+
|
9
|
+
spec.summary = %q{Repositório responsavel por salvar logs de um sistema}
|
10
|
+
spec.homepage = "https://github.com/DavidSchnee/logs_maino"
|
11
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
12
|
+
|
13
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
14
|
+
spec.metadata["source_code_uri"] = "https://github.com/DavidSchnee/logs_maino"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
spec.add_dependency 'sequel'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logs_maino
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Schnee
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sequel
|
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
|
+
description:
|
28
|
+
email:
|
29
|
+
- david.schnee@maino.com.br
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".env"
|
35
|
+
- ".gitignore"
|
36
|
+
- Gemfile
|
37
|
+
- Gemfile.lock
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- bin/console
|
41
|
+
- bin/setup
|
42
|
+
- db/migrate/001_create_logs.rb
|
43
|
+
- lib/config/db.rb
|
44
|
+
- lib/logs_maino.rb
|
45
|
+
- lib/logs_maino/version.rb
|
46
|
+
- lib/models.rb
|
47
|
+
- lib/models/log.rb
|
48
|
+
- lib/modules/callable.rb
|
49
|
+
- lib/modules/resources.rb
|
50
|
+
- lib/processor.rb
|
51
|
+
- lib/repositories.rb
|
52
|
+
- lib/repositories/log.rb
|
53
|
+
- lib/services.rb
|
54
|
+
- lib/services/log/store.rb
|
55
|
+
- logs_maino.gemspec
|
56
|
+
homepage: https://github.com/DavidSchnee/logs_maino
|
57
|
+
licenses: []
|
58
|
+
metadata:
|
59
|
+
homepage_uri: https://github.com/DavidSchnee/logs_maino
|
60
|
+
source_code_uri: https://github.com/DavidSchnee/logs_maino
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.3.0
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubygems_version: 3.1.6
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Repositório responsavel por salvar logs de um sistema
|
80
|
+
test_files: []
|