jott 0.1.4 → 0.1.6

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: cbe57b0abd9bbab0015e3e3979403190e3747df1dbd4cbddfcaa6a5ecb9a31ee
4
- data.tar.gz: a7240c6740a2fe368ef2ccba37d7c0c9a2fd78701da6b98532d6af906df921a3
3
+ metadata.gz: dddda1ff591c566dc59bd17103d0c77b4d7d4004a577f32432136cabbddc5b85
4
+ data.tar.gz: 62e7c74f6b2723a6e34305e6f8635ac74039bd1e71eecb718ebf84c0e83a205d
5
5
  SHA512:
6
- metadata.gz: cdf341a7c114d92b80501cfafb8113a44fe6a21f0bb474861d70331d4be52796b8902b29c4906a5761699f2f3ab87dde37bbd8d7e8d0e4fe4bb66c2be7eea0dd
7
- data.tar.gz: 2467e581e4058f9a07a9cdc6a8f8b459044560b7d1546df934848a399ff38b722c03c9dce999e5de512bdf0fb061040634dffa1bf207250e1a6e399cc77bd2b2
6
+ metadata.gz: d8a7fed13bc01ab9456c90dc2f82089982d833a8003412bca61209e4c32e861733105bae955f2accf2e9fd27a0e49eef66d9973f287b509698a85b127f476b14
7
+ data.tar.gz: 128923d9495608f7a40a76007aa48605cb6e56ae141649e2b8c54cbedc68a3e5a01bebea640481091daa92b7e32283b97cfb201cc847a4ddad3e911bd263ff84
data/.rubocop.yml CHANGED
@@ -1,13 +1,13 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.6
2
+ TargetRubyVersion: 3.1
3
3
 
4
4
  Style/StringLiterals:
5
5
  Enabled: true
6
- EnforcedStyle: double_quotes
6
+ EnforcedStyle: single_quotes
7
7
 
8
8
  Style/StringLiteralsInInterpolation:
9
9
  Enabled: true
10
- EnforcedStyle: double_quotes
10
+ EnforcedStyle: single_quotes
11
11
 
12
12
  Layout/LineLength:
13
13
  Max: 120
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source "https://rubygems.org"
3
+ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in jott.gemspec
6
6
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jott (0.1.3)
4
+ jott (0.1.6)
5
5
  colorize
6
6
  sqlite3
7
7
  thor
@@ -10,15 +10,18 @@ GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  ast (2.4.2)
13
- colorize (0.8.1)
13
+ colorize (1.1.0)
14
14
  diff-lcs (1.5.0)
15
15
  json (2.6.3)
16
- parallel (1.22.1)
17
- parser (3.2.2.0)
16
+ language_server-protocol (3.17.0.3)
17
+ parallel (1.23.0)
18
+ parser (3.2.2.4)
18
19
  ast (~> 2.4.1)
20
+ racc
21
+ racc (1.7.1)
19
22
  rainbow (3.1.1)
20
- regexp_parser (2.8.0)
21
- rexml (3.2.5)
23
+ regexp_parser (2.8.2)
24
+ rexml (3.2.6)
22
25
  rspec (3.12.0)
23
26
  rspec-core (~> 3.12.0)
24
27
  rspec-expectations (~> 3.12.0)
@@ -32,22 +35,23 @@ GEM
32
35
  diff-lcs (>= 1.2.0, < 2.0)
33
36
  rspec-support (~> 3.12.0)
34
37
  rspec-support (3.12.0)
35
- rubocop (1.50.2)
38
+ rubocop (1.57.2)
36
39
  json (~> 2.3)
40
+ language_server-protocol (>= 3.17.0)
37
41
  parallel (~> 1.10)
38
- parser (>= 3.2.0.0)
42
+ parser (>= 3.2.2.4)
39
43
  rainbow (>= 2.2.2, < 4.0)
40
44
  regexp_parser (>= 1.8, < 3.0)
41
45
  rexml (>= 3.2.5, < 4.0)
