gisture 0.0.11 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 562752af4ac2795824b1624d31fa1d4140198eab
4
- data.tar.gz: c70c205d2041bef77bd7f030cb8831a449917751
3
+ metadata.gz: ab45da4ed2c2d6056ff570a3acb5fb65040c4a9e
4
+ data.tar.gz: 4b59c005cb105f398c21cc0587c46b129cca8080
5
5
  SHA512:
6
- metadata.gz: 6e625ab43f9d65f19e0261b29998634c1aa9d5d0d55bd447c4eaabe2d239dbbfd869c7c1143bb16a0ef3e67cef3abafdb3ccbe205142f29efc6216e805f78066
7
- data.tar.gz: 74d045d2265805b027b5c15908e82d4fb798d22856f471168a75786919d60a537ee58e3cfd8a0589af784c9a4796e39589b39c2fcdfeb4d3388e97167b43a0af
6
+ metadata.gz: 949934e74b6d675074d0a07677650671d1dd29d2b937b37694030c56a200fe3d3db727cec96f829f205f735376c21a59a1fec95fe093fe756e64d1407c574b2f
7
+ data.tar.gz: ef22d5df5fb865b17051ff3f4ebb0738bc2a2f00a7de4247072a061499b00bcd9b2183b924ee7298157e9502328e5c394b5a1a18cb3ed4ca1484eaadab6eef3e
@@ -44,7 +44,7 @@ module Gisture
44
44
  path = ::File.join(clone_path, file_path)
45
45
  @clone_path = clone_path
46
46
  @tempfile = ::File.new(path)
47
- file_hash = Hashie::Mash.new({path: path, filename: ::File.basename(path), content: tempfile.read})
47
+ file_hash = Hashie::Mash.new({path: path, filename: file_path, content: tempfile.read})
48
48
  super(file_hash, basename: basename, strategy: strategy)
49
49
  end
50
50
  end
@@ -0,0 +1,84 @@
1
+ require 'kommand/commands'
2
+
3
+ module Gisture
4
+ module Commands
5
+ module Repo
6
+ module File
7
+ class Run
8
+ include Kommand::Commands::Command
9
+
10
+ command_name 'repo:file:run'
11
+ command_summary "Run a repo file directly from the command line"
12
+ valid_argument Kommand::Scripts::Argument.new("-f, --filename", summary: "Specify a filename if it's not included in the repo URL")
13
+ valid_argument Kommand::Scripts::Argument.new("-s, --strategy", summary: "Execution strategy, defaults to 'eval'")
14
+ valid_argument Kommand::Scripts::Argument.new("-e, --evaluator", summary: "Use a custom evaluator class, only applies to 'eval' strategy")
15
+ valid_argument Kommand::Scripts::Argument.new("-c, --clone", summary: "Clone the repo into a local tmp path and run from that working dir")
16
+ validate_arguments false
17
+
18
+ class << self
19
+ def usage
20
+ puts "usage: #{Kommand.kommand} #{command_name} GIST_ID_OR_URL #{valid_arguments.to_s}"
21
+ unless valid_arguments.empty?
22
+ puts
23
+ puts "Arguments:"
24
+ puts valid_arguments.to_help
25
+ end
26
+ end
27
+ end
28
+
29
+ def run
30
+ clone? ? repo.clone! : repo.destroy_clone!
31
+
32
+ result = file.run!
33
+
34
+ if strategy == :exec
35
+ puts result
36
+ else
37
+ result
38
+ end
39
+ end
40
+
41
+ protected
42
+
43
+ def file
44
+ @file ||= repo.file((repo_url[1] || filename), strategy: strategy)
45
+ end
46
+
47
+ def repo
48
+ @repo ||= Gisture.repo(repo_url[0])
49
+ end
50
+
51
+ def repo_url
52
+ Gisture::Repo.parse_file_url(arguments.unnamed.first.value)
53
+ rescue
54
+ [Gisture::Repo.parse_repo_url(arguments.unnamed.first.value).join('/')]
55
+ end
56
+
57
+ def strategy
58
+ @strategy ||= begin
59
+ strat = arguments.get(:strategy) || 'eval'
60
+ if strat == 'eval'
61
+ {eval: evaluator}
62
+ else
63
+ strat.to_sym
64
+ end
65
+ end
66
+ end
67
+
68
+ def evaluator
69
+ @evaluator ||= eval(arguments.get(:evaluator) || 'Gisture::Evaluator')
70
+ end
71
+
72
+ def filename
73
+ @filename ||= arguments.get(:filename)
74
+ end
75
+
76
+ def clone?
77
+ arguments.arg?(:clone)
78
+ end
79
+
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -7,16 +7,12 @@ module Gisture
7
7
  include Kommand::Commands::Command
