gistim 0.1.1 → 0.2.0

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: c28928cf1dc92cb6a9109e5006c46aea31718e09b5011b8e38f489c741d83127
4
- data.tar.gz: 7c6a1d4d6797d02421bc388458a6c4ca17094ddc103d262e79708ad35b02ca87
3
+ metadata.gz: 84f019162ca9bc2b3c91325fd779c78e3e89bf19869730a3be4351ece6bb3fbb
4
+ data.tar.gz: d50479f09998f99993b8ae07341d42493f82c00e53036486f5565ceb4370fb6d
5
5
  SHA512:
6
- metadata.gz: 8b047dee82c692140bd614751e01370e38ac270ce7abb0261de4d8814ab7178c493d0edb2220594e2914fab6205b00c34049efdb6bd96b31a652d5c09d55ac34
7
- data.tar.gz: 862071d90863a5cee45ff380f053aedf6c16be520af07a26696b87ab80193dccd939e4ec6113fdc482beeeb141692e26bb05a27cbf32a06c6151fc6cf7ad5664
6
+ metadata.gz: 46544d692c449d93fa7742996ee73490af6069f5e41f4610ac8df0dd632df6327d4b051f5af89267254d30c51c5b04f63a6cd8e4d2754ba3275b1ce6cd3de098
7
+ data.tar.gz: 973fe40ec2f905ac6483d3b3393752c9ef73a8b4a7dc8af2ca96ee80f8ca0649dfb8e6ad790d8424a99062b5ea534e97ee1c668b79568ca65f3aa53117e72411
data/.gistim.tmp ADDED
@@ -0,0 +1 @@
1
+ Hello gist!
data/.gitignore CHANGED
@@ -5,7 +5,7 @@
5
5
  /doc/
6
6
  /pkg/
7
7
  /spec/reports/
