twenty-server 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0d6efa17d0c84f1ff0591bd6bb826fb6b41f1025d03cf1024cf593b053303ee
4
- data.tar.gz: 5f8c54b72b4b50d8a8a233e327f91add68c34696d21e652d57ebee8d458fcef0
3
+ metadata.gz: '09a7504d2ef036f0463b573bd999ec4df8fa5e32a48bd40e7e91e947e5f1a25d'
4
+ data.tar.gz: 6a0e602227119bf35e1857525994e0b019061bc234a0913fc6c9a58dabfbf1da
5
5
  SHA512:
6
- metadata.gz: 0f8a06f4eaa4b6cc964d3b907a80c0646a771987311aa46fccf13b4e78718b1e109af615d92f54709d8f469919fd63e8f8d1f70ace915a44d1bb0f8b2859a75f
7
- data.tar.gz: d7b5b4b9e9a56ac7a90a84bf2ac0c8cf67b720d0f8806deb1d22e0a13cc4ce8c1896a5385e4135ae326a53e48193ea58e44240cd56e93f91d36491f5b262005f
6
+ metadata.gz: 06e09450ff1212091122d480fcb77c3f6d2c319eed0b998986d541f1c5df730cd67b7a98b861336c6dc195e6e46c1d1f452ec09dc39813a177ab80834831b84b
7
+ data.tar.gz: a3adb49e1dd8132ceebfb0d78638d175a0d0a72fab31d12de7445633328e0a8921b68265d7a8c6bffbb3bc3e51d829db7b062a38ae1c4b17a68e585a3610f0b5
@@ -2,7 +2,7 @@
2
2
 
3
3
  Sequel.migration do
4
4
  up do
5
- default = Twenty::ColorableMixin.random_color
5
+ default = Twenty::Mixin::Colorable.random_color
6
6
  add_column :projects, :color, :string, null: false, default:
7
7
  end
8
8
 
@@ -1,25 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Twenty::Migration
4
- require "sequel/extensions/migration"
4
+ Sequel.extension(:migration)
5
+
5
6
  ##
6
7
  # @return [String]
7
- # Returns the path to twenty's migrations.
8
+ # Returns the path to the migrations directory
8
9
  def self.migrations_path
9
10
  File.join(__dir__, "migration")
10
11
  end
11
12
 
12
13
  ##
13
- # Runs migrations (if neccessary).
14
+ # Run migrations
14
15
  # @return [void]
15
- def self.run!
16
- Sequel::Migrator.run(Twenty.connection, migrations_path)
16
+ def self.run!(options = {})
17
+ Sequel::Migrator.run(Twenty.connection, migrations_path, options)
17
18
  end
18
19
 
19
20
  ##
20
21
  # @return [Boolean]
21
- # Returns true when there are pending migrations.
22
+ # Returns true when there are pending migrations
22
23
  def self.pending_migrations?
23
- Sequel::Migrator.is_current?(Twenty.connection, migrations_path)
24
+ ! Sequel::Migrator.is_current?(Twenty.connection, migrations_path)
24
25
  end
25
26
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Twenty::Mixin
4
+ module Colorable
5
+ extend self
6
+
7
+ COLORS = [
8
+ "#222222", "#333333", "#444444", "#555555", "#666666",
9
+ "#777777", "#888888", "#999999", "#AA2222", "#22AA22",
10
+ "#2222AA", "#AA22AA", "#CC9900", "#0099CC", "#9900CC",
11
+ "#FF9900", "#00CC99", "#99CC00", "#CC0099", "#990000",
12
+ "#112233", "#445566", "#778899", "#AA4455", "#5544AA",
13
+ "#88AA44", "#AA88AA", "#CCBB00", "#1155CC", "#9900BB",
14
+ "#DD6600", "#00BBCC", "#CC0099", "#BB3300", "#006688",
15
+ "#993366", "#2200AA", "#557788", "#998877", "#BB4400"
16
+ ]
17
+
18
+ def before_validation
19
+ super if defined?(super)
20
+ set_random_color
21
+ end
22
+
23
+ def random_color
24
+ COLORS.sample
25
+ end
26
+
27
+ private
28
+
29
+ def set_random_color
30
+ return if id
31
+ self.color = random_color
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module Twenty::Mixin
2
+ require_relative "mixin/colorable"
3
+ end
@@ -1,42 +1,44 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Twenty::Project < Sequel::Model
4
- include Twenty::Model
5
- include Twenty::ColorableMixin
3
+ module Twenty
4
+ class Project < Sequel::Model
5
+ include Model
6
+ include Mixin::Colorable
6
7
 
