amp-core 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -8,4 +8,5 @@ group :development do
8
8
  gem 'rspec', '< 2.0.0'
9
9
  gem 'yard'
10
10
  gem 'cucumber'
11
+ gem 'haml' # for templates
11
12
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -1,53 +1,35 @@
1
+ puts "Loading amp-core..."
2
+
3
+ require 'amp-core/command_ext/repository_loading'
4
+ require 'amp-core/repository/repository.rb'
5
+ require 'amp-core/repository/generic_repo_picker.rb'
6
+
7
+ Dir[File.join(File.dirname(__FILE__), 'amp-core', 'commands', '**', '*.rb')].each do |file|
8
+ require file
9
+ end
10
+
1
11
  module Amp
2
- module Core
3
- end
4
12
  module Support
13
+ autoload :Template, 'amp-core/templates/template.rb'
5
14
  end
6
- end
7
-
8
- class Amp::Plugins::Core < Amp::Plugins::Base
9
- # this is necessary to prevent loading when #load! isn't called.
10
- @loader = lambda {
11
- $:.unshift(File.expand_path(File.dirname(__FILE__)))
12
- module ::Amp
13
- module Core
14
- module Repositories
15
- autoload :GenericRepoPicker, 'amp-core/repository/generic_repo_picker.rb'
16
- autoload :AbstractLocalRepository, 'amp-core/repository/abstract/abstract_local_repo.rb'
17
- autoload :AbstractStagingArea, 'amp-core/repository/abstract/abstract_staging_area.rb'
18
- autoload :AbstractChangeset, 'amp-core/repository/abstract/abstract_changeset.rb'
19
- autoload :AbstractVersionedFile, 'amp-core/repository/abstract/abstract_versioned_file.rb'
20
- autoload :CommonChangesetMethods, 'amp-core/repository/abstract/common_methods/changeset.rb'
21
- autoload :CommonLocalRepoMethods, 'amp-core/repository/abstract/common_methods/local_repo.rb'
22
- autoload :CommonStagingAreaMethods, 'amp-core/repository/abstract/common_methods/staging_area.rb'
23
- autoload :CommonChangesetMethods, 'amp-core/repository/abstract/common_methods/changeset.rb'
24
- autoload :CommonVersionedFileMethods,'amp-core/repository/abstract/common_methods/versioned_file.rb'
25
- end
26
- module Support
27
- autoload :EncodingUtils, 'amp-core/support/encoding_utils.rb'
28
- autoload :Platform, 'amp-core/support/platform_utils.rb'
29
- autoload :RootedOpener, 'amp-core/support/rooted_opener.rb'
30
- autoload :StringUtils, 'amp-core/support/string_utils.rb'
31
- end
32
- end
15
+ module Core
16
+ module Repositories
17
+ autoload :GenericRepoPicker, 'amp-core/repository/generic_repo_picker.rb'
18
+ autoload :AbstractLocalRepository, 'amp-core/repository/abstract/abstract_local_repo.rb'
19
+ autoload :AbstractStagingArea, 'amp-core/repository/abstract/abstract_staging_area.rb'
20
+ autoload :AbstractChangeset, 'amp-core/repository/abstract/abstract_changeset.rb'
21
+ autoload :AbstractVersionedFile, 'amp-core/repository/abstract/abstract_versioned_file.rb'
22
+ autoload :CommonChangesetMethods, 'amp-core/repository/abstract/common_methods/changeset.rb'
23
+ autoload :CommonLocalRepoMethods, 'amp-core/repository/abstract/common_methods/local_repo.rb'
24
+ autoload :CommonStagingAreaMethods, 'amp-core/repository/abstract/common_methods/staging_area.rb'
25
+ autoload :CommonChangesetMethods, 'amp-core/repository/abstract/common_methods/changeset.rb'
26
+ autoload :CommonVersionedFileMethods,'amp-core/repository/abstract/common_methods/versioned_file.rb'
33
27
  end
34
- }
35
- class << self
36
- attr_reader :loader
37
- end
38
-
39
- def initialize(opts={})
40
- @opts = opts
41
- end
42
-
43
- def load!
44
- puts "Loading amp-core..."
45
- require 'amp-core/command_ext/repository_loading'
46
- require 'amp-core/repository/repository.rb'
47
- require 'amp-core/repository/generic_repo_picker.rb'
48
- ::Amp::Support.class_eval do
49
- autoload :Template, "amp-core/templates/template.rb"
28
+ module Support
29
+ autoload :EncodingUtils, 'amp-core/support/encoding_utils.rb'
30
+ autoload :Platform, 'amp-core/support/platform_utils.rb'
31
+ autoload :RootedOpener, 'amp-core/support/rooted_opener.rb'
32
+ autoload :HexString, 'amp-core/support/hex_string.rb'
50
33
  end