8
8
 
9
9
  command_name 'repo:run'
10
- command_summary "Run a repo file directly from the command line"
11
- valid_argument Kommand::Scripts::Argument.new("-f, --filename", summary: "Specify a filename if it's not included in the repo URL")
12
- valid_argument Kommand::Scripts::Argument.new("-s, --strategy", summary: "Execution strategy, defaults to 'eval'")
13
- valid_argument Kommand::Scripts::Argument.new("-e, --evaluator", summary: "Use a custom evaluator class, only applies to 'eval' strategy")
14
- valid_argument Kommand::Scripts::Argument.new("-c, --clone", summary: "Clone the repo into a local tmp path and run from that working dir")
10
+ command_summary "Run a yaml gisture directly from the command line"
15
11
  validate_arguments false
16
12
 
17
13
  class << self
18
14
  def usage
19
- puts "usage: #{Kommand.kommand} #{command_name} GIST_ID_OR_URL #{valid_arguments.to_s}"
15
+ puts "usage: #{Kommand.kommand} #{command_name} YAML_GISTURE_URL #{valid_arguments.to_s}"
20
16
  unless valid_arguments.empty?
21
17
  puts
22
18
  puts "Arguments:"
@@ -26,22 +22,11 @@ module Gisture
26
22
  end
27
23
 
28
24
  def run
29
- clone? ? repo.clone! : repo.destroy_clone!
30
-
31
- result = file.run!
32
-
33
- if strategy == :exec
34
- puts result
35
- else
36
- result
37
- end
25
+ repo.run!(repo_url[1])
38
26
  end
39
27
 
40
28
  protected
41
29
 
42
- def file
43
- @file ||= repo.file((repo_url[1] || filename), strategy: strategy)
44
- end
45
30
 
46
31
  def repo
47
32
  @repo ||= Gisture.repo(repo_url[0])
@@ -53,29 +38,6 @@ module Gisture
53
38
  [Gisture::Repo.parse_repo_url(arguments.unnamed.first.value).join('/')]
54
39
  end
55
40
 
56
- def strategy
57
- @strategy ||= begin
58
- strat = arguments.get(:strategy) || 'eval'
59
- if strat == 'eval'
60
- {eval: evaluator}
61
- else
62
- strat.to_sym
63
- end
64
- end
65
- end
66
-
67
- def evaluator
68
- @evaluator ||= eval(arguments.get(:evaluator) || 'Gisture::Evaluator')
69
- end
70
-
71
- def filename
72
- @filename ||= arguments.get(:filename)
73
- end
74
-
75
- def clone?
76
- arguments.arg?(:clone)
77
- end
78
-
79
41
  end
80
42
  end
81
43
  end
data/lib/gisture/file.rb CHANGED
@@ -21,21 +21,21 @@ module Gisture
21
21
  end
22
22
 
23
23
  def require!(*args, &block)
24
- Gisture.logger.info "[gisture] Running #{basename}/#{file.path || file.filename} via the :require strategy"
24
+ Gisture.logger.info "[gisture] Running #{::File.join(basename, (file.filename || file.path))} via the :require strategy"
25
25
  required = require tempfile.path