7
- validates_presence_of :name
8
- validates_presence_of :path
9
- one_to_many :tasks, class_name: "Twenty::Task"
8
+ validates_presence_of :name
9
+ validates_presence_of :path
10
+ one_to_many :tasks, class_name: "Twenty::Task"
10
11
 
11
- ##
12
- # @api private
13
- def validate
14
- super
15
- errors.add(:path, "does not exist on disk") if !path_exist?
16
- errors.add(:path, "is not absolute") if !File.absolute_path?(self[:path])
17
- end
12
+ ##
13
+ # @api private
14
+ def validate
15
+ super
16
+ errors.add(:path, "does not exist on disk") if !path_exist?
17
+ errors.add(:path, "is not absolute") if !File.absolute_path?(self[:path])
18
+ end
18
19
 
19
- ##
20
- # @return [String]
21
- # The path to a project
22
- def path
23
- super&.sub(Dir.home, "~")
24
- end
20
+ ##
21
+ # @return [String]
22
+ # The path to a project
23
+ def path
24
+ super&.sub(Dir.home, "~")
25
+ end
25
26
 
26
- ##
27
- # @return [Boolean]
28
- # Returns true when {#path} exists on disk
29
- def path_exist?
30
- File.exist? File.expand_path(path)
31
- end
27
+ ##
28
+ # @return [Boolean]
29
+ # Returns true when {#path} exists on disk
30
+ def path_exist?
31
+ File.exist? File.expand_path(path)
32
+ end
32
33
 
33
- ##
34
- # @return [Integer]
35
- # Returns the number of open tasks a project has
36
- def open_task_count
37
- @open_task_count ||= Twenty::Task
38
- .where(project_id: id)
39
- .where(Sequel.lit("status IN (0,1,2)"))
40
- .count
34
+ ##
35
+ # @return [Integer]
36
+ # Returns the number of open tasks a project has
37
+ def open_task_count
38
+ @open_task_count ||= Twenty::Task
39
+ .where(project_id: id)
40
+ .where(Sequel.lit("status IN (0,1,2)"))
41
+ .count
42
+ end
41
43
  end
42
44
  end
@@ -6,7 +6,6 @@ module Twenty::Model
6
6
  model.plugin(:timestamps, update_on_create: true)
7
7
  end
8
8
 
9
- require_relative "model/mixin/colorable_mixin"
10
9
  require_relative "model/project"
11
10
  require_relative "model/task"
12
11
  end
data/lib/twenty/server.rb CHANGED
@@ -1,22 +1,49 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Twenty
4
- require "fileutils"
5
- require "sequel"
6
- require_relative "server/path"
4
+ extend Module.new {
5
+ require "tmpdir"
6
+ require "fileutils"
7
+ extend self
8
+ extend FileUtils
7
9
 
8
- ##
9
- # @return [String]
10
- # Returns the location of the default SQLite database.
11
- def self.default_database
12
- @default_database ||= File.join(Path.datadir, "database.sqlite")
13
- end
10
+ ##
11
+ # @return [String]
12
+ # Returns the path for the default SQLite database
13
+ def default_database
14
+ @default_database ||= File.join(datadir, "database.sqlite")
15
+ end
16
+
17
+ ##
18
+ # @return [String]
19
+ # Returns the directory where twenty stores data
20
+ def datadir
21
+ File.join(Dir.home, ".local", "share", "twenty")
22
+ end
23
+
24
+ ##
25
+ # @return [String]
26
+ # Returns the directory where twenty stores temporary data
27
+ def tmpdir
28
+ File.join(Dir.tmpdir, "twenty")
29
+ end
30
+
31
+ ##
32
+ # @return [String]
33
+ # Returns the path to a PID file
34
+ def pid
35
+ File.join(tmpdir, "server.pid")
36
+ end
37
+
38
+ mkdir_p(datadir)
39
+ mkdir_p(tmpdir)
40
+ }
14
41
 
15
42
  ##
16
- # Establishes a database connection.
43
+ # Establishes a database connection
17
44
  #
18
45
  # @param [String] path
19
- # The path to a SQLite3 database file.
46
+ # The path to a SQLite database
20
47
  #
21
48
  # @return [void]
22
49
  def self.establish_connection(path:)
@@ -26,12 +53,17 @@ module Twenty
26
53
  )
27
54
  end
28
55
 
56
+ ##
57
+ # @return [Sequel::Database::SQLite]
58
+ # Returns the connection to a database
29
59
  def self.connection
30
60
  establish_connection unless @connection
31
61
  @connection
32
62
  end
33
63
 
34
- FileUtils.touch(default_database)
64
+ require "sequel"
65
+ require_relative "server/mixin"
66
+ require_relative "server/migration"
35
67
  require_relative "server/graphql"
36
68
  require_relative "server/rack"
37
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twenty-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - '0x1eef'
@@ -123,11 +123,11 @@ files:
123
123
  - "./lib/twenty/server/migration/1_create_projects.rb"
124
124
  - "./lib/twenty/server/migration/2_create_tasks.rb"
125
125
  - "./lib/twenty/server/migration/3_add_color_to_projects.rb"
126
+ - "./lib/twenty/server/mixin.rb"
127
+ - "./lib/twenty/server/mixin/colorable.rb"
126
128
  - "./lib/twenty/server/model.rb"
127
- - "./lib/twenty/server/model/mixin/colorable_mixin.rb"
128
129
  - "./lib/twenty/server/model/project.rb"
129
130
  - "./lib/twenty/server/model/task.rb"
130
- - "./lib/twenty/server/path.rb"
131
131
  - "./lib/twenty/server/rack.rb"
132
132
  - "./lib/twenty/server/rack/graphql.rb"
133
133
  - "./share/twenty/server/schema.graphql"
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Twenty::ColorableMixin
4
- extend self
5
-
6
- COLORS = [
7
- "#222222", "#333333", "#444444", "#555555", "#666666",
8
- "#777777", "#888888", "#999999", "#AA2222", "#22AA22",
9
- "#2222AA", "#AA22AA", "#CC9900", "#0099CC", "#9900CC",
10
- "#FF9900", "#00CC99", "#99CC00", "#CC0099", "#990000",
11
- "#112233", "#445566", "#778899", "#AA4455", "#5544AA",
12
- "#88AA44", "#AA88AA", "#CCBB00", "#1155CC", "#9900BB",
13
- "#DD6600", "#00BBCC", "#CC0099", "#BB3300", "#006688",
14
- "#993366", "#2200AA", "#557788", "#998877", "#BB4400"
15
- ]
16
-
17
- def before_validation
18
- super if defined?(super)
19
- set_random_color
20
- end
21
-
22
- def random_color
23
- COLORS.sample
24
- end
25
-
26
- private
27
-
28
- def set_random_color
29
- return if id
30
- self.color = random_color
31
- end
32
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Twenty::Path
4
- require "tmpdir"
5
- extend self
6
-
7
- ##
8
- # @return [String]
9
- # Returns the directory where twenty stores persistent data.
10
- def datadir
11
- File.join(Dir.home, ".local", "share", "twenty")
12
- end
13
-
14
- ##
15
- # @return [String]
16
- # Returns the directory where twenty stores temporary data.
17
- def tmpdir
18
- File.join(Dir.tmpdir, "twenty")
19
- end
20
-
21
- ##
22
- # @return [String]
23
- # Returns the file where twenty can write the PID of
24
- # a web server running in the background.
25
- def pidfile
26
- File.join(tmpdir, "server.pid")
27
- end
28
-
29
- FileUtils.mkdir_p(datadir)
30
- FileUtils.mkdir_p(tmpdir)
31
- end