51
- self.class.loader.call
52
34
  end
53
35
  end
@@ -0,0 +1,16 @@
1
+ module Amp
2
+ module Core
3
+ end
4
+ module Support
5
+ end
6
+ end
7
+
8
+ class Amp::Plugins::Core < Amp::Plugins::Base
9
+ def initialize(opts={})
10
+ @opts = opts
11
+ end
12
+
13
+ def load!
14
+ require 'amp-core'
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ Amp::Command.create('info') do |c|
2
+ c.has_repo
3
+ c.validates_argument_count(:minimum => 1)
4
+ c.on_call do
5
+ arguments.each do |arg|
6
+ p repository[arg]
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ Amp::Command.create('root') do |c|
2
+ c.has_repo
3
+ c.on_call do
4
+ p repository.root
5
+ end
6
+ end
@@ -19,26 +19,76 @@ module Amp
19
19
  # This module is a set of string functions that we use frequently.
20
20
  # They sued to be monkey-patched onto the String class, but we don't
21
21
  # do that anymore.
22
- module StringUtils
23
- module_function
24
-
22
+ class HexString
23
+ # Construct a HexString
24
+ def self.from_bin(bin)
25
+ HexString === bin ? bin : new(bin, nil)
26
+ end
27
+
28
+ # Construct a HexString
29
+ def self.from_hex(hex)
30
+ HexString === hex ? hex : new(nil, hex)
31
+ end
32
+
33
+ # Mainly internal/test helper method; change the encoding in 1.9
34
+ def self.as_binary(s)
35
+ if s.respond_to?(:force_encoding)
36
+ s.force_encoding('binary')
37
+ else
38
+ s
39
+ end
40
+ end
41
+
42
+ def self.sha1(str)
43
+ HexString.from_bin(Digest::SHA1.new.update(str).digest)
44
+ end
45
+
46
+ # Assumes one or the other argument will be nil.
47
+ # Mostly an internal constructor
48
+ def initialize(binary_part, hex_part)
49
+ @binary = self.class.as_binary(binary_part)
50
+ @hex = hex_part
51
+ end
52
+
53
+ def <=>(other)
54
+ to_s <=> other.to_s
55
+ end
56
+ include Comparable
57
+
58
+ # Return raw binary data
59
+ def to_bin
60
+ @binary ||= unhexlify
61
+ end
62
+
63
+ # Return hexidecimal representation of binary data
64
+ def to_hex
65
+ @hex ||= hexlify
66
+ end
67
+
68
+ # Return hexidecimal representation of binary data
69
+ alias_method :to_s, :to_hex
70
+
25
71
  # Converts this text into hex. each letter is replaced with
26
72
  # it's hex counterpart
27
- def hexlify(src)
28
- str = ""
29
- src.each_byte do |i|
30
- str << i.to_s(16).rjust(2, "0")
73
+ def hexlify
74
+ hex = ""
75
+ @binary.each_byte do |i|
76
+ hex << i.to_s(16).rjust(2, "0")
31
77
  end
32
- str
78
+ hex
79
+ end
80
+
81
+ def empty?
82
+ to_bin.size == 0
33
83
  end
34
84
 
35
85
  if RUBY_VERSION < "1.9"
36
86
  # Returns the value of the first byte of the string.
37
87
  #
38
88
  # @return [Fixnum, 0 <= x < 256] The value of the first byte.
39
- def ord(str)
40
- raise ArgumentError.new('empty string') if str.empty?
41
- str[0]
89
+ def ord
90
+ raise ArgumentError.new('empty string') if to_bin.empty?
91
+ to_bin[0]
42
92
  end
43
93
  ##
44
94
  # Converts a string of hex into the binary values it represents. This is used for
@@ -46,40 +96,35 @@ module Amp
46
96
  #
