jott 0.1.3 → 0.1.4
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 +4 -4
- data/.ruby-version +1 -0
- data/Gemfile.lock +6 -6
- data/README.md +40 -2
- data/jott.gemspec +1 -1
- data/lib/jott/cli.rb +59 -1
- data/lib/jott/config.rb +30 -0
- data/lib/jott/memo.rb +10 -0
- data/lib/jott/version.rb +1 -1
- metadata +6 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: cbe57b0abd9bbab0015e3e3979403190e3747df1dbd4cbddfcaa6a5ecb9a31ee
         | 
| 4 | 
            +
              data.tar.gz: a7240c6740a2fe368ef2ccba37d7c0c9a2fd78701da6b98532d6af906df921a3
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: cdf341a7c114d92b80501cfafb8113a44fe6a21f0bb474861d70331d4be52796b8902b29c4906a5761699f2f3ab87dde37bbd8d7e8d0e4fe4bb66c2be7eea0dd
         | 
| 7 | 
            +
              data.tar.gz: 2467e581e4058f9a07a9cdc6a8f8b459044560b7d1546df934848a399ff38b722c03c9dce999e5de512bdf0fb061040634dffa1bf207250e1a6e399cc77bd2b2
         | 
    
        data/.ruby-version
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            3.2.2
         | 
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -14,10 +14,10 @@ GEM | |
| 14 14 | 
             
                diff-lcs (1.5.0)
         | 
| 15 15 | 
             
                json (2.6.3)
         | 
| 16 16 | 
             
                parallel (1.22.1)
         | 