26
26
  unlink_tempfile
27
27
  block_given? ? yield : required
28
28
  end
29
29
 
30
30
  def load!(*args, &block)
31
- Gisture.logger.info "[gisture] Running #{basename}/#{file.path || file.filename} via the :load strategy"
31
+ Gisture.logger.info "[gisture] Running #{::File.join(basename, (file.filename || file.path))} via the :load strategy"
32
32
  loaded = load tempfile.path
33
33
  unlink_tempfile
34
34
  block_given? ? yield : loaded
35
35
  end
36
36
 
37
37
  def eval!(*args, &block)
38
- Gisture.logger.info "[gisture] Running #{basename}/#{file.path || file.filename} via the :eval strategy"
38
+ Gisture.logger.info "[gisture] Running #{::File.join(basename, (file.filename || file.path))} via the :eval strategy"
39
39
  args << Gisture::Evaluator
40
40
  klass = args.first
41
41
  evaluator = klass.new(file.content)
@@ -44,7 +44,7 @@ module Gisture
44
44
  end
45
45
 
46
46
  def exec!(*args, &block)
47
- Gisture.logger.info "[gisture] Running #{basename}/#{file.path || file.filename} via the :exec strategy"
47
+ Gisture.logger.info "[gisture] Running #{::File.join(basename, (file.filename || file.path))} via the :exec strategy"
48
48
 
49
49
  # map nils to file path in args to allow easily inserting the filepath wherever
50
50
  # makes sense in your executable arguments (i.e. 'ruby', '-v', nil, '--script-arg')
@@ -81,6 +81,17 @@ module Gisture
81
81
  end
82
82
  end
83
83
 
84
+ def localize!(root)
85
+ @tempfile = begin
86
+ fname = ::File.join(root, (file.path || file.filename))
87
+ FileUtils.mkdir_p ::File.dirname(fname)
88
+ local_file = ::File.open(fname, 'w')
89
+ local_file.write(file.content)
90
+ local_file.close
91
+ local_file
92
+ end
93
+ end
94
+
84
95
  def extname
85
96
  @extname ||= ::File.extname(file.filename)
86
97
  end
data/lib/gisture/repo.rb CHANGED
@@ -3,6 +3,7 @@ module Gisture
3
3
  attr_reader :owner, :project
4
4
  REPO_URL_REGEX = /\A((http[s]?:\/\/)?github\.com\/)?([a-z0-9_\-\.]*)\/([a-z0-9_\-\.]*)\/?\Z/i
5
5
  FILE_URL_REGEX = /\A((http[s]?:\/\/)?github\.com\/)?(([a-z0-9_\-\.]*)\/([a-z0-9_\-\.]*))(\/[a-z0-9_\-\.\/]+)\Z/i
6
+ GISTURE_FILE_REGEX = /\A(gisture\.ya?ml|.+\.gist|.+\.gisture)\Z/ # gisture.yml, gisture.yaml, whatever.gist, whatever.gisture
6
7
 
7
8
  class << self
8
9
  def file(path, strategy: nil)
@@ -44,9 +45,67 @@ module Gisture
44
45
  end
45
46
  end
46
47
 