47
97
  # @example StringUtils.unhexlify("DEADBEEF") #=> "\336\255\276\357"
48
98
  # @return [String] the string decoded from hex form
49
- def unhexlify(src)
50
- str = "\000" * (src.size/2)
99
+ def unhexlify
100
+ bin = "\000" * (@hex.size/2)
51
101
  c = 0
52
- (0..src.size-2).step(2) do |i|
53
- hex = src[i,2].to_i(16)
54
- str[c] = hex
102
+ (0..@hex.size-2).step(2) do |i|
103
+ byte = @hex[i,2].to_i(16)
104
+ bin[c] = byte
55
105
  c += 1
56
106
  end
57
- str
107
+ bin
58
108
  end
59
109
  else
60
110
  # Returns the value of the first byte of the string.
61
111
  #
62
112
  # @return [Fixnum, 0 <= x < 256] The value of the first byte.
63
- def ord(str)
64
- raise ArgumentError.new('empty string') if str.empty?
65
- str.ord
113
+ def ord
114
+ to_bin.ord
66
115
  end
67
116
 
68
- def unhexlify(str)
69
- str = "\000" * (src.size/2)
117
+ def unhexlify
118
+ bin = "\000" * (@hex.size/2)
70
119
  c = 0
71
- (0..src.size-2).step(2) do |i|
72
- hex = src[i,2].to_i(16)
73
- str[c] = hex.chr
120
+ (0..@hex.size-2).step(2) do |i|
121
+ byte = @hex[i,2].to_i(16)
122
+ bin[c] = byte.chr
74
123
  c += 1
75
124
  end
76
- str
125
+ bin
77
126
  end
78
127
  end
79
-
80
- def sha1(str)
81
- Digest::SHA1.new.update(str)
82
- end
83
128
  end
84
129
  end
85
130
  end
@@ -0,0 +1,23 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require '../amp-front/lib/amp-front'
5
+ require 'amp-core/amp_plugin'
6
+
7
+ describe "plugin" do
8
+ it "should have a plugin constant: Amp::Plugins::Core" do
9
+ result = nil
10
+ Amp::Plugins.class_eval do
11
+ result = const_defined?(:Core)
12
+ end
13
+ result.should be_true
14
+ end
15
+
16
+ it 'should load the plugin' do
17
+ plugin = Amp::Plugins::Core.new
18
+ # this is entirely too white-box, but other tests already loaded everything
19
+ # mucking with the environment would be kind of messy
20
+ plugin.should_receive(:require)
21
+ plugin.load!
22
+ end
23
+ end
@@ -34,7 +34,6 @@ describe Amp::Core::Repositories do
34
34
  end
35
35
 
36
36
  it 'Picks the first loaded Repository type to match.' do
37
- p Amp::Core::Repositories::GenericRepoPicker.all_pickers
38
37
  Amp::Core::Repositories.pick(nil, nil, false).should == @expected
39
38
  end
40
39
  end
@@ -7,8 +7,6 @@ require 'amp-core'
7
7
  require 'spec'
8
8
  require 'spec/autorun'
9
9
 
10
- Amp::Plugins::Core.new.load!
11
-
12
10
  Spec::Runner.configure do |config|
13
11
 
14
12
  end
