gistal 0.1.1

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/gistal +18 -0
  3. data/lib/gistal.rb +54 -0
  4. metadata +46 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 25743e9b3af6ea80a94e0fdcb6032b907b4d7272
4
+ data.tar.gz: 81dc932346b03afb3a198e9560c7b7cdae8abdc6
5
+ SHA512:
6
+ metadata.gz: 59cfb53041f6acc39615ee165cb16a576bb3ea5a91db3be2ace38e3f778a27979d414ff6d0c7b39f538a91bc8d4e7e9e23efa192023ec1a819afa2540eaf075e
7
+ data.tar.gz: d41bb7874fe8cdcbe0ca6570cc7599ceeb6bcc08a4c6a0531da39346d664a5ac848b6a5af5271506e744c3a1175e91e667b9e912686b988a4ff2c19abde948da
data/bin/gistal ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gistal'
4
+
5
+ config_filename = ARGV[0]
6
+ if config_filename.nil? || config_filename.empty?
7
+ puts "config file not given"
8
+ return
9
+ end
10
+
11
+ config_file = File.join(`pwd`.strip, config_filename)
12
+
13
+ unless File.exists?(config_file)
14
+ puts "#{config_filename} not exists"
15
+ return
16
+ end
17
+
18
+ Gistal.new(config_file).parse
data/lib/gistal.rb ADDED
@@ -0,0 +1,54 @@
1
+ require 'yaml'
2
+ require 'json'
3
+ require 'pathname'
4
+
5
+ class Gistal
6
+ def initialize(config_fielname)
7
+ load_config(config_fielname)
8
+ end
9
+
10
+ def load_config(filename)
11
+ @config = YAML.load_file(filename)
12
+ @home_path = File.dirname(filename)
13
+ @lock = File.join(@home_path, 'gistr.lock')
14
+ end
15
+
16
+ def parse
17
+ @config['gists'].each do |item|
18
+ gist_result = get_gist(item)
19
+
20
+ item['files'].each do |file_config|
21
+ gist_file = gist_result['files'][file_config['source']]
22
+
23
+ dest_filename = file_config['name'] || gist_file['filename']
24
+ dest_folder = file_config['dest'] || item['dest'] || item['id']
25
+
26
+ dest_fullpath = File.join(@home_path, dest_folder, dest_filename)
27
+
28
+ write_content(file_config['source'], dest_fullpath, gist_file['raw_url'])
29
+ chmod(dest_fullpath, file_config['chmod'])
30
+ end
31
+ end
32
+ end
33
+
34
+ def get_gist(config)
35
+ puts "Processing [#{config['name']}](#{config['id']})"
36
+ JSON.parse `curl -s https://api.github.com/gists/#{config['id']}`
37
+ end
38
+
39
+ def write_content(source, fullpath, content_url)
40
+ puts "- saving #{source} => #{get_relative_path(fullpath)}"
41
+ `curl -s #{content_url} --create-dirs -o "#{fullpath}"`
42
+ end
43
+
44
+ def chmod(fullpath, mod)
45
+ return if mod.nil? || mod.empty?
46
+
47
+ puts "- changing #{File.basename(fullpath)} => #{mod}"
48
+ `chmod #{mod} "#{fullpath}"`
49
+ end
50
+
51
+ def get_relative_path(first, second = @home_path)
52
+ Pathname.new(first).relative_path_from(Pathname.new(second))
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gistal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Bevis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-01-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Load multiple gist sources by config
14
+ email: i@bevis.me
15
+ executables:
16
+ - gistal
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/gistal
21
+ - lib/gistal.rb
22
+ homepage: http://github.com/beviz/gistal
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.6.14
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Gists loader
46
+ test_files: []