47
- def run!(path, strategy: nil, &block)
48
- file(path, strategy: strategy).run!(&block)
48
+ def files(path)
49
+ if cloned?
50
+ Dir[::File.join(clone_path, path, '*')].map { |f| Hashie::Mash.new({name: ::File.basename(f), path: ::File.join(path, ::File.basename(f))}) }
51
+ else
52
+ github.repos.contents.get(user: owner, repo: project, path: path).body
53
+ end
54
+ end
55
+
56
+ # TODO move all the gisture/gisticulate stuff into a separate class (Gisture? Gisticulation?)
57
+
58
+ def gistures(path)
59
+ if ::File.basename(path).match(GISTURE_FILE_REGEX)
60
+ [Hashie::Mash.new(YAML.load(file(path).content).symbolize_keys)]
61
+ else
62
+ files(path).select { |f| f.name.match(GISTURE_FILE_REGEX) }.map { |f| Hashie::Mash.new(YAML.load(file(f.path).content).symbolize_keys) }
63
+ end
64
+ end
65
+
66
+ def gisticulate(gisture, &block)
67
+ if gisture.key?(:gistures) || gisture.key?(:gists)
68
+ gists = (gisture[:gistures] || gisture[:gists])
69
+ gists = gists.values if gists.respond_to?(:values)
70
+ clone! if gists.any? { |g| g[:clone] == true } # force clone once up front for a refresh
71
+ gists.map { |gist| gisticulate(gist, &block) }
72
+ else
73
+ clone if gisture[:clone] == true
74
+
75
+ run_options = []
76
+ run_options << eval(gisture[:evaluator]) if (!gisture.key?(:strategy) || gisture[:strategy].to_sym == :eval) && gisture.key?(:evaluator)
77
+ run_options = gisture[:executor] if (gisture.key?(:strategy) && gisture[:strategy].to_sym == :exec) && gisture.key?(:executor)
78
+
79
+ if gisture[:resources] && !cloned?
80
+ # localize and pull down any relevant resources
81
+ gisture[:resources].each do |resource|
82
+ Gisture.logger.info "[gisture] Localizing resource #{::File.join(owner, project, resource)} into #{clone_path}"
83
+ file(resource).localize!(clone_path)
84
+ end
85
+
86
+ # localize the file we're running
87
+ Gisture.logger.info "[gisture] Localizing gisture #{::File.join(owner, project, gisture[:path])} into #{clone_path}"
88
+ gfile = file(gisture[:path], strategy: gisture[:strategy])
89
+ gfile.localize!(clone_path)
90
+
91
+ # chdir into the localized temp path
92
+ cwd = Dir.pwd
93
+ Dir.chdir ::File.dirname(gfile.tempfile.path)
94
+ result = gfile.run!(*run_options, &block)
95
+ Dir.chdir cwd
96
+ result
97
+ else
98
+ file(gisture[:path], strategy: gisture[:strategy]).run!(*run_options, &block)
99
+ end
100
+ end
101
+ end
102
+
103
+ def run(path, &block)
104
+ gists = gistures(path)
105
+ clone! if gists.any? { |g| g[:clone] == true } # force clone once up front for a refresh
106
+ gists.map { |g| gisticulate(g, &block) }
49
107
  end
108
+ alias_method :run!, :run
50
109
 
51
110
  def clone_path
52
111
  @clone_path ||= ::File.join(Gisture.configuration.tmpdir, owner, project)
@@ -1,3 +1,3 @@
1
1
  module Gisture
2
- VERSION = '0.0.11'
2
+ VERSION = '0.0.12'
3
3
  end
@@ -8,10 +8,17 @@ namespace :gisture do
8
8
  end
9
9
 
10
10
  namespace :repo do
11
- desc 'Run a file from a github repo in a rake task'
12
- task :run, [:repo, :filename, :strategy, :runner] => :environment do |t,args|
13
- runner = Proc.new { eval(args.runner.to_s) }
14
- Gisture.repo(args.repo).file(args.filename, strategy: args.strategy).run!(&runner)
11
+ desc 'Run a yaml gisture from a github repo in a rake task'
12
+ task :run, [:repo, :yaml_file] => :environment do |t,args|
13
+ Gisture.repo(args.repo).run!(args.yaml_file)
14
+ end
15
+
16
+ namespace :file do
17
+ desc 'Run a file from a github repo in a rake task'
18
+ task :run, [:repo, :filename, :strategy, :runner] => :environment do |t,args|
19
+ runner = Proc.new { eval(args.runner.to_s) }
20
+ Gisture.repo(args.repo).file(args.filename, strategy: args.strategy).run!(&runner)
21
+ end
15
22
  end
16
23
  end
17
24
  end