@@ -0,0 +1,112 @@
1
+ # encoding: UTF-8
2
+ # chosen as something that forces the subject to deal with encodings
3
+ ##################################################################
4
+ # Licensing Information #
5
+ # #
6
+ # The following code is licensed, as standalone code, under #
7
+ # the Ruby License, unless otherwise directed within the code. #
8
+ # #
9
+ # For information on the license of this code when distributed #
10
+ # with and used in conjunction with the other modules in the #
11
+ # Amp project, please see the root-level LICENSE file. #
12
+ # #
13
+ # © Michael J. Edgar and Ari Brown, 2009-2010 #
14
+ # #
15
+ ##################################################################
16
+
17
+ require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
18
+
19
+ describe Amp::Core::Support::HexString do
20
+ Subject = Amp::Core::Support::HexString
21
+ describe 'created from binary data' do
22
+ it 'can be created without error' do
23
+ Subject.from_bin('A').should be_kind_of(Subject)
24
+ end
25
+
26
+ it 'is compareable' do
27
+ Subject.from_bin('A').should == Subject.from_bin('A')
28
+ end
29
+
30
+ it 'is compareable and right' do
31
+ Subject.from_bin('A').should_not == Subject.from_bin('B')
32
+ end
33
+
34
+ describe '#ord' do
35
+ it 'raises an ArgumentError on an empty string' do
36
+ lambda { Subject.from_bin('').ord }.should raise_error(ArgumentError)
37
+ end
38
+
39
+ it 'returns the first byte of a simple character' do
40
+ Subject.from_bin('A').ord.should == 65
41
+ end
42
+
43
+ it 'returns the first byte of a complex character' do
44
+ Subject.from_bin('™').ord.should == 226
45
+ end
46
+ end
47
+
48
+ describe '#to_bin' do
49
+ it 'maintains itself' do
50
+ Subject.from_bin('abcd').to_bin.should == "abcd"
51
+ end
52
+ end
53
+
54
+ describe '#to_hex' do
55
+ it 'converts text data to its hex form' do
56
+ Subject.from_bin('ABCD').to_hex.should == '41424344'
57
+ end
58
+ end
59
+
60
+ describe '#to_s' do
61
+ it 'same result as to_hex' do
62
+ s = Subject.from_bin('ABCD')
63
+ s.to_s.should == s.to_hex
64
+ end
65
+ end
66
+ end
67
+
68
+ describe 'created from hex string' do
69
+ it 'can be created without error' do
70
+ Subject.from_hex('ab').should be_kind_of(Subject)
71
+ end
72
+
73
+ describe '#ord' do
74
+ it 'raises an ArgumentError on an empty string' do
75
+ lambda { Subject.new('').ord }.should raise_error(ArgumentError)
76
+ end
77
+
78
+ it 'returns the first byte of a simple character' do
79
+ Subject.from_hex('41').ord.should == 65
80
+ end
81
+
82
+ it 'returns the first byte of a complex character' do
83
+ Subject.from_hex('e2').ord.should == 226
84
+ end
85
+ end
86
+
87
+ describe '#to_bin' do
88
+ it 'converts a few hex bytes to binary' do
89
+ Subject.from_hex('abcd').to_bin.should == Subject.as_binary("\xab\xcd")
90
+ end
91
+ end
92
+
93
+ describe '#to_hex' do
94
+ it 'maintains itself' do
95
+ Subject.from_hex('ABCD').to_hex.should == 'ABCD'
96
+ end
97
+ end
98
+
99
+ describe '#to_s' do
100
+ it 'same result as to_hex' do
101
+ s = Subject.from_hex('ABCD')
102
+ s.to_s.should == s.to_hex
103
+ end
104
+ end
105
+ end
106
+
107
+ describe '::sha1' do
108
+ it 'creates a HexString' do
109
+ Subject.sha1('A').should be_kind_of(Subject)
110
+ end
111
+ end
112
+ end
@@ -18,7 +18,6 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
18
18
  require 'rubygems'
19
19
  require 'amp-front'
20
20
  require 'amp-core'
21
- Amp::Plugins::Core.new.load!
22
21
 
23
22
  class TestTemplates < Test::Unit::TestCase
24
23
  include Amp::Support
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Edgar
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-03 00:00:00 -04:00
17
+ date: 2010-11-11 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -79,7 +79,10 @@ files:
79
79
  - features/step_definitions/amp-core_steps.rb
80
80
  - features/support/env.rb
81
81
  - lib/amp-core.rb
82
+ - lib/amp-core/amp_plugin.rb
82
83
  - lib/amp-core/command_ext/repository_loading.rb
84
+ - lib/amp-core/commands/info.rb
85
+ - lib/amp-core/commands/root.rb
83
86
  - lib/amp-core/repository/abstract/abstract_changeset.rb
84
87
  - lib/amp-core/repository/abstract/abstract_local_repo.rb
85
88
  - lib/amp-core/repository/abstract/abstract_staging_area.rb
@@ -91,9 +94,9 @@ files:
91
94
  - lib/amp-core/repository/generic_repo_picker.rb
92
95
  - lib/amp-core/repository/repository.rb
93
96
  - lib/amp-core/support/encoding_utils.rb
97
+ - lib/amp-core/support/hex_string.rb
94
98
  - lib/amp-core/support/platform_utils.rb
95
99
  - lib/amp-core/support/rooted_opener.rb
