gist_updater 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/exe/gist_updater ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'gist_updater'
5
+
6
+ GistUpdater::Commands.start
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'gist_updater/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'gist_updater'
9
+ spec.version = GistUpdater::VERSION
10
+ spec.authors = ['Takashi Masuda']
11
+ spec.email = ['masutaka.net@gmail.com']
12
+
13
+ spec.summary = 'Updates your Gist files'
14
+ spec.description = 'Updates your Gist files which defined in YAML'
15
+ spec.homepage = 'https://github.com/masutaka/gist_updater'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_dependency 'octokit', '~> 4.0'
26
+ spec.add_dependency 'thor', '~> 0.19.1'
27
+
28
+ spec.add_development_dependency 'bundler', '~> 1.13'
29
+ spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.0'
31
+ spec.add_development_dependency 'rubocop', '~> 0.43.0'
32
+ end
@@ -0,0 +1,16 @@
1
+ -
2
+ # https://gist.github.com/masutaka/8177244
3
+ - 8177244
4
+ - .emacs.d/init.el
5
+ -
6
+ # https://gist.github.com/masutaka/9642146
7
+ - 9642146
8
+ - bin/my-brew-bundle
9
+ -
10
+ # https://gist.github.com/masutaka/9287567
11
+ - 9287567
12
+ - .zshenv
13
+ -
14
+ # https://gist.github.com/masutaka/9287575
15
+ - 9287575
16
+ - .zshrc
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'thor'
4
+ require 'yaml'
5
+
6
+ module GistUpdater
7
+ class Commands < Thor
8
+ package_name 'gist_updater'
9
+ default_task :update
10
+ class_option :yaml, type: :string, aliases: :y,
11
+ desc: 'User definition YAML file',
12
+ default: 'gist_updater.yml'
13
+ class_option :user, type: :string, aliases: :u,
14
+ desc: 'GitHub username'
15
+ class_option :token, type: :string, aliases: :t,
16
+ desc: 'GitHub personal access token'
17
+ class_option :debug, type: :boolean, aliases: :d,
18
+ desc: 'Debug mode', default: false
19
+
20
+ desc 'update', 'Update your Gist files (default)'
21
+ def update
22
+ configs.each do |config|
23
+ content = ContentFactory.build(user, access_token, config)
24
+
25
+ if content.gist == content.local
26
+ puts <<~EOS if options[:debug]
27
+ There was no need to update `#{content.name}`.
28
+ EOS
29
+ else
30
+ content.update
31
+ end
32
+ end
33
+ end
34
+
35
+ desc 'version', 'Display version'
36
+ def version
37
+ puts VERSION
38
+ end
39
+
40
+ private
41
+
42
+ def configs
43
+ @configs ||= YAML.load(IO.read(options[:yaml]))
44
+ end
45
+
46
+ def user
47
+ @user ||= options[:user] ||
48
+ ENV['GISTUPDATER_USER'] ||
49
+ help_and_exit
50
+ end
51
+
52
+ def access_token
53
+ @access_token ||= options[:token] ||
54
+ ENV['GISTUPDATER_ACCESS_TOKEN'] ||
55
+ help_and_exit
56
+ end
57
+
58
+ def help_and_exit
59
+ help
60
+ exit(1)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'octokit'
4
+
5
+ module GistUpdater
6
+ class Content
7
+ attr_reader :name
8
+
9
+ def initialize(user:, access_token:, gist_id:, file_name:)
10
+ @client = Octokit::Client.new(
11
+ login: user,
12
+ access_token: access_token
13
+ )
14
+ @gist_id = gist_id
15
+ @name = file_name
16
+ @basename = File.basename(file_name)
17
+ end
18
+
19
+ def gist
20
+ @gist ||= client.gist(gist_id).files[basename].content
21
+ end
22
+
23
+ def local
24
+ @local ||= File.read(name)
25
+ end
26
+
27
+ def update
28
+ result = client.edit_gist(
29
+ gist_id,
30
+ files: { basename => { 'content' => local } }
31
+ )
32
+ puts "Updated `#{name}` to #{result.html_url}"
33
+ result
34
+ end
35
+
36
+ private
37
+
38
+ attr_reader :client, :gist_id, :basename
39
+ end
40
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GistUpdater
4
+ class ContentFactory
5
+ def self.build(user, access_token, config, content_class = Content)
6
+ content_class.new(
7
+ user: user,
8
+ access_token: access_token,
9
+ gist_id: config[0],
10
+ file_name: config[1]
11
+ )
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GistUpdater
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'gist_updater/commands'
4
+ require 'gist_updater/content'
5
+ require 'gist_updater/content_factory'
6
+ require 'gist_updater/version'
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gist_updater
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Takashi Masuda
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octokit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.19.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.19.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.43.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.43.0
97
+ description: Updates your Gist files which defined in YAML
98
+ email:
99
+ - masutaka.net@gmail.com
100
+ executables:
101
+ - gist_updater
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".rubocop.yml"
108
+ - ".ruby-version"
109
+ - CODE_OF_CONDUCT.md
110
+ - Gemfile
111
+ - LICENSE.txt
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - circle.yml
117
+ - disabled.yml
118
+ - enabled.yml
119
+ - exe/gist_updater
120
+ - gist_updater.gemspec
121
+ - gist_updater.yml.example
122
+ - lib/gist_updater.rb
123
+ - lib/gist_updater/commands.rb
124
+ - lib/gist_updater/content.rb
125
+ - lib/gist_updater/content_factory.rb
126
+ - lib/gist_updater/version.rb
127
+ homepage: https://github.com/masutaka/gist_updater
128
+ licenses:
129
+ - MIT
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.5.1
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: Updates your Gist files
151
+ test_files: []