gisture 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gisture/evaluator.rb +12 -0
- data/lib/gisture/gist.rb +100 -0
- data/lib/gisture/railtie.rb +7 -0
- data/lib/gisture/version.rb +1 -1
- data/lib/gisture.rb +28 -0
- data/lib/tasks/gisture.rake +9 -0
- data/spec/gists/called_class.rb +16 -0
- data/spec/gists/called_method.rb +7 -0
- data/spec/gists/class.rb +13 -0
- data/spec/gists/method.rb +5 -0
- data/spec/gists/simple.rb +3 -0
- data/spec/gisture/evaluator_spec.rb +4 -0
- data/spec/gisture/gist_spec.rb +4 -0
- data/spec/gisture_spec.rb +4 -0
- metadata +49 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63c10c0aa36f2eb7e0eb2db5a9c37476717f1e74
|
4
|
+
data.tar.gz: f30b1941956c1bc94d58f3f352e11760c29de1df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e030f036dd3f9e4351f351d7ed029f0cd0427fac14785206389b7240e88a1f70fc6a96279c9e0edf10ed66fa9c655f3f34e8d3f25554c0eeb9761907797e8904
|
7
|
+
data.tar.gz: 90d4c4092cd55cae22442c3cb589eee2608a5b70409f5f5c23655c22cc45e0430699a4d4393da760f770c38f4beca0f633d7e08749a3f33703568bc62a2da0cf
|
data/lib/gisture/gist.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
3
|
+
module Gisture
|
4
|
+
class Gist
|
5
|
+
attr_reader :filename, :gist_id, :strategy
|
6
|
+
|
7
|
+
STRATEGIES = [:eval, :load, :require]
|
8
|
+
|
9
|
+
def self.run!(gist_id: nil, strategy: nil, filename: nil, &block)
|
10
|
+
new(gist_id: gist_id, strategy: strategy, filename: filename).run!(&block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def run!(&block)
|
14
|
+
send "#{strategy}!".to_sym, &block
|
15
|
+
end
|
16
|
+
|
17
|
+
def require!(&block)
|
18
|
+
required = require tempfile.path
|
19
|
+
unlink_tempfile
|
20
|
+
block_given? ? yield : required
|
21
|
+
end
|
22
|
+
|
23
|
+
def load!(&block)
|
24
|
+
loaded = load tempfile.path
|
25
|
+
unlink_tempfile
|
26
|
+
block_given? ? yield : loaded
|
27
|
+
end
|
28
|
+
|
29
|
+
def eval!(&block)
|
30
|
+
clean_room = Evaluator.new(raw)
|
31
|
+
clean_room.instance_eval &block if block_given?
|
32
|
+
clean_room
|
33
|
+
end
|
34
|
+
|
35
|
+
def github
|
36
|
+
@github ||= begin
|
37
|
+
github_config = Gisture::GITHUB_CONFIG_OPTS.map { |key| [key, Gisture.configuration.send(key)] }.to_h
|
38
|
+
Github.new(github_config)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def gist
|
43
|
+
@gist ||= github.gists.get(gist_id)
|
44
|
+
end
|
45
|
+
|
46
|
+
def gist_file
|
47
|
+
return @gist_file unless @gist_file.nil?
|
48
|
+
|
49
|
+
if gist.files.count > 1
|
50
|
+
raise ArgumentError, "You must specify a filename if your gist contains more than one file" if filename.nil?
|
51
|
+
gist.files.each do |file|
|
52
|
+
@gist_file = file if file[0] == filename
|
53
|
+
end
|
54
|
+
raise ArgumentError, "The filename '#{filename}' was not found in the list of files for the gist '#{gist_id}'" if @gist_file.nil?
|
55
|
+
else
|
56
|
+
@gist_file = gist.files.first
|
57
|
+
end
|
58
|
+
|
59
|
+
@gist_file
|
60
|
+
end
|
61
|
+
|
62
|
+
def raw
|
63
|
+
gist_file[1].content
|
64
|
+
end
|
65
|
+
|
66
|
+
def strategy=(strat)
|
67
|
+
raise ArgumentError, "Invalid strategy '#{strat}'. Must be one of #{STRATEGIES.join(', ')}" unless STRATEGIES.include?(strat.to_sym)
|
68
|
+
@strategy = strat.to_sym
|
69
|
+
end
|
70
|
+
|
71
|
+
def tempfile
|
72
|
+
@tempfile ||= begin
|
73
|
+
file = Tempfile.new([gist_id, '.rb'], Gisture.configuration.tmpdir)
|
74
|
+
file.write(raw)
|
75
|
+
file.close
|
76
|
+
file
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def to_h
|
81
|
+
{ gist_id: gist_id,
|
82
|
+
strategy: strategy,
|
83
|
+
filename: filename }
|
84
|
+
end
|
85
|
+
|
86
|
+
protected
|
87
|
+
|
88
|
+
def initialize(gist_id: nil, strategy: nil, filename: nil)
|
89
|
+
raise ArgumentError, "Invalid gist_id" if gist_id.nil?
|
90
|
+
@gist_id = gist_id
|
91
|
+
@filename = filename
|
92
|
+
self.strategy = strategy || :eval
|
93
|
+
end
|
94
|
+
|
95
|
+
def unlink_tempfile
|
96
|
+
tempfile.unlink
|
97
|
+
@tempfile = nil
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/lib/gisture/version.rb
CHANGED
data/lib/gisture.rb
CHANGED
@@ -1,4 +1,32 @@
|
|
1
|
+
require 'canfig'
|
2
|
+
require 'github_api'
|
1
3
|
require 'gisture/version'
|
4
|
+
require 'gisture/evaluator'
|
5
|
+
require 'gisture/gist'
|
6
|
+
require 'gisture/railtie' if defined?(Rails)
|
2
7
|
|
3
8
|
module Gisture
|
9
|
+
include Canfig::Module
|
10
|
+
|
11
|
+
GITHUB_CONFIG_OPTS = [:basic_auth, :oauth_token, :client_id, :client_secret, :user, :org]
|
12
|
+
|
13
|
+
configure do |config|
|
14
|
+
# config options for the github_api gem
|
15
|
+
config.basic_auth = nil # user:password string
|
16
|
+
config.oauth_token = nil # oauth authorization token
|
17
|
+
config.client_id = nil # oauth client id
|
18
|
+
config.client_secret = nil # oauth client secret
|
19
|
+
config.user = nil # global user used in requets if none provided
|
20
|
+
config.org = nil # global organization used in request if none provided
|
21
|
+
|
22
|
+
config.tmpdir = Dir.tmpdir # location to store gist tempfiles
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.new(gist_id, strategy=nil, filename=nil)
|
26
|
+
Gisture::Gist.new(gist_id: gist_id, strategy: strategy, filename: filename)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.run(gist_id, strategy=nil, filename=nil, &block)
|
30
|
+
new(gist_id, strategy, filename).run!(&block)
|
31
|
+
end
|
4
32
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'gisture'
|
2
|
+
|
3
|
+
namespace 'gisture' do
|
4
|
+
desc 'Run a github gist in a rake task'
|
5
|
+
task :run, [:gist_id, :strategy, :filename, :runner] => :environment do |t,args|
|
6
|
+
runner = Proc.new { eval(args.runner.to_s) }
|
7
|
+
Gisture.run(args.gist_id, args.strategy, args.filename, &runner)
|
8
|
+
end
|
9
|
+
end
|
data/spec/gists/class.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gisture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rebec
|
@@ -10,6 +10,34 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2015-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: canfig
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: github_api
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: rake
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -46,7 +74,19 @@ extensions: []
|
|
46
74
|
extra_rdoc_files: []
|
47
75
|
files:
|
48
76
|
- lib/gisture.rb
|
77
|
+
- lib/gisture/evaluator.rb
|
78
|
+
- lib/gisture/gist.rb
|
79
|
+
- lib/gisture/railtie.rb
|
49
80
|
- lib/gisture/version.rb
|
81
|
+
- lib/tasks/gisture.rake
|
82
|
+
- spec/gists/called_class.rb
|
83
|
+
- spec/gists/called_method.rb
|
84
|
+
- spec/gists/class.rb
|
85
|
+
- spec/gists/method.rb
|
86
|
+
- spec/gists/simple.rb
|
87
|
+
- spec/gisture/evaluator_spec.rb
|
88
|
+
- spec/gisture/gist_spec.rb
|
89
|
+
- spec/gisture_spec.rb
|
50
90
|
- spec/spec_helper.rb
|
51
91
|
homepage: http://github.com/markrebec/gisture
|
52
92
|
licenses: []
|
@@ -72,4 +112,12 @@ signing_key:
|
|
72
112
|
specification_version: 4
|
73
113
|
summary: Execute one-off gists inline or in the background.
|
74
114
|
test_files:
|
115
|
+
- spec/gists/called_class.rb
|
116
|
+
- spec/gists/called_method.rb
|
117
|
+
- spec/gists/class.rb
|
118
|
+
- spec/gists/method.rb
|
119
|
+
- spec/gists/simple.rb
|
120
|
+
- spec/gisture/evaluator_spec.rb
|
121
|
+
- spec/gisture/gist_spec.rb
|
122
|
+
- spec/gisture_spec.rb
|
75
123
|
- spec/spec_helper.rb
|