96
- - lib/amp-core/support/string_utils.rb
97
100
  - lib/amp-core/templates/git/blank.log.erb
98
101
  - lib/amp-core/templates/git/default.log.erb
99
102
  - lib/amp-core/templates/mercurial/blank.commit.erb
@@ -101,17 +104,17 @@ files:
101
104
  - lib/amp-core/templates/mercurial/default.commit.erb
102
105
  - lib/amp-core/templates/mercurial/default.log.erb
103
106
  - lib/amp-core/templates/template.rb
104
- - spec/amp-core_spec.rb
105
107
  - spec/command_ext_specs/repository_loading_spec.rb
106
108
  - spec/command_ext_specs/spec_helper.rb
109
+ - spec/plugin_spec.rb
107
110
  - spec/repository_specs/repository_spec.rb
108
111
  - spec/repository_specs/spec_helper.rb
109
112
  - spec/spec.opts
110
113
  - spec/spec_helper.rb
111
114
  - spec/support_specs/encoding_utils_spec.rb
115
+ - spec/support_specs/hex_string_spec.rb
112
116
  - spec/support_specs/platform_utils_spec.rb
113
117
  - spec/support_specs/spec_helper.rb
114
- - spec/support_specs/string_utils_spec.rb
115
118
  - test/test_templates.rb
116
119
  has_rdoc: true
117
120
  homepage: http://github.com/michaeledgar/amp-core
@@ -144,14 +147,14 @@ signing_key:
144
147
  specification_version: 3
145
148
  summary: The core plugin for Amp. Necessary for Amp to function.
146
149
  test_files:
147
- - spec/amp-core_spec.rb
148
150
  - spec/command_ext_specs/repository_loading_spec.rb
149
151
  - spec/command_ext_specs/spec_helper.rb
152
+ - spec/plugin_spec.rb
150
153
  - spec/repository_specs/repository_spec.rb
151
154
  - spec/repository_specs/spec_helper.rb
152
155
  - spec/spec_helper.rb
153
156
  - spec/support_specs/encoding_utils_spec.rb
157
+ - spec/support_specs/hex_string_spec.rb
154
158
  - spec/support_specs/platform_utils_spec.rb
155
159
  - spec/support_specs/spec_helper.rb
156
- - spec/support_specs/string_utils_spec.rb
157
160
  - test/test_templates.rb
@@ -1,11 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "amp-core" do
4
- it "should have a plugin constant: Amp::Plugins::Core" do
5
- result = nil
6
- Amp::Plugins.class_eval do
7
- result = const_defined?(:Core)
8
- end
9
- result.should be_true
10
- end
11
- end
@@ -1,44 +0,0 @@
1
- ##################################################################
2
- # Licensing Information #
3
- # #
4
- # The following code is licensed, as standalone code, under #
5
- # the Ruby License, unless otherwise directed within the code. #
6
- # #
7
- # For information on the license of this code when distributed #
8
- # with and used in conjunction with the other modules in the #
9
- # Amp project, please see the root-level LICENSE file. #
10
- # #
11
- # © Michael J. Edgar and Ari Brown, 2009-2010 #
12
- # #
13
- ##################################################################
14
-
15
- require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
16
-
17
- describe Amp::Core::Support::StringUtils do
18
- describe '#ord' do
19
- it 'raises an ArgumentError on an empty string' do
20
- lambda { Amp::Core::Support::StringUtils.ord('') }.should raise_error(ArgumentError)
21
- end
22
-
23
- it 'returns the first byte of the string' do
24
- Amp::Core::Support::StringUtils.ord('A').should == 65
25
- Amp::Core::Support::StringUtils.ord('™').should == 226
26
- end
27
- end
28
-
29
- describe '#unhexlify' do
30
- it 'converts a few hex bytes to binary' do
31
- Amp::Core::Support::StringUtils.unhexlify('abcd').should == "\xab\xcd"
32
- end
33
- end
34
-
35
- describe '#hexlify' do
36
- it 'converts text data to its hex form' do
37
- Amp::Core::Support::StringUtils.hexlify('ABCD').should == '41424344'
38
- end
39
-
40
- it 'converts binary data to its hex form' do
41
- Amp::Core::Support::StringUtils.hexlify('ABCD').should == '41424344'
42
- end
43
- end
44
- end