@@ -0,0 +1,7 @@
1
+ gists:
2
+ - path: spec/gists/simple.rb
3
+ strategy: eval
4
+ - path: spec/gists/method.rb
5
+ strategy: load
6
+ - path: spec/gists/class.rb
7
+ strategy: require
@@ -0,0 +1,4 @@
1
+ path: /spec/gists/class.rb
2
+ strategy: require
3
+ evaluator: "Gisture::Evaluator"
4
+ clone: true
@@ -0,0 +1,5 @@
1
+ path: /spec/gists/simple.rb
2
+ strategy: eval
3
+ evaluator: "Gisture::Evaluator"
4
+ executor: ['ruby', '-v']
5
+ clone: true
@@ -0,0 +1,3 @@
1
+ path: /spec/gists/method.rb
2
+ strategy: eval
3
+ clone: false
@@ -0,0 +1,10 @@
1
+ gistures:
2
+ simple:
3
+ path: spec/gists/simple.rb
4
+ strategy: eval
5
+ method:
6
+ path: spec/gists/method.rb
7
+ strategy: load
8
+ class:
9
+ path: spec/gists/class.rb
10
+ strategy: require
@@ -0,0 +1,4 @@
1
+ path: spec/gists/resourceful.rb
2
+ resources:
3
+ - spec/gists/resourceful.txt
4
+ - lib/gisture/version.rb
@@ -0,0 +1,2 @@
1
+ puts ::File.read('./resourceful.txt')
2
+ puts ::File.read('../../lib/gisture/version.rb')
@@ -0,0 +1 @@
1
+ This is the content of resourceful.txt
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gisture
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Rebec
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-06 00:00:00.000000000 Z
11
+ date: 2015-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: canfig
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hashie
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'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: git
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +122,7 @@ files:
108
122
  - lib/gisture/cloned_file.rb
109
123
  - lib/gisture/commands.rb
110
124
  - lib/gisture/commands/gist/run.rb
125
+ - lib/gisture/commands/repo/file/run.rb
111
126
  - lib/gisture/commands/repo/run.rb
112
127
  - lib/gisture/errors.rb
113
128
  - lib/gisture/evaluator.rb
@@ -119,10 +134,18 @@ files:
119
134
  - lib/gisture/repo_file.rb
120
135
  - lib/gisture/version.rb
121
136
  - lib/tasks/gisture.rake
137
+ - spec/gists/array.gist
122
138
  - spec/gists/called_class.rb
123
139
  - spec/gists/called_method.rb
140
+ - spec/gists/class.gist
124
141
  - spec/gists/class.rb
142
+ - spec/gists/gisture.yml
143
+ - spec/gists/method.gisture
125
144
  - spec/gists/method.rb
145
+ - spec/gists/multi.gist
146
+ - spec/gists/resourceful.gist
147
+ - spec/gists/resourceful.rb
148
+ - spec/gists/resourceful.txt
126
149
  - spec/gists/simple.rb
127
150
  - spec/gisture/evaluator_spec.rb
128
151
  - spec/gisture/file_spec.rb
@@ -156,10 +179,18 @@ signing_key:
156
179
  specification_version: 4
157
180
  summary: Execute one-off gists inline or in the background.
158
181
  test_files:
182
+ - spec/gists/array.gist
159
183
  - spec/gists/called_class.rb
160
184
  - spec/gists/called_method.rb
185
+ - spec/gists/class.gist
161
186
  - spec/gists/class.rb
187
+ - spec/gists/gisture.yml
188
+ - spec/gists/method.gisture
162
189
  - spec/gists/method.rb
190
+ - spec/gists/multi.gist
191
+ - spec/gists/resourceful.gist
192
+ - spec/gists/resourceful.rb
193
+ - spec/gists/resourceful.txt
163
194
  - spec/gists/simple.rb
164
195
  - spec/gisture/evaluator_spec.rb
165
196
  - spec/gisture/file_spec.rb