overture 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: 67719de8a9681b85fa9a2736febd368c53b2f5ed99650ec57c3997f812a23925
4
+ data.tar.gz: 82d3fefb3fb15f4674a8a2bdf8078865df14b86ad5bed0da2d8dc2c90fc4001c
5
+ SHA512:
6
+ metadata.gz: d785fcc8a0fae25165899087c8238a2ed74eb9378fda5a146d35f731d4a20146d52696c4af7cee4365598220777e296a4778a7e40d212b2b78aeccb13e1d10f0
7
+ data.tar.gz: 544673208d5782b8623e378800e88649158201368d35af737077bb7151724d9123d150725e74dae43d675b10212390a1b017619fdfbf4c594e5d1e89ac103572
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # Overture
2
+
3
+ This is a library of tools and configurations based on the Clean Architecture.
4
+
5
+ This gem contains the basic configuration options and file organization to create a Ruby application.
6
+
7
+ Sinatra is used as a delivery layer, but it can be easily replaced. Core business rules live in the Interactors.
8
+
9
+ ## Contents
10
+
11
+ - `Overture::Database`
12
+ - `Overture::Interactor`
13
+ - `Overture::Model`
14
+ - `Overture::PasswordDigester`
15
+
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'optparse'
5
+ require 'fileutils'
6
+
7
+ class Parser
8
+ def self.parse(options = {})
9
+ opt_parser = OptionParser.new do |opts|
10
+ opts.banner = 'Usage: overture-generate migration [options]'
11
+
12
+ opts.on '-nNAME', '--name=NAME', 'Migration name' do |n|
13
+ options[:name] = n
14
+ end
15
+
16
+ opts.on '-h', '--help', 'Prints this message' do
17
+ puts opts
18
+ exit
19
+ end
20
+ end
21
+
22
+ opt_parser.parse!(options)
23
+ options
24
+ end
25
+ end
26
+
27
+ options = Parser.parse
28
+
29
+ if options[:name].nil?
30
+ Parser.parse(['--help'])
31
+ exit
32
+ end
33
+
34
+ def generate_migration(name)
35
+ timestamp = Time.now.strftime('%Y%m%d%H%M%S')
36
+ filename = "migrations/#{timestamp}_#{name.tr(' ', '_').downcase}.rb"
37
+
38
+ FileUtils.mkdir_p('migrations')
39
+ File.open(filename, 'w') do |f|
40
+ f.puts <<~TEMPLATE
41
+ # frozen_string_literal: true
42
+
43
+ Sequel.migration do
44
+ table_name = :table_name # change this
45
+
46
+ up do
47
+ create_table(table_name) do
48
+ primary_key :id
49
+ DateTime :created_at, null: false
50
+ DateTime :updated_at, null: false
51
+ end
52
+ end
53
+
54
+ down do
55
+ drop_table(table_name)
56
+ end
57
+ end
58
+
59
+ TEMPLATE
60
+ end
61
+ puts "-----------> Created db migration: #{filename}"
62
+ end
63
+
64
+ generate_migration(options[:name])
65
+
data/lib/overture.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dotenv/load'
4
+ require 'overture/version'
5
+
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sequel'
4
+
5
+ Sequel.database_timezone = :utc
6
+ Sequel.application_timezone = :local
7
+ Sequel.extension :datetime_parse_to_time
8
+
9
+ module Overture
10
+ module Database
11
+ DEFAULT_OPTIONS = {
12
+ extensions: %i[
13
+ pg_array
14
+ pg_json
15
+ pg_timestamptz
16
+ named_timezones
17
+ ],
18
+ }.freeze
19
+
20
+ module_function
21
+
22
+ def connect(url, options = {})
23
+ Sequel.connect(url, DEFAULT_OPTIONS.merge(options))
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'interactor'
4
+
5
+ module Overture
6
+ class Interactor
7
+ include ::Interactor
8
+
9
+ class << self
10
+ def required(*input)
11
+ before do
12
+ opts = input.last.is_a?(Hash) ? input.pop : {}
13
+ allow_empty = opts[:allow_empty]
14
+
15
+ input.each do |attr|
16
+ value = context.public_send(attr)
17
+ empty = value.respond_to?(:empty?) ? value.empty? : false
18
+ valid = !value.nil? && (allow_empty ? true : !empty)
19
+ fail!("#{attr} is required") unless valid
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ def fail!(message)
26
+ context.fail!(error: message)
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sequel'
4
+
5
+ module Overture
6
+ Model = Class.new(Sequel::Model)
7
+ Model.def_Model(self)
8
+ Model.plugin :timestamps, update_on_create: true
9
+ Model.plugin :many_through_many
10
+ Model.plugin :defaults_setter
11
+ end
12
+
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bcrypt'
4
+
5
+ module Overture
6
+ module PasswordDigester
7
+ def valid_password?(password_digest, password)
8
+ BCrypt::Password.new(password_digest).is_password?(password)
9
+ rescue BCrypt::Errors::InvalidHash
10
+ false
11
+ end
12
+
13
+ def digest_password(password, cost: BCrypt::Engine.cost)
14
+ BCrypt::Password.create(password, cost: cost)
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Overture
4
+ VERSION = '0.1.0'
5
+ end
6
+
data/lib/tasks/db.rake ADDED
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sequel'
4
+
5
+ Sequel.extension :migration
6
+
7
+ namespace :db do
8
+ desc 'Run migrations for $DATABASE_URL'
9
+ task :migrate, [:version] do |_t, args|
10
+ require_relative '../overture/database'
11
+
12
+ DB ||= Overture::Database.connect(ENV['DATABASE_URL'])
13
+ version = args[:version].to_i if args[:version]
14
+
15
+ def pk_uuid(name)
16
+ column name, :uuid, primary_key: true, default: Sequel.function(:uuid_generate_v4)
17
+ end
18
+
19
+ puts "Migrating database to #{version ? "version #{version}" : 'latest version'}..."
20
+ Sequel::Migrator.run(DB, 'migrations', target: version)
21
+ end
22
+
23
+ desc 'Resets $DATABASE_URL schema to latest version'
24
+ task :reset do
25
+ Rake::Task['db:migrate'].reenable
26
+ Rake::Task['db:migrate'].invoke(0)
27
+ Rake::Task['db:migrate'].reenable
28
+ Rake::Task['db:migrate'].invoke
29
+ end
30
+
31
+ namespace :test do
32
+ desc 'Resets $TEST_DATABASE_URL database schema to latest version'
33
+ task :reset do
34
+ ENV['RACK_ENV'] = 'test'
35
+ ENV['DATABASE_URL'] = ENV['TEST_DATABASE_URL']
36
+
37
+ Rake::Task['db:migrate'].reenable
38
+ Rake::Task['db:migrate'].invoke(0)
39
+ Rake::Task['db:migrate'].reenable
40
+ Rake::Task['db:migrate'].invoke
41
+ end
42
+ end
43
+ end
44
+
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: overture
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - edgarjs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bcrypt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: interactor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sequel_pg
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.11'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.11'
69
+ - !ruby/object:Gem::Dependency
70
+ name: tzinfo
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: tzinfo-data
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.2018'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.2018'
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '5.11'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '5.11'
111
+ - !ruby/object:Gem::Dependency
112
+ name: minitest-reporters
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.3'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.3'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '12'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '12'
139
+ description: |
140
+ Tools and configurations based on the Clean Architecture.
141
+
142
+ This gem contains the basic configuration options and file
143
+ organization to create a Ruby application.
144
+
145
+ Sinatra is used as a delivery layer, but it can be easily
146
+ replaced. Core business rules live in the Interactors.
147
+ email: edgar.js@gmail.com
148
+ executables:
149
+ - overture-migration
150
+ extensions: []
151
+ extra_rdoc_files: []
152
+ files:
153
+ - README.md
154
+ - bin/overture-migration
155
+ - lib/overture.rb
156
+ - lib/overture/database.rb
157
+ - lib/overture/interactor.rb
158
+ - lib/overture/model.rb
159
+ - lib/overture/password_digester.rb
160
+ - lib/overture/version.rb
161
+ - lib/tasks/db.rake
162
+ homepage: https://github.com/edgarjs/overture
163
+ licenses:
164
+ - MIT
165
+ metadata: {}
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ requirements: []
181
+ rubyforge_project:
182
+ rubygems_version: 2.7.6
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: Tools and configurations for your web app.
186
+ test_files: []