42
- rubocop-ast (>= 1.28.0, < 2.0)
46
+ rubocop-ast (>= 1.28.1, < 2.0)
43
47
  ruby-progressbar (~> 1.7)
44
48
  unicode-display_width (>= 2.4.0, < 3.0)
45
- rubocop-ast (1.28.0)
49
+ rubocop-ast (1.30.0)
46
50
  parser (>= 3.2.1.0)
47
51
  ruby-progressbar (1.13.0)
48
- sqlite3 (1.6.2-x86_64-linux)
49
- thor (1.2.1)
50
- unicode-display_width (2.4.2)
52
+ sqlite3 (1.6.8-x86_64-linux)
53
+ thor (1.3.0)
54
+ unicode-display_width (2.5.0)
51
55
 
52
56
  PLATFORMS
53
57
  x86_64-linux
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
5
 
6
6
  RSpec::Core::RakeTask.new(:spec)
7
7
 
8
- require "rubocop/rake_task"
8
+ require 'rubocop/rake_task'
9
9
 
10
10
  RuboCop::RakeTask.new
11
11
 
data/exe/jott CHANGED
@@ -1,3 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "jott"
4
+ require 'jott'
data/jott.gemspec CHANGED
@@ -1,23 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/jott/version"
3
+ require_relative 'lib/jott/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "jott"
6
+ spec.name = 'jott'
7
7
  spec.version = Jott::VERSION
8
- spec.authors = ["seita1996"]
9
- spec.email = ["tahara.seitaro@gmail.com"]
8
+ spec.authors = ['seita1996']
9
+ spec.email = ['tahara.seitaro@gmail.com']
10
10
 
11
- spec.summary = "CLI application for a little note"
11
+ spec.summary = 'CLI application for a little note'
12
12
  # spec.description = "TODO: Write a longer description or delete this line."
13
- spec.homepage = "https://rubygems.org/gems/jott"
14
- spec.license = "MIT"
15
- spec.required_ruby_version = ">= 3.1"
13
+ spec.homepage = 'https://rubygems.org/gems/jott'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 3.1'
16
16
 
17
17
  # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
18
 
19
- spec.metadata["homepage_uri"] = spec.homepage
20
- spec.metadata["source_code_uri"] = "https://github.com/seita1996/jott"
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/seita1996/jott'
21
21
  # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
22
 
23
23
  # Specify which files should be added to the gem when it is released.
