ed 0.1.0

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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
@@ -0,0 +1,13 @@
1
+
2
+ rvm:
3
+ - 1.8.7 # (current default)
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - rbx-2.0
7
+ - ruby-head
8
+ - ree
9
+
10
+ notifications:
11
+ irc: "irc.freenode.org#flowof.info"
12
+ recipients:
13
+ - rob@flowof.info
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
@@ -0,0 +1,91 @@
1
+ __OVERVIEW__
2
+
3
+
4
+ | Project | Ed
5
+ |:----------------|:--------------------------------------------------
6
+ | Homepage | https://github.com/robgleeson/ed
7
+ | Wiki | https://github.com/robgleeson/ed/wiki
8
+ | Documentation | http://rubydoc.info/gems/ed/frames
9
+ | Author | Rob Gleeson
10
+
11
+
12
+ __DESCRIPTION__
13
+
14
+ A Domain Specific Language(DSL) that you can use to talk to Git from Ruby.
15
+ It isn't intended to be a full interface to Git, but a very small subset of
16
+ one that allows you to profile code from tag A against tag B (for example).
17
+
18
+
19
+ __WHY?__
20
+
21
+ So I could:
22
+
23
+ * Profile different tags, commits, and branches against one another inside Ruby.
24
+ * Explore code in different tags, commits, and branches using a REPL
25
+ like [Pry](https://github.com/pry/pry).
26
+
27
+ __PLATFORM SUPPORT__
28
+
29
+ _supported_
30
+
31
+ * Rubinius
32
+ * CRuby (1.8 / 1.9)
33
+
34
+ _unsupported_
35
+
36
+ * JRuby
37
+ * MacRuby
38
+
39
+ __EXAMPLES__
40
+
41
+ __1.__
42
+
43
+ Travel time and explore, with the aid of [Pry](https://github.com/pry/pry).
44
+ (The calling scope is lost in this example, through use of instance\_eval):
45
+
46
+ Repository "git://github.com/robgleeson/barney.git" do
47
+ before do |path|
48
+ $: << File.join(path, "lib/")
49
+ require "barney"
50
+ end
51
+
52
+ tag "0.1.0" do
53
+ binding.pry
54
+ end
55
+
56
+ tag "0.2.0" do
57
+ binding.pry
58
+ end
59
+ end
60
+
61
+ __2.__
62
+
63
+ Travel time and explore, with the aid of [Pry](https://github.com/pry/pry).
64
+ (The calling scope is kept in this example by accepting a block parameter):
65
+
66
+ Ed.new do |repo|
67
+ repo.before do |path|
68
+ $: << File.join(path, "lib/")
69
+ require "barney"
70
+ end
71
+
72
+ repo.tag "0.1.0" do
73
+ binding.pry
74
+ end
75
+
76
+ repo.tag "0.2.0" do
77
+ binding.pry
78
+ end
79
+ end
80
+
81
+ __INSTALL__
82
+
83
+ gem install ed
84
+
85
+ __LICENSE__
86
+
87
+
88
+ See LICENSE.txt
89
+
90
+
91
+
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.name = :test
6
+ t.test_files = FileList["test/*.rb"]
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ed/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ed"
7
+ s.version = Ed::VERSION
8
+ s.authors = ["Rob Gleeson"]
9
+ s.email = ["rob@flowof.info"]
10
+ s.homepage = "https://github.com/robgleeson/ed"
11
+ s.summary = %q{A Domain Specific Language(DSL) that you can use to talk to Git from Ruby.}
12
+ s.description = s.summary
13
+
14
+ s.rubyforge_project = "Ed"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+
22
+ #s.add_runtime_dependency "scm" , "~> 0.1.0.pre1"
23
+
24
+ s.add_runtime_dependency "observe" , "~> 0.2.0"
25
+ s.add_development_dependency "rake" , "~> 0.9.2"
26
+ s.add_development_dependency "minitest", "~> 2.6"
27
+ end
@@ -0,0 +1,27 @@
1
+ require "ed"
2
+ require "pry"
3
+ require "benchmark"
4
+
5
+ Repository "git://github.com/robgleeson/barney.git" do
6
+ before do |path|
7
+ $: << File.join(path, "lib/")
8
+ require "barney"
9
+ end
10
+
11
+ tag "0.1.0" do
12
+ Benchmark.bm do |r|
13
+ r.report("0.1.0") {
14
+ Barney::Share.new
15
+ }
16
+ end
17
+ end
18
+
19
+ tag "0.2.0" do
20
+ Benchmark.bm do |r|
21
+ r.report("0.2.0") {
22
+ Barney::Share.new
23
+ }
24
+ end
25
+ end
26
+ end
27
+
@@ -0,0 +1,17 @@
1
+ require "ed"
2
+ require "pry"
3
+
4
+ Repository "git://github.com/robgleeson/barney.git" do
5
+ before do |path|
6
+ $: << File.join(path, "lib/")
7
+ require "barney"
8
+ end
9
+
10
+ tag "0.1.0" do
11
+ binding.pry
12
+ end
13
+
14
+ tag "0.2.0" do
15
+ binding.pry
16
+ end
17
+ end
@@ -0,0 +1,65 @@
1
+ require 'observe'
2
+ require 'ed/version'
3
+ require 'ed/repository'
4
+ require 'ed/context'
5
+ require 'ed/core_ext/object'
6
+
7
+ class Ed
8
+
9
+ include Observe
10
+
11
+ #
12
+ # @param [String] path
13
+ # The path to a git repository.
14
+ #
15
+ # @yieldparam [Ed] _self
16
+ # Yields self, if a block is given.
17
+ #
18
+ # @return [Ed::Repository]
19
+ #
20
+ def initialize path
21
+ @repo = Ed::Repository.new(path)
22
+
23
+ if block_given?
24
+ yield(self)
25
+ end
26
+ end
27
+
28
+ #
29
+ # @param [Proc] block
30
+ # A block executed before {#commit}, {#branch}, or {#tag} is called.
31
+ #
32
+ # @return [void]
33
+ #
34
+ def before &block
35
+ add_observer(:before_filter, &block)
36
+ end
37
+
38
+ #
39
+ # @param [String] commit
40
+ # Any string that is passable to 'git checkout'.
41
+ #
42
+ # @param [Proc] block
43
+ # A block executed while the repository has switched to 'commit'.
44
+ #
45
+ def commit commit, &block
46
+ switch(commit, &block)
47
+ end
48
+ alias_method :tag , :commit
49
+ alias_method :branch, :commit
50
+
51
+
52
+ def switch(commit, &block)
53
+ pid = fork do
54
+ @repo.checkout '-q', commit
55
+ notify_observers(:before_filter, @repo.path)
56
+ block.call
57
+ end
58
+
59
+ Process.wait(pid)
60
+ end
61
+ private :switch
62
+
63
+ end
64
+
65
+
@@ -0,0 +1,35 @@
1
+ class Ed::Context
2
+
3
+ def initialize path, &block
4
+ @__ed__ = Ed.new(path)
5
+ instance_eval(&block)
6
+ end
7
+
8
+ #
9
+ # @param block
10
+ # (see Ed#before)
11
+ #
12
+ # @return
13
+ # (see Ed#before)
14
+ #
15
+ def before &block
16
+ @__ed__.before(&block)
17
+ end
18
+
19
+ #
20
+ # @param commit
21
+ # (see Ed#commit)
22
+ #
23
+ # @param block
24
+ # (see Ed#commit)
25
+ #
26
+ # @return
27
+ # (see Ed#commit)
28
+ #
29
+ def commit commit, &block
30
+ @__ed__.commit(commit, &block)
31
+ end
32
+ alias_method :tag , :commit
33
+ alias_method :branch, :commit
34
+
35
+ end
@@ -0,0 +1,22 @@
1
+ #
2
+ # @param [String] path
3
+ # The path to the repository.
4
+ #
5
+ # @param [Proc] block
6
+ # A block executed within an instance of {Ed::Repository}.
7
+ #
8
+ # @yieldparam [Ed] repo
9
+ # Yields instance of {Ed}.
10
+ # If not given, 'block' is run through instance_eval on {Ed::Context} instead.
11
+ #
12
+ # @return [void]
13
+ #
14
+ def Repository path, &block
15
+ if block.arity == 1
16
+ block.call Ed.new(path)
17
+ else
18
+ Ed::Context.new(path, &block)
19
+ end
20
+ end
21
+
22
+
@@ -0,0 +1,76 @@
1
+ require 'fileutils'
2
+
3
+ class Ed::Repository
4
+
5
+ #
6
+ # @return [String]
7
+ # The path to the repository on a local disk.
8
+ #
9
+ attr_reader :path
10
+
11
+ #
12
+ # @return [Boolean]
13
+ # Has the repository been copied?
14
+ #
15
+ attr_reader :copy
16
+ alias_method :copy?, :copy
17
+
18
+ #
19
+ # @param [String, #to_s] path
20
+ # The URI to a git repository.
21
+ #
22
+ # @param [Boolean] copy
23
+ # If true, a copy of the repository is created.
24
+ #
25
+ def initialize path, copy = true
26
+ if copy
27
+ @path = copy!(path.to_s)
28
+ @copy = true
29
+ else
30
+ @path = path.to_s
31
+ @copy = false
32
+ end
33
+ end
34
+
35
+ #
36
+ # @param [String] *options
37
+ # The same commands given to 'git checkout'
38
+ #
39
+ # @return [void]
40
+ #
41
+ def checkout *options
42
+ git "checkout", *options
43
+ end
44
+
45
+ #
46
+ # @param [String] from
47
+ # The path to copy from.
48
+ #
49
+ # @param [String] to
50
+ # The path to copy to.
51
+ #
52
+ # @return [String]
53
+ # The path to the copied repository.
54
+ #
55
+ def copy! from, to = "/tmp/#{Process.pid}-#{Thread.current.object_id}.ed"
56
+ unless File.exists? to
57
+ FileUtils.mkdir_p(to)
58
+ system 'git', 'clone', '-q', from, to
59
+ end
60
+
61
+ to
62
+ end
63
+ private :copy!
64
+
65
+ #
66
+ # Provides low-level access to the git binary in the context of {#path}.
67
+ # @return [void]
68
+ #
69
+ def git *args
70
+ Dir.chdir(@path) do
71
+ system "git", *args
72
+ end
73
+ end
74
+ private :git
75
+
76
+ end
@@ -0,0 +1,3 @@
1
+ class Ed
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'bundler/setup'
2
+ require 'minitest/spec'
3
+ require 'minitest/autorun'
4
+ require 'tempfile'
5
+ require 'ed'
6
+
7
+ alias :context :describe
@@ -0,0 +1,32 @@
1
+ context Ed do
2
+
3
+ context 'When given a git:// URI.' do
4
+ before do
5
+ @ed = Ed.new "git://github.com/robgleeson/barney.git"
6
+ @repo = @ed.instance_variable_get(:@repo)
7
+ end
8
+
9
+ it 'must clone and store the repository locally.' do
10
+ File.exists?(@repo.path).must_equal(true)
11
+ end
12
+
13
+ it 'must checkout the "0.1.0" tag.' do
14
+ Tempfile.open "assertion" do |tmpfile|
15
+ @ed.before do |path|
16
+ $: << File.join(path, "lib")
17
+ require 'thread'
18
+ require 'barney'
19
+ end
20
+
21
+ @ed.tag "0.1.0" do
22
+ tmpfile.write Barney::VERSION
23
+ end
24
+
25
+ tmpfile.rewind
26
+ version = tmpfile.read
27
+ version.must_equal("0.1.0")
28
+ end
29
+ end
30
+ end
31
+
32
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rob Gleeson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: observe
16
+ requirement: &70110727518460 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.2.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70110727518460
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70110727517060 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.2
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70110727517060
36
+ - !ruby/object:Gem::Dependency
37
+ name: minitest
38
+ requirement: &70110727515260 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '2.6'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70110727515260
47
+ description: A Domain Specific Language(DSL) that you can use to talk to Git from
48
+ Ruby.
49
+ email:
50
+ - rob@flowof.info
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - .travis.yml
57
+ - Gemfile
58
+ - README.md
59
+ - Rakefile
60
+ - ed.gemspec
61
+ - examples/benchmark.rb
62
+ - examples/pry.rb
63
+ - lib/ed.rb
64
+ - lib/ed/context.rb
65
+ - lib/ed/core_ext/object.rb
66
+ - lib/ed/repository.rb
67
+ - lib/ed/version.rb
68
+ - test/setup.rb
69
+ - test/test_ed.rb
70
+ homepage: https://github.com/robgleeson/ed
71
+ licenses: []
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project: Ed
90
+ rubygems_version: 1.8.11
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: A Domain Specific Language(DSL) that you can use to talk to Git from Ruby.
94
+ test_files:
95
+ - test/setup.rb
96
+ - test/test_ed.rb
97
+ has_rdoc: