cliz 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/cliz +9 -24
  3. data/lib/functions.rb +30 -3
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: de4a5cd7ac9ce9598f60e1674053920a3362d5cf93a9fc19c1b879845fb06567
4
- data.tar.gz: 23e5e440771e05f9e15a8b8a508de4747fccf613dc1af6e459cce7c9bad85c5c
3
+ metadata.gz: f7e969650b2cf9c73bcc4ccd6828ae1c017e3b28636c53ab5df834f22b3578be
4
+ data.tar.gz: c65d9ec553353788a99a7885582ba078cfde12a8f073a341ed554facdf271ab2
5
5
  SHA512:
6
- metadata.gz: 7e8d8bde06fc90d008c29ccfa234157a9d26d160557ecc6cef78cd201db533c5ec13cedfd1f4a3d05b2b5b33bef7b4dbe43cb4e9611b3025070f3594a0232892
7
- data.tar.gz: 504e21a63bd2359ce50ef4e567fbb3b894c2d92aed4a1c37e2d40f105b4661ba11e698706891a96e564b6ef2cb799c6f0d5ac8cefb527083dab1eeeeab011f1d
6
+ metadata.gz: 42bf0f66ac2f39af3cd067f817251d84f68fa93cc79cb53b8bff39500208e3d817cc6bc10ca41acef0046b61e2b75075b7c66e5d2812c0517c0ec5b6bb56babe
7
+ data.tar.gz: 3055bdfb251fd53754a2d0e1c0ca40f3ca07e6d5b12cafe7bf11fb585978aa510177d74477f350ba1f874d8ad69e2b61d48112b9d7691c90e9b9436c48c7130e
data/bin/cliz CHANGED
@@ -1,42 +1,27 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'securerandom'
4
3
  require 'fileutils'
5
4
  require 'yaml'
6
- require 'fileutils'
7
5
  require_relative '../lib/functions.rb'
8
6
 
9
7
  include Cliz
10
8
 
11
-
12
-
13
9
  config = YAML.load(File.read('config.yml'))
14
10
  output_dir = config['output_dir']
15
11
 
12
+ # Is this the right place for this?
13
+ # Could we have a initialization function?
16
14
  FileUtils.mkdir_p File.join output_dir, 'reverse-index'
17
15
 
18
16
  url = ARGV[0]
19
17
  short_suggestion = ARGV[1]
18
+ short_urls = nil
20
19
 
21
- unless short_suggestion
22
- # check for reverse index
23
- reverse_index_file = File.join output_dir, 'reverse-index', "#{Digest::SHA2.hexdigest url}"
24
-
25
- if File.exist? reverse_index_file
26
- base_domain = config['base_domain']
27
- paths = File.open(reverse_index_file).readlines
28
- for path in paths
29
- puts File.join base_domain, path
30
- end
31
- exit
32
- end
20
+ if short_suggestion
21
+ short_urls = [short(config, url, short_suggestion)]
22
+ else
23
+ short_urls = previously_shortened_urls(config, url)
24
+ short_urls ||= [short(config, url)]
33
25
  end
34
26
 
35
-
36
- short_url = short config, url, short_suggestion
37
-
38
- # do reverse index
39
-
40
- reverse_index config, short_url
41
-
42
- puts short_url
27
+ print_urls(short_urls)
data/lib/functions.rb CHANGED
@@ -71,9 +71,12 @@ module Cliz
71
71
  folder_path = get_a_folder_path output_dir, short_suggestion
72
72
  create_index_file(url, folder_path)
73
73
 
74
- system("sh #{deploy_script}") if deploy_script
74
+ short_url = File.join base_domain, short_suggestion
75
+ reverse_index config, short_url
75
76
 
76
- File.join base_domain, short_suggestion
77
+ system("sh #{deploy_script}") if deploy_script
78
+
79
+ short_url
77
80
  end
78
81
 
79
82
  ##
@@ -94,7 +97,7 @@ module Cliz
94
97
 
95
98
  def reverse_index config, short_url
96
99
  output_dir = config['output_dir']
97
-
100
+
98
101
  long_url = long_url config, short_url
99
102
 
100
103
  reverse_index_file = File.join output_dir, 'reverse-index', "#{Digest::SHA2.hexdigest long_url}"
@@ -104,4 +107,28 @@ module Cliz
104
107
  f.puts path(config, short_url)
105
108
  end
106
109
  end
110
+
111
+ def previously_shortened_urls(config, url)
112
+ output_dir = config['output_dir']
113
+
114
+ reverse_index_file = File.join output_dir, 'reverse-index', "#{Digest::SHA2.hexdigest url}"
115
+
116
+ if File.exist? reverse_index_file
117
+ urls = []
118
+ base_domain = config['base_domain']
119
+ paths = File.open(reverse_index_file).readlines
120
+
121
+ for path in paths
122
+ urls << File.join(base_domain, path)
123
+ end
124
+ end
125
+
126
+ urls
127
+ end
128
+
129
+ def print_urls(urls)
130
+ for url in urls
131
+ puts url
132
+ end
133
+ end
107
134
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cliz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karthikeyan A K