@@ -27,16 +27,16 @@ Gem::Specification.new do |spec|
27
27
  (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
28
28
  end
29
29
  end
30
- spec.bindir = "exe"
31
- spec.executables = "jott"
32
- spec.require_paths = ["lib"]
30
+ spec.bindir = 'exe'
31
+ spec.executables = 'jott'
32
+ spec.require_paths = ['lib']
33
33
 
34
- spec.add_dependency "colorize"
35
- spec.add_dependency "sqlite3"
36
- spec.add_dependency "thor"
34
+ spec.add_dependency 'colorize'
35
+ spec.add_dependency 'sqlite3'
36
+ spec.add_dependency 'thor'
37
37
 
38
- spec.add_development_dependency("rspec", "~> 3.0")
39
- spec.add_development_dependency("rubocop", "~> 1.21")
38
+ spec.add_development_dependency('rspec', '~> 3.0')
39
+ spec.add_development_dependency('rubocop', '~> 1.21')
40
40
 
41
41
  # For more information and examples about making a new gem, check out our
42
42
  # guide at: https://bundler.io/guides/creating_gem.html
data/lib/jott/cli.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'colorize'
2
4
  require 'tempfile'
3
5
  require 'thor'
@@ -6,14 +8,13 @@ require_relative 'memo'
6
8
  require_relative 'version'
7
9
 
8
10
  class CLI < Thor
9
- desc "clear", "clear all memos"
10
- method_option :aliases => "-cl"
11
+ desc 'clear', 'clear all memos'
11
12
  def clear
12
13
  Memo.new.clear
13
- puts "Clear all memos".colorize(:green)
14
+ puts 'Clear all memos'.colorize(:green)
14
15
  end
15
16
 
16
- desc "add", "Add a new memo"
17
+ desc 'add', 'Add a new memo'
17
18
  def add(*str)
18
19
  if str.empty? # open text editor
19
20
  tempfile = Tempfile.new
@@ -21,70 +22,80 @@ class CLI < Thor
21
22
  text = File.read(tempfile.path)
22
23
  tempfile.unlink
23
24
  else # add memo from command line
24
- text = str.join(" ")
25
+ text = str.join(' ')
26
+ end
27
+
28
+ if text.chomp == ''
29
+ puts 'Please enter text.'.colorize(:red)
30
+ exit
25
31
  end
32
+
26
33
  title = text[0, 30]
27
34
  Memo.new.create(title:, body: text)
28
35
  puts "Added new memo: #{title}".colorize(:green)
29
36
  end
30
37
 
31
- desc "delete", "delete memo ID"
38
+ desc 'delete', 'delete memo ID'
32
39
  def rm(id)
33
40
  Memo.new.delete(id:)
34
41
  puts "Deleted the memo: #{id}".colorize(:green)
35
42
  end
36
43
 
37
- desc "edit", "open the memo with text editor and update"
44
+ desc 'edit', 'open the memo with text editor and update'
38
45
  def edit(*args)
39
46
  id = args.first
40
47
  id = Memo.new.last[0][0] if id.nil?
41
- str = args[1..-1]
48
+ str = args[1..]
42
49
  memo = Memo.new.find(id)
43
50
 
44
51
  if str.nil? || str.empty? # open text editor
45
52
  tempfile = Tempfile.new
46
- File.open(tempfile.path, "w") do |f|
53
+ File.open(tempfile.path, 'w') do |f|
47
54
  f.puts memo[0][2]
48
55
  end
49
56
  system(editor, tempfile.path)
50
- data = File.read(tempfile.path)
51
- Memo.new.update(id: id, title: data[0, 30], body: data)
57
+ text = File.read(tempfile.path)
52
58
  tempfile.unlink
53
- puts "Edited the memo: #{id}".colorize(:green)
54
59
  else # add memo from command line
55
- text = str.join(" ")
56
- title = text[0, 30]
57
- Memo.new.update(id: id, title: title, body: text)
58
- puts "Edited the memo: #{id}".colorize(:green)
60
+ text = str.join(' ')
59
61
  end
62
+
63
+ if text.chomp == ''
64
+ puts 'Please enter text.'.colorize(:red)
65
+ exit
66
+ end
67
+
68
+ title = text[0, 30]
69
+ Memo.new.update(id:, title:, body: text)
70
+ puts "Edited the memo: #{id}".colorize(:green)
60
71
  end
61
72
 
62
- desc "list", "list all memos"
73
+ desc 'list', 'list all memos'
63
74
  def ls
64
75
  memos = Memo.new.all
65
76
  memos.each do |memo|
66
- puts "#{memo[0]}. #{memo[1]}: #{memo[2]}"
77
+ puts "#{memo[0]}. #{memo[1]}"
67
78
  end
68
79
  end
69
80
 
70
- desc "show", "show memo ID"
81
+ desc 'show', 'show memo ID'
71
82
  def show(id)
72
83
  memo = Memo.new.find(id)
73
- puts "#{memo[0][2]}"
84
+ puts(memo[0][2])
74
85
  end
75
86
 
76
- desc "set-editor", "Set the default editor"
87
+ desc 'set-editor', 'Set the default editor'
77
88
  def set_editor(editor)
78
89
  Config.new.set_editor(editor)
79
90
  puts "Set editor: #{editor}".colorize(:green)
80
91
  end
81
92
 
82
- desc "config", "Show the current configuration"
93
+ desc 'config', 'Show the current configuration'
83
94
  def config
84
95
  puts "editor: #{editor}"
85
96
  end
86
97
 
87
- desc "version", "show version"
98
+ desc 'version', 'show version'
88
99
  def version
89
100
  puts "jott version #{Jott::VERSION}"
90
101
  end
data/lib/jott/config.rb CHANGED
@@ -1,28 +1,25 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Config
2
4
  attr_reader :editor
3
5
 
4
6
  def initialize
5
- @file_path = File.join("#{File.dirname(__FILE__)}", "jott.config")
6
- unless File.exist?(@file_path)
7
- File.new(@file_path, "w")
8
- end
7
+ @file_path = File.join(File.dirname(__FILE__).to_s, 'jott.config')
8
+ File.new(@file_path, 'w') unless File.exist?(@file_path)
9
9
  @editor = get_editor
10
10
  end
11
11
 
12
12
  def get_editor
13
- File.open(@file_path, "r") do |file|
13
+ File.open(@file_path, 'r') do |file|
14
14
  file.each_line do |line|
15
- if line.include?("editor")
16
- return line.split(":")[1].strip
17
- else
18
- return "vi"
19
- end
15
+ return line.split(':')[1].strip if line.include?('editor')
20
16
  end
21
17
  end
18
+ 'vi'
22
19
  end
23
20
 
24
21
  def set_editor(editor)
25
- File.open(@file_path, "w") do |file|
22
+ File.open(@file_path, 'w') do |file|
26
23
  file.puts "editor: #{editor}"
27
24
  end
28
25
  @editor = editor
data/lib/jott/memo.rb CHANGED
@@ -1,42 +1,44 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sqlite3'
2
4
 
3
5
  class Memo
4
6
  def initialize
5
- @db = SQLite3::Database.new(File.join(File.dirname(__FILE__), "jott.db"))
6
- @db.execute("CREATE TABLE IF NOT EXISTS memos(id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, body TEXT)")
7
+ @db = SQLite3::Database.new(File.join(File.dirname(__FILE__), 'jott.db'))
8
+ @db.execute('CREATE TABLE IF NOT EXISTS memos(id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, body TEXT)')
7
9
  end
8
10
 
9
11
  def all
10
- @db.execute("SELECT * FROM memos")
12
+ @db.execute('SELECT * FROM memos')
11
13
  end
12
14
 
13
15
  def clear
14
- @db.execute("DROP TABLE memos")
16
+ @db.execute('DROP TABLE memos')
15
17
  end
16
18
 
17
19
  def count
18
- @db.execute("SELECT COUNT(id) FROM memos")
20
+ @db.execute('SELECT COUNT(id) FROM memos')
19
21
  end
20
22
 
21
23
  def create(title:, body:)
22
- title = title.gsub(/\n/, "")
23
- @db.execute("INSERT INTO memos(title, body) VALUES (?, ?)", [title, body])
24
+ title = title.gsub(/\n/, '')
25
+ @db.execute('INSERT INTO memos(title, body) VALUES (?, ?)', [title, body])
24
26
  end
25
27
 
26
28
  def delete(id:)
27
- @db.execute("DELETE FROM memos WHERE id = ?", id)
29
+ @db.execute('DELETE FROM memos WHERE id = ?', id)
28
30
  end
29
31
 
30
32
  def find(id)
31
- @db.execute("SELECT * FROM memos WHERE id = ?", id)
33
+ @db.execute('SELECT * FROM memos WHERE id = ?', id)
32
34
  end
33
35
 
34
36
  def last
35
- @db.execute("SELECT max(id), * FROM memos")
37
+ @db.execute('SELECT max(id), * FROM memos')
36
38
  end
37
39
 
38
40
  def update(id:, title:, body:)
39
- title = title.gsub(/\n/, "")
40
- @db.execute("UPDATE memos SET title = ?, body = ? WHERE id = ?", [title, body, id])
41
+ title = title.gsub(/\n/, '')
42
+ @db.execute('UPDATE memos SET title = ?, body = ? WHERE id = ?', [title, body, id])
41
43
  end
42
44
  end
data/lib/jott/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jott
4
- VERSION = "0.1.4"
4
+ VERSION = '0.1.6'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jott
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - seita1996
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-30 00:00:00.000000000 Z
11
+ date: 2023-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize