difgist 0.0.12

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.
data/.gemtest ADDED
File without changes
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ === 0.0.1 - 0.0.12 2013-03-16
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,13 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ bin/difgist
7
+ lib/difgist.rb
8
+ lib/difgist/difgist.rb
9
+ script/console
10
+ script/destroy
11
+ script/generate
12
+ test/test_difgist.rb
13
+ test/test_helper.rb
data/PostInstall.txt ADDED
@@ -0,0 +1,7 @@
1
+
2
+ For more information on difgist, see http://difgist.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
data/README.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ = difgist
2
+
3
+ * http://github.com/nerocrux/difgist
4
+
5
+ == DESCRIPTION:
6
+
7
+ FIX (describe your package)
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * FIX (sudo gem install, anything else)
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2013 peichao.yu
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/difgist'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'difgist' do
14
+ self.developer 'nerocrux', 'nerocrux@gmail.com'
15
+ self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
+ self.rubyforge_name = self.name # TODO this is default value
17
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
18
+
19
+ end
20
+
21
+ require 'newgem/tasks'
22
+ Dir['tasks/**/*.rake'].each { |t| load t }
23
+
24
+ # TODO - want other tests/tasks run by default? Add them to the list
25
+ # remove_task :default
26
+ # task :default => [:spec, :features]
data/bin/difgist ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created on 2013-3-12.
4
+ # Copyright (c) 2013. All rights reserved.
5
+
6
+ require 'rubygems'
7
+ require File.join(File.dirname(File.expand_path(__FILE__)), %w{ .. lib difgist difgist })
8
+
9
+ system("touch ~/.difgist.yml;touch ~/.difgist.diff")
10
+ difgist = Difgist.new(ARGV)
11
+ difgist.run
data/lib/difgist.rb ADDED
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module Difgist
5
+ VERSION = '0.0.12'
6
+ end
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/ruby
2
+ require 'rubygems'
3
+ require 'rest-client'
4
+ require 'json'
5
+ require 'optparse'
6
+ require 'yaml'
7
+ require 'pathname'
8
+
9
+ class Difgist
10
+
11
+ def initialize(arguments)
12
+ @config_yml = File.expand_path("~/.difgist.yml")
13
+ @diff_file = File.expand_path("~/.difgist.diff")
14
+ @params = ["hostname", "username", "password"]
15
+ @options = {}
16
+ @settings = {}
17
+ load_config
18
+ set_options(arguments)
19
+ check_options
20
+ end
21
+
22
+ def load_config
23
+ config = YAML.load_file(@config_yml)
24
+ is_initialized = true
25
+ @params.each{|key|
26
+ if not config or not config.has_key?(:"#{key}")
27
+ is_initialized = false
28
+ break
29
+ else @settings[:"#{key}"] = config[:"#{key}"]
30
+ end
31
+ }
32
+ if not is_initialized
33
+ init_config
34
+ end
35
+ end
36
+
37
+ def init_config
38
+ print "Initializing...\n"
39
+ # hostname
40
+ print "= hit enter if you want yo use github, or enter endpoint url if you use github enterprise =\n"
41
+ print "[hostname]: "
42
+ hostname = gets.strip
43
+ if hostname == "" then @settings[:hostname] = "api.github.com" else @settings[:hostname] = hostname end
44
+ # username
45
+ print "[username]: "
46
+ @settings[:username] = gets.strip
47
+ # password
48
+ print "[password]: "
49
+ @settings[:password] = gets.strip
50
+ # finish
51
+ print "Init done. [username] = #{@settings[:username]}, [hostname] = #{@settings[:hostname]}\n"
52
+ # write to yml
53
+ File.open(@config_yml, "w") {|f| f.write(YAML.dump(@settings)) }
54
+ system("chmod 600 #{@config_yml}")
55
+ end
56
+
57
+ def set_options(arguments)
58
+ @optparse = OptionParser.new
59
+ @optparse.banner = "Usage: -d --description, -f -file"
60
+ @optparse.on('-d value','--description value') { |opt| @options[:description] = opt }
61
+ @optparse.on('-f value','--file value') { |opt| @options[:target_file] = opt }
62
+ begin
63
+ @optparse.parse!(arguments)
64
+ rescue
65
+ puts "Bad params."
66
+ exit
67
+ end
68
+ end
69
+
70
+ def check_options
71
+ if @options[:description] == nil
72
+ then description = "posted by difgist"
73
+ end
74
+ if @options[:target_file] == nil
75
+ then target_file = ""
76
+ else
77
+ if File.exist?("#{@options[:target_file]}") == false
78
+ puts "No such file. Dump diff."
79
+ @options[:target_file] = ""
80
+ end
81
+ end
82
+ end
83
+
84
+ def run
85
+ begin
86
+ if @options[:target_file] != nil
87
+ @diff_file = @options[:target_file]
88
+ @filename = Pathname.new("#{@options[:target_file]}").basename
89
+ else
90
+ if File.exist?(".svn")
91
+ then
92
+ system("LANG=C svn diff #{@options[:target_file]} > #{@diff_file}")
93
+ elsif system('git rev-parse --is-inside-work-tree >/dev/null 2>&1') == true
94
+ then
95
+ system("git diff #{@options[:target_file]} > #{@diff_file}")
96
+ else
97
+ end
98
+ @filename = 'difgist.diff'
99
+ end
100
+
101
+ payload = nil
102
+ File.open(@diff_file, "r") do |f|
103
+ payload = {
104
+ :description => @options[:description],
105
+ :public => true,
106
+ :files => {
107
+ @filename => {
108
+ :content => f.read
109
+ }
110
+ }
111
+ }
112
+ response = JSON.parse(RestClient.post("https://#{@settings[:username]}:#{@settings[:password]}@#{@settings[:hostname]}/gists", payload.to_json, :content_type => "text/json"))
113
+ puts "Done. " + response['html_url']
114
+ end
115
+ rescue
116
+ puts "Error."
117
+ end
118
+ end
119
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/difgist.rb'}"
9
+ puts "Loading difgist gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestDifgist < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/difgist'
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: difgist
3
+ version: !ruby/object:Gem::Version
4
+ hash: 7
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 12
10
+ version: 0.0.12
11
+ platform: ruby
12
+ authors:
13
+ - nerocrux
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-03-16 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rdoc
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 19
29
+ segments:
30
+ - 3
31
+ - 10
32
+ version: "3.10"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: newgem
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 5
44
+ segments:
45
+ - 1
46
+ - 5
47
+ - 3
48
+ version: 1.5.3
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: hoe
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 13
60
+ segments:
61
+ - 3
62
+ - 5
63
+ version: "3.5"
64
+ type: :development
65
+ version_requirements: *id003
66
+ description: FIX (describe your package)
67
+ email:
68
+ - nerocrux@gmail.com
69
+ executables:
70
+ - difgist
71
+ extensions: []
72
+
73
+ extra_rdoc_files:
74
+ - History.txt
75
+ - Manifest.txt
76
+ - PostInstall.txt
77
+ - README.rdoc
78
+ files:
79
+ - History.txt
80
+ - Manifest.txt
81
+ - PostInstall.txt
82
+ - README.rdoc
83
+ - Rakefile
84
+ - bin/difgist
85
+ - lib/difgist.rb
86
+ - lib/difgist/difgist.rb
87
+ - script/console
88
+ - script/destroy
89
+ - script/generate
90
+ - test/test_difgist.rb
91
+ - test/test_helper.rb
92
+ - .gemtest
93
+ homepage: http://github.com/nerocrux/difgist
94
+ licenses: []
95
+
96
+ post_install_message: PostInstall.txt
97
+ rdoc_options:
98
+ - --main
99
+ - README.rdoc
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ requirements: []
121
+
122
+ rubyforge_project: difgist
123
+ rubygems_version: 1.8.10
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: FIX (describe your package)
127
+ test_files:
128
+ - test/test_difgist.rb
129
+ - test/test_helper.rb