| 17 | 
            -
                parser (3.2. | 
| 17 | 
            +
                parser (3.2.2.0)
         | 
| 18 18 | 
             
                  ast (~> 2.4.1)
         | 
| 19 19 | 
             
                rainbow (3.1.1)
         | 
| 20 | 
            -
                regexp_parser (2. | 
| 20 | 
            +
                regexp_parser (2.8.0)
         | 
| 21 21 | 
             
                rexml (3.2.5)
         | 
| 22 22 | 
             
                rspec (3.12.0)
         | 
| 23 23 | 
             
                  rspec-core (~> 3.12.0)
         | 
| @@ -32,20 +32,20 @@ GEM | |
| 32 32 | 
             
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 33 33 | 
             
                  rspec-support (~> 3.12.0)
         | 
| 34 34 | 
             
                rspec-support (3.12.0)
         | 
| 35 | 
            -
                rubocop (1. | 
| 35 | 
            +
                rubocop (1.50.2)
         | 
| 36 36 | 
             
                  json (~> 2.3)
         | 
| 37 37 | 
             
                  parallel (~> 1.10)
         | 
| 38 38 | 
             
                  parser (>= 3.2.0.0)
         | 
| 39 39 | 
             
                  rainbow (>= 2.2.2, < 4.0)
         | 
| 40 40 | 
             
                  regexp_parser (>= 1.8, < 3.0)
         | 
| 41 41 | 
             
                  rexml (>= 3.2.5, < 4.0)
         | 
| 42 | 
            -
                  rubocop-ast (>= 1. | 
| 42 | 
            +
                  rubocop-ast (>= 1.28.0, < 2.0)
         | 
| 43 43 | 
             
                  ruby-progressbar (~> 1.7)
         | 
| 44 44 | 
             
                  unicode-display_width (>= 2.4.0, < 3.0)
         | 
| 45 | 
            -
                rubocop-ast (1. | 
| 45 | 
            +
                rubocop-ast (1.28.0)
         | 
| 46 46 | 
             
                  parser (>= 3.2.1.0)
         | 
| 47 47 | 
             
                ruby-progressbar (1.13.0)
         | 
| 48 | 
            -
                sqlite3 (1.6. | 
| 48 | 
            +
                sqlite3 (1.6.2-x86_64-linux)
         | 
| 49 49 | 
             
                thor (1.2.1)
         | 
| 50 50 | 
             
                unicode-display_width (2.4.2)
         | 
| 51 51 |  | 
    
        data/README.md
    CHANGED
    
    | @@ -1,4 +1,9 @@ | |
| 1 | 
            -
             | 
| 1 | 
            +
            
         | 
| 2 | 
            +
             | 
| 3 | 
            +
             | 
| 4 | 
            +
            [](https://github.com/seita1996/jott/actions/workflows/test.yml)
         | 
| 5 | 
            +
            [](https://opensource.org/licenses/MIT)
         | 
| 6 | 
            +
            
         | 
| 2 7 |  | 
| 3 8 | 
             
            A CLI application that allows you to create small memos.
         | 
| 4 9 | 
             
            It can be installed as a Ruby Gem, and you can create, delete and display memos with the jott command.
         | 
| @@ -14,7 +19,12 @@ $ gem install jott | |
| 14 19 | 
             
            Create a new memo
         | 
| 15 20 |  | 
| 16 21 | 
             
            ```
         | 
| 17 | 
            -
            $ jott add  | 
| 22 | 
            +
            $ jott add This is first memo
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            or
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            $ jott add
         | 
| 27 | 
            +
            -> open your editor
         | 
| 18 28 | 
             
            ```
         | 
| 19 29 |  | 
| 20 30 | 
             
            List memos
         | 
| @@ -23,6 +33,22 @@ List memos | |
| 23 33 | 
             
            $ jott ls
         | 
| 24 34 | 
             
            ```
         | 
| 25 35 |  | 
| 36 | 
            +
            Edit the memo
         | 
| 37 | 
            +
             | 
| 38 | 
            +
            ```
         | 
| 39 | 
            +
            $ jott edit 1 This is updated memo
         | 
| 40 | 
            +
             | 
| 41 | 
            +
            or
         | 
| 42 | 
            +
             | 
| 43 | 
            +
            $ jott edit 1
         | 
| 44 | 
            +
            -> open your editor
         | 
| 45 | 
            +
             | 
| 46 | 
            +
            or
         | 
| 47 | 
            +
             | 
| 48 | 
            +
            $ jott edit
         | 
| 49 | 
            +
            -> open your editor (last memo)
         | 
| 50 | 
            +
            ```
         | 
| 51 | 
            +
             | 
| 26 52 | 
             
            Delete the memo
         | 
| 27 53 |  | 
| 28 54 | 
             
            ```
         | 
| @@ -35,6 +61,18 @@ Clear all memos | |
| 35 61 | 
             
            $ jott clear
         | 
| 36 62 | 
             
            ```
         | 
| 37 63 |  | 
| 64 | 
            +
            Set the editor
         | 
| 65 | 
            +
             | 
| 66 | 
            +
            ```
         | 
| 67 | 
            +
            $ jott set-editor vim
         | 
| 68 | 
            +
            ```
         | 
| 69 | 
            +
             | 
| 70 | 
            +
            Check config
         | 
| 71 | 
            +
             | 
| 72 | 
            +
            ```
         | 
| 73 | 
            +
            $ jott config
         | 
| 74 | 
            +
            ```
         | 
| 75 | 
            +
             | 
| 38 76 | 
             
            ## Development
         | 
| 39 77 |  | 
| 40 78 | 
             
            After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
         | 
    
        data/jott.gemspec
    CHANGED
    
    | @@ -12,7 +12,7 @@ Gem::Specification.new do |spec| | |
| 12 12 | 
             
              # spec.description = "TODO: Write a longer description or delete this line."
         | 
| 13 13 | 
             
              spec.homepage = "https://rubygems.org/gems/jott"
         | 
| 14 14 | 
             
              spec.license = "MIT"
         | 
| 15 | 
            -
              spec.required_ruby_version = ">=  | 
| 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 |  | 
    
        data/lib/jott/cli.rb
    CHANGED
    
    | @@ -1,5 +1,7 @@ | |
| 1 1 | 
             
            require 'colorize'
         | 
| 2 | 
            +
            require 'tempfile'
         | 
| 2 3 | 
             
            require 'thor'
         | 
| 4 | 
            +
            require_relative 'config'
         | 
| 3 5 | 
             
            require_relative 'memo'
         | 
| 4 6 | 
             
            require_relative 'version'
         | 
| 5 7 |  | 
| @@ -12,7 +14,15 @@ class CLI < Thor | |
| 12 14 | 
             
              end
         | 
| 13 15 |  | 
| 14 16 | 
             
              desc "add", "Add a new memo"
         | 
| 15 | 
            -
              def add( | 
| 17 | 
            +
              def add(*str)
         | 
| 18 | 
            +
                if str.empty? # open text editor
         | 
| 19 | 
            +
                  tempfile = Tempfile.new
         | 
| 20 | 
            +
                  system(editor, tempfile.path)
         | 
| 21 | 
            +
                  text = File.read(tempfile.path)
         | 
| 22 | 
            +
                  tempfile.unlink
         | 
| 23 | 
            +
                else # add memo from command line
         | 
| 24 | 
            +
                  text = str.join(" ")
         | 
| 25 | 
            +
                end
         | 
| 16 26 | 
             
                title = text[0, 30]
         | 
| 17 27 | 
             
                Memo.new.create(title:, body: text)
         | 
| 18 28 | 
             
                puts "Added new memo: #{title}".colorize(:green)
         | 
| @@ -24,6 +34,31 @@ class CLI < Thor | |
| 24 34 | 
             
                puts "Deleted the memo: #{id}".colorize(:green)
         | 
| 25 35 | 
             
              end
         | 
| 26 36 |  | 
| 37 | 
            +
              desc "edit", "open the memo with text editor and update"
         | 
| 38 | 
            +
              def edit(*args)
         | 
| 39 | 
            +
                id = args.first
         | 
| 40 | 
            +
                id = Memo.new.last[0][0] if id.nil?
         | 
| 41 | 
            +
                str = args[1..-1]
         | 
| 42 | 
            +
                memo = Memo.new.find(id)
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                if str.nil? || str.empty? # open text editor
         | 
| 45 | 
            +
                  tempfile = Tempfile.new
         | 
| 46 | 
            +
                  File.open(tempfile.path, "w") do |f|
         | 
| 47 | 
            +
                    f.puts memo[0][2]
         | 
| 48 | 
            +
                  end
         | 
| 49 | 
            +
                  system(editor, tempfile.path)
         | 
| 50 | 
            +
                  data = File.read(tempfile.path)
         | 
| 51 | 
            +
                  Memo.new.update(id: id, title: data[0, 30], body: data)
         | 
| 52 | 
            +
                  tempfile.unlink
         | 
| 53 | 
            +
                  puts "Edited the memo: #{id}".colorize(:green)
         | 
| 54 | 
            +
                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)
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
              end
         | 
| 61 | 
            +
             | 
| 27 62 | 
             
              desc "list", "list all memos"
         | 
| 28 63 | 
             
              def ls
         | 
| 29 64 | 
             
                memos = Memo.new.all
         | 
| @@ -32,10 +67,33 @@ class CLI < Thor | |
| 32 67 | 
             
                end
         | 
| 33 68 | 
             
              end
         | 
| 34 69 |  | 
| 70 | 
            +
              desc "show", "show memo ID"
         | 
| 71 | 
            +
              def show(id)
         | 
| 72 | 
            +
                memo = Memo.new.find(id)
         | 
| 73 | 
            +
                puts "#{memo[0][2]}"
         | 
| 74 | 
            +
              end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
              desc "set-editor", "Set the default editor"
         | 
| 77 | 
            +
              def set_editor(editor)
         | 
| 78 | 
            +
                Config.new.set_editor(editor)
         | 
| 79 | 
            +
                puts "Set editor: #{editor}".colorize(:green)
         | 
| 80 | 
            +
              end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
              desc "config", "Show the current configuration"
         | 
| 83 | 
            +
              def config
         | 
| 84 | 
            +
                puts "editor: #{editor}"
         | 
| 85 | 
            +
              end
         | 
| 86 | 
            +
             | 
| 35 87 | 
             
              desc "version", "show version"
         | 
| 36 88 | 
             
              def version
         | 
| 37 89 | 
             
                puts "jott version #{Jott::VERSION}"
         | 
| 38 90 | 
             
              end
         | 
| 91 | 
            +
             | 
| 92 | 
            +
              private
         | 
| 93 | 
            +
             | 
| 94 | 
            +
              def editor
         | 
| 95 | 
            +
                Config.new.editor
         | 
| 96 | 
            +
              end
         | 
| 39 97 | 
             
            end
         | 
| 40 98 |  | 
| 41 99 | 
             
            CLI.start(ARGV)
         | 
    
        data/lib/jott/config.rb
    ADDED
    
    | @@ -0,0 +1,30 @@ | |
| 1 | 
            +
            class Config
         | 
| 2 | 
            +
              attr_reader :editor
         | 
| 3 | 
            +
             | 
| 4 | 
            +
              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
         | 
| 9 | 
            +
                @editor = get_editor
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              def get_editor
         | 
| 13 | 
            +
                File.open(@file_path, "r") do |file|
         | 
| 14 | 
            +
                  file.each_line do |line|
         | 
| 15 | 
            +
                    if line.include?("editor")
         | 
| 16 | 
            +
                      return line.split(":")[1].strip
         | 
| 17 | 
            +
                    else
         | 
| 18 | 
            +
                      return "vi"
         | 
| 19 | 
            +
                    end
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              def set_editor(editor)
         | 
| 25 | 
            +
                File.open(@file_path, "w") do |file|
         | 
| 26 | 
            +
                  file.puts "editor: #{editor}"
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
                @editor = editor
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
            end
         | 
    
        data/lib/jott/memo.rb
    CHANGED
    
    | @@ -19,6 +19,7 @@ class Memo | |
| 19 19 | 
             
              end
         | 
| 20 20 |  | 
| 21 21 | 
             
              def create(title:, body:)
         | 
| 22 | 
            +
                title = title.gsub(/\n/, "")
         | 
| 22 23 | 
             
                @db.execute("INSERT INTO memos(title, body) VALUES (?, ?)", [title, body])
         | 
| 23 24 | 
             
              end
         | 
| 24 25 |  | 
| @@ -26,7 +27,16 @@ class Memo | |
| 26 27 | 
             
                @db.execute("DELETE FROM memos WHERE id = ?", id)
         | 
| 27 28 | 
             
              end
         | 
| 28 29 |  | 
| 30 | 
            +
              def find(id)
         | 
| 31 | 
            +
                @db.execute("SELECT * FROM memos WHERE id = ?", id)
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
             | 
| 29 34 | 
             
              def last
         | 
| 30 35 | 
             
                @db.execute("SELECT max(id), * FROM memos")
         | 
| 31 36 | 
             
              end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
              def update(id:, title:, body:)
         | 
| 39 | 
            +
                title = title.gsub(/\n/, "")
         | 
| 40 | 
            +
                @db.execute("UPDATE memos SET title = ?, body = ? WHERE id = ?", [title, body, id])
         | 
| 41 | 
            +
              end
         | 
| 32 42 | 
             
            end
         | 
    
        data/lib/jott/version.rb
    CHANGED
    
    
    
        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 | 
            +
              version: 0.1.4
         | 
| 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- | 
| 11 | 
            +
            date: 2023-04-30 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: colorize
         | 
| @@ -91,6 +91,7 @@ files: | |
| 91 91 | 
             
            - ".editorconfig"
         | 
| 92 92 | 
             
            - ".rspec"
         | 
| 93 93 | 
             
            - ".rubocop.yml"
         | 
| 94 | 
            +
            - ".ruby-version"
         | 
| 94 95 | 
             
            - CHANGELOG.md
         | 
| 95 96 | 
             
            - CODE_OF_CONDUCT.md
         | 
| 96 97 | 
             
            - Gemfile
         | 
| @@ -102,6 +103,7 @@ files: | |
| 102 103 | 
             
            - jott.gemspec
         | 
| 103 104 | 
             
            - lib/jott.rb
         | 
| 104 105 | 
             
            - lib/jott/cli.rb
         | 
| 106 | 
            +
            - lib/jott/config.rb
         | 
| 105 107 | 
             
            - lib/jott/memo.rb
         | 
| 106 108 | 
             
            - lib/jott/version.rb
         | 
| 107 109 | 
             
            - sig/jott.rbs
         | 
| @@ -119,14 +121,14 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 119 121 | 
             
              requirements:
         | 
| 120 122 | 
             
              - - ">="
         | 
| 121 123 | 
             
                - !ruby/object:Gem::Version
         | 
| 122 | 
            -
                  version:  | 
| 124 | 
            +
                  version: '3.1'
         | 
| 123 125 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 124 126 | 
             
              requirements:
         | 
| 125 127 | 
             
              - - ">="
         | 
| 126 128 | 
             
                - !ruby/object:Gem::Version
         | 
| 127 129 | 
             
                  version: '0'
         | 
| 128 130 | 
             
            requirements: []
         | 
| 129 | 
            -
            rubygems_version: 3.4. | 
| 131 | 
            +
            rubygems_version: 3.4.10
         | 
| 130 132 | 
             
            signing_key: 
         | 
| 131 133 | 
             
            specification_version: 4
         | 
| 132 134 | 
             
            summary: CLI application for a little note
         |