Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup and linter fixes #46

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions pluto-models/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

source 'https://rubygems.org'
ruby '>=2.2'
gem 'activerecord' # , '>= 6.1.4'
gem 'activerecord-utils' # , '>= 0.4.0'
gem 'activityutils' # , '>= 0.1.1'
gem 'date-formatter' # , '>= 0.1.1'
gem 'feedfilter' # , '>= 1.1.1'
gem 'feedparser' # , '>= 2.1.2'
gem 'logutils' # , '>= 0.6.1'
gem 'logutils-activerecord' # , '>= 0.2.1'
gem 'props' # , '>= 1.2.0'
gem 'props-activerecord' # , '>= 0.2.0'
gem 'rubocop', require: false
gem 'rubocop-rake', require: false
gem 'textutils' # , '>= 1.4.0'
112 changes: 112 additions & 0 deletions pluto-models/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
GEM
remote: https://rubygems.org/
specs:
activemodel (7.1.3.2)
activesupport (= 7.1.3.2)
activerecord (7.1.3.2)
activemodel (= 7.1.3.2)
activesupport (= 7.1.3.2)
timeout (>= 0.4.0)
activerecord-utils (0.4.1)
activerecord
logutils
activesupport (7.1.3.2)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
activityutils (0.1.2)
logutils (>= 0.6.1)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.6)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
date-formatter (0.1.1)
drb (2.2.0)
ruby2_keywords
feedfilter (1.1.1)
textutils (>= 1.0.1)
feedparser (2.2.0)
logutils (>= 0.6.1)
textutils (>= 1.0.0)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
iniparser (1.0.1)
json (2.7.1)
language_server-protocol (3.17.0.3)
logutils (0.6.1)
logutils-activerecord (0.2.1)
activerecord
logutils (>= 0.6.1)
minitest (5.22.2)
mutex_m (0.2.0)
parallel (1.24.0)
parser (3.3.0.5)
ast (~> 2.4.1)
racc
props (1.2.0)
iniparser (>= 0.1.0)
props-activerecord (0.2.0)
activerecord
props (>= 1.2.0)
racc (1.7.3)
rainbow (3.1.1)
regexp_parser (2.9.0)
rexml (3.2.6)
rubocop (1.60.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
textutils (1.4.0)
activesupport
logutils (>= 0.6.1)
props (>= 1.1.2)
rubyzip (>= 1.0.0)
timeout (0.4.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)

PLATFORMS
x86_64-linux

DEPENDENCIES
activerecord
activerecord-utils
activityutils
date-formatter
feedfilter
feedparser
logutils
logutils-activerecord
props
props-activerecord
rubocop
rubocop-rake
textutils

RUBY VERSION
ruby 3.0.2p107

BUNDLED WITH
2.3.5
11 changes: 5 additions & 6 deletions pluto-models/Rakefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# frozen_string_literal: true

require 'hoe'
require './lib/pluto/version.rb'
require './lib/pluto/version'

Hoe.spec 'pluto-models' do

self.version = Pluto::VERSION

self.summary = "pluto-models - planet schema 'n' models for easy (re)use"
self.description = summary

self.urls = ['https://github.com/feedreader/pluto']
self.urls = { 'home': 'https://github.com/feedreader/pluto' }

self.author = 'Gerald Bauer'
self.email = '[email protected]'
Expand All @@ -28,14 +29,12 @@ Hoe.spec 'pluto-models' do
['logutils-activerecord', '>= 0.2.1'],
['props-activerecord', '>= 0.2.0'],
['activityutils', '>= 0.1.1'],
['activerecord-utils', '>= 0.4.0'],
['activerecord-utils', '>= 0.4.0']
]


self.licenses = ['Public Domain']

self.spec_extras = {
required_ruby_version: '>= 2.2.2'
}

end
61 changes: 29 additions & 32 deletions pluto-models/lib/pluto/config.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@


module Pluto
class Configuration

def debug=(value) @debug = value; end
def debug?() @debug || false; end

def logger
## always return root for now; let's you globally configure e.g.
## logger.level = :debug etc.
LogUtils::Logger.root
end
end # class Configuration



## lets you use
## Pluto.configure do |config|
## config.debug = true
## config.logger.level = :debug
## end

def self.configure
yield( config )
end

def self.config
@config ||= Configuration.new
end

end # module Pluto
# frozen_string_literal: true

module Pluto
class Configuration
attr_writer :debug

def debug? = @debug || false

def logger
## always return root for now; let's you globally configure e.g.
## logger.level = :debug etc.
LogUtils::Logger.root
end
end

## lets you use
## Pluto.configure do |config|
## config.debug = true
## config.logger.level = :debug
## end

def self.configure
yield(config)
end

def self.config
@config ||= Configuration.new
end
end
131 changes: 58 additions & 73 deletions pluto-models/lib/pluto/connecter.rb
Original file line number Diff line number Diff line change
@@ -1,89 +1,74 @@
# encoding: utf-8
# frozen_string_literal: true

module Pluto
# DB Connecter / Connection Manager
# lets you establish connection

class Connecter
include LogUtils::Logging

# DB Connecter / Connection Manager
# lets you establish connection

class Connecter

include LogUtils::Logging



def initialize
# do nothing for now
end

def debug?() Pluto.config.debug?; end



def connect( config={} )

if config.empty? # use/try DATABASE_URL from environment

logger.debug "ENV['DATBASE_URL'] - >#{ENV['DATABASE_URL']}<"

db = URI.parse( ENV['DATABASE_URL'] || 'sqlite3:///pluto.db' )
def initialize
# do nothing for now
end

if db.scheme == 'postgres'
config = {
adapter: 'postgresql',
host: db.host,
port: db.port,
username: db.user,
password: db.password,
database: db.path[1..-1],
encoding: 'utf8'
}
else # assume sqlite3
config = {
adapter: db.scheme, # sqlite3
database: db.path[1..-1] # pluto.db (NB: cut off leading /, thus 1..-1)
}
def debug? = Pluto.config.debug?

def connect(config = {})
if config.empty? # use/try DATABASE_URL from environment

logger.debug "ENV['DATBASE_URL'] - >#{ENV['DATABASE_URL']}<"

db = URI.parse(ENV['DATABASE_URL'] || 'sqlite3:///pluto.db')

config = if db.scheme == 'postgres'
{
adapter: 'postgresql',
host: db.host,
port: db.port,
username: db.user,
password: db.password,
database: db.path[1..],
encoding: 'utf8'
}
else # assume sqlite3
{
adapter: db.scheme, # sqlite3
database: db.path[1..] # pluto.db (NB: cut off leading /, thus 1..-1)
}
end
end
end # if config.nil?

logger.info 'db settings:'
logger.info config.pretty_inspect
logger.info 'db settings:'
logger.info config.pretty_inspect

### for dbbrowser and other tools add to ActiveRecord
### for dbbrowser and other tools add to ActiveRecord

if ActiveRecord::Base.configurations.nil? # todo/check: can this ever happen? remove?
logger.debug "ActiveRecord configurations nil - set to empty hash"
ActiveRecord::Base.configurations = {} # make it an empty hash
end
if ActiveRecord::Base.configurations.nil? # todo/check: can this ever happen? remove?
logger.debug 'ActiveRecord configurations nil - set to empty hash'
ActiveRecord::Base.configurations = {} # make it an empty hash
end

## todo/fix: remove debug? option - why? why not?
## (just) use logger level eg. logger.debug
if debug?
logger.debug 'ar configurations (before):'
logger.debug ActiveRecord::Base.configurations.pretty_inspect
end
## todo/fix: remove debug? option - why? why not?
## (just) use logger level eg. logger.debug
if debug?
logger.debug 'ar configurations (before):'
logger.debug ActiveRecord::Base.configurations.pretty_inspect
end

# note: for now always use pluto key for config storage
configs = ActiveRecord::Base.configurations.to_h.reject { |db_config| db_config.env_name == 'pluto' }
configs['pluto'] = config
configurations = ActiveRecord::Base.configurations.configs_for(env_name: 'pluto')
configurations << config

ActiveRecord::Base.configurations = configs
ActiveRecord::Base.configurations = configurations

if debug?
logger.debug 'ar configurations (after):'
logger.debug ActiveRecord::Base.configurations.pretty_inspect
end
if debug?
logger.debug 'ar configurations (after):'
logger.debug ActiveRecord::Base.configurations.pretty_inspect
end

# for debugging - disable for production use
ActiveRecord::Base.logger = Logger.new($stdout) if debug?

# for debugging - disable for production use
if debug?
ActiveRecord::Base.logger = Logger.new( STDOUT )
ActiveRecord::Base.establish_connection(config)
end

ActiveRecord::Base.establish_connection( config )
end # method connect


end # class Connecter

end # module Pluto
end
end
Loading