8
- /tmp/
8
+ */tmp/
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gistim (0.1.1)
4
+ gistim (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -44,7 +44,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
44
44
 
45
45
  ## Contributing
46
46
 
47
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gistim. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/YumaInaura/gistim. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
48
48
 
49
49
  ## License
50
50
 
data/exe/gistim CHANGED
@@ -2,13 +2,37 @@
2
2
 
3
3
  require 'pry'
4
4
  require 'gistim'
5
-
6
5
  subcommand = ARGV[0]
7
6
 
8
- if subcommand == 'clone'
7
+ if subcommand == 'help'
8
+ puts <<~HELP
9
+ $ gistim create some_word
10
+
11
+ Crete new gist and git clone
12
+ HELP
13
+ elsif subcommand == 'clone'
9
14
  Gistim::Clone.clone(ARGV[1], clone_directory: ARGV[2])
10
15
  elsif subcommand == 'create'
11
- Gistim::Create.new(alias_name: ARGV[1]).create
16
+ create = Gistim::Create.new(alias_name: ARGV[1]).implement
17
+ puts "#{create.directory}"
18
+ `cd #{create.directory}` if ARGV.include? ["--cd"]
19
+ elsif ['list', 'history'].include? subcommand
20
+ require 'json'
21
+
22
+ list = `gist --list`
23
+
24
+ history_file_path = "#{Gistim::Command.home}/gist-history.txt"
25
+ File.write(history_file_path, list)
26
+ results = File.read(history_file_path).split("\n").map do |line|
27
+ [
28
+ ["url", line.split(/\s/)[0]],
29
+ ["description", line.split(/\s/)[1..-1].join]
30
+ ].to_h
31
+ end
32
+ # FIXME: escape backslash
33
+ puts JSON.pretty_generate(results, quirks_mode: true)
34
+ elsif ['open'].include? subcommand
35
+ `open $(echo https://gist.github.com/$(git config user.username)/$(git remote -v | head -n 1 | awk '{ print $2 }' | awk -F':' '{ print $2 }'))`
12
36
  else
13
37
  puts <<~TEXT
14
38
  =====================================
@@ -0,0 +1,4 @@
1
+ class Gistim::Command::Create
2
+
3
+
4
+ end
@@ -0,0 +1,17 @@
1
+ module Gistim
2
+ class Command
3
+ def self.home
4
+ path = if ENV['GISTIM_HOME']
5
+ ENV['GISTIM_HOME']
6
+ elsif ENV['HOME']
7
+ "#{ENV['HOME']}/gistim"
8
+ else
9
+ './gistim'
10
+ end
11
+
12
+ FileUtils.mkpath(path)
13
+ path
14
+ end
15
+ end
16
+ end
17
+
data/lib/gistim/create.rb CHANGED
@@ -1,58 +1,65 @@
1
1
  module Gistim
2
2
  class Create
3
- def initialize(alias_name: nil)
3
+ def initialize(description: nil, alias_name: nil)
4
4
  @alias_name = alias_name
5
+ @description = description
5
6
  end
6
7
 
7
- attr_reader :alias_name
8
+ attr_reader :alias_name, :url
8
9
 
9
- def create
10
- File.write(initialize_file_path, 'Wellcome to Gist! ( created by gistim )')
10
+ def implement
11
+ File.write(initialize_file_path, description)
11
12
 
12
- create_empty
13
+ @url = create_empty
13
14
  clone
14
15
 
16
+ File.write(url_file_path, url)
17
+ File.write(hash_file_path, hash)
18
+
15
19
  File.delete(initialize_file_path)
16
-
17
- # FIME: write good structured work flow and good test
18
- # File.write("#{clone_directory}/.gist.url", gist_url)
19
- # File.write("#{clone_directory}/.gist.hash", gist_hash)
20
20
 
21
21
  self
22
22
  end
23
23
 
24
- def gist_hash
25
- gist_url.chomp.gsub(/\A.+\//, '')
24
+ def hash
25
+ url.nil? ? nil : url.chomp.gsub(/\A.+\//, '')
26
26
  end
27
-
27
+
28
+ def description
29
+ @description ||= '# Hello Gist!'
30
+ end
31
+
32
+ def hash_file_path
33
+ "#{directory}/.hash"
34
+ end
35
+
36
+ def url_file_path
37
+ "#{directory}/.url"
38
+ end
39
+
28
40
  private
29
41
 
30
42
  def clone
31
- Clone.clone(gist_url, clone_directory: clone_directory)
43
+ Clone.clone(url, clone_directory: directory)
32
44
  end
33
45
 
34
46
  def create_empty
35
47
  # Execute `$ gist [some_file]` command and get gist url result
36
- @gist_url ||= `gist #{initialize_file_path}`.chomp
37
- end
48
+ url = `gist #{initialize_file_path}`.chomp
38
49
 
39
- def gist_url
40
- @gist_url ||= create_empty
50
+ url
41
51
  end
42
52
 
43
53
  def initialize_file_path
44
- '.gistim.tmp'
54
+ 'GIST.md'
45
55
  end
46
56
 
47
- def clone_directory
48
- alias_name || gist_hash
57
+ def directory
58
+ "#{Gistim::Command.home}/#{name}"
49
59
  end
50
60
 
51
- # public
52
- class << self
53
- def implement
54
- self.class.new.create
55
- end
61
+ def name
62
+ alias_name || hash
56
63
  end
57
64
  end
58
65
  end
@@ -1,3 +1,3 @@
1
1
  module Gistim
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/gistim.rb CHANGED
@@ -2,7 +2,9 @@ require "gistim/version"
2
2
  require 'gist'
3
3
  require 'gistim/clone'
4
4
  require 'gistim/create'
5
+ require 'gistim/command'
5
6
 
6
7
  module Gistim
8
+ HOME = Gistim::Command.home
7
9
  end
8
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gistim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yumainaura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-15 00:00:00.000000000 Z
11
+ date: 2018-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gist
@@ -88,6 +88,7 @@ executables:
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
+ - ".gistim.tmp"
91
92
  - ".github.url"
92
93
  - ".gitignore"
93
94
  - ".rspec"
@@ -103,8 +104,10 @@ files:
103
104
  - bin/setup
104
105
  - exe/gistim
105
106
  - gistim.gemspec
107
+ - lib/command/create.rb
106
108
  - lib/gistim.rb
107
109
  - lib/gistim/clone.rb
110
+ - lib/gistim/command.rb
108
111
  - lib/gistim/create.rb
109
112
  - lib/gistim/version.rb
110
113
  homepage: https://github.com/YumaInaura/gistim