mattock 0.5.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NWU5MDFhZGU0YWEwMjNlNzdiMzIyN2IzNTk2MDg1Y2NhODY2YWEwNQ==
5
+ data.tar.gz: !binary |-
6
+ NWMzNzQwZTFiZjRmNDcxNDdhNjU3YTNhMjY2MmQ4YTIzYmU5YmNiYQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MThlMzM0YzMyNjA3MjVlZTNjZWFkZTVhMTZmOGM2MTcxZWJjMzBjMjk2NDdm
10
+ MzJiYzdiZjE0MmYxNmYxZTdjZmY4YmIzZGI5NjYyYzBkOWZmYTFjM2Q5ZGY3
11
+ ZTUwN2EwNzkzYjM1ODc2ZjI4ZmYxNGRhZGU0ZDVjNWQ3ZDYxNGQ=
12
+ data.tar.gz: !binary |-
13
+ OWFkNGI4ZmY5YzhlMjFlZDRmNWM0MGQ4NDllNDE2NGE2NWQ1NzM5Mjc3ZWRk
14
+ OGQyZTgyMGU0NzAzNWNlMzkyZTdlODQ3NWE5NDFhMDYwNTNjZWYyNGMwZGRh
15
+ Y2Q0MDhlNDIwYjIzMzA0ZDcyMTEwZWMyN2IwYThlNDdjMGRjZDQ=
@@ -6,28 +6,37 @@ module Mattock
6
6
  env = {}
7
7
  if defined? Bundler
8
8
  %w{
9
- BUNDLER_EDITOR
10
- BUNDLE_APP_CONFIG
11
- BUNDLE_BIN_PATH
12
- BUNDLE_CONFIG
13
- BUNDLE_PATH
14
- BUNDLE_SPEC_RUN
15
- DEBUG
16
- DEBUG_RESOLVER
17
- EDITOR
18
- GEM_HOME
19
- GEM_PATH
20
- MANPAGER
21
- PAGER
22
- PATH
23
- RB_USER_INSTALL
24
- RUBYOPT
25
- VISUAL
9
+ BUNDLER_EDITOR
10
+ BUNDLE_APP_CONFIG
11
+ BUNDLE_CONFIG
12
+ BUNDLE_PATH
13
+ BUNDLE_SPEC_RUN
14
+ DEBUG
15
+ DEBUG_RESOLVER
16
+ EDITOR
17
+ GEM_HOME
18
+ GEM_PATH
19
+ MANPAGER
20
+ PAGER
21
+ PATH
22
+ RB_USER_INSTALL
23
+ RUBYOPT
24
+ VISUAL
25
+ bundle_bin
26
+ bundle_dir
26
27
  }.each do |bundler_varname|
28
+ next if ENV[bundler_varname] == Bundler::ORIGINAL_ENV[bundler_varname]
27
29
  env[bundler_varname] = Bundler::ORIGINAL_ENV[bundler_varname]
28
30
  end
31
+ %w{
32
+ bundle_bin
33
+ bundle_dir
34
+ BUNDLE_BIN_PATH
35
+ BUNDLE_GEMFILE
36
+ }.each do |bundler_varname|
37
+ env[bundler_varname] = nil
38
+ end
29
39
  end
30
- env["BUNDLE_GEMFILE"] = nil
31
40
  env
32
41
  end
33
42
 
@@ -2,27 +2,32 @@ require 'mattock/command-line/command-run-result'
2
2
 
3
3
  module Mattock
4
4
  class CommandLine
5
- def self.define_chain_op(opname, klass)
6
- define_method(opname) do |other|
7
- unless CommandLine === other
8
- other = CommandLine.new(*[*other])
5
+ class << self
6
+ def define_chain_op(opname, klass)
7
+ define_method(opname) do |other|
8
+ unless CommandLine === other
9
+ other = CommandLine.new(*[*other])
10
+ end
11
+ chain = nil
12
+ if klass === self
13
+ chain = self
14
+ else
15
+ chain = klass.new
16
+ chain.add(self)
17
+ end
18
+ chain.add(other)
9
19
  end
10
- chain = nil
11
- if klass === self
12
- chain = self
13
- else
14
- chain = klass.new
15
- chain.add(self)
16
- end
17
- chain.add(other)
18
20
  end
19
- end
20
21
 
21
- def self.define_op(opname)
22
- CommandLine.define_chain_op(opname, self)
22
+ def define_op(opname)
23
+ CommandLine.define_chain_op(opname, self)
24
+ end
25
+
26
+ attr_accessor :output_stream
23
27
  end
24
28
 
25
29
  def initialize(executable, *options)
30
+ @output_stream = self.class.output_stream || $stderr
26
31
  @executable = executable
27
32
  @options = options
28
33
  @redirections = []
@@ -30,7 +35,7 @@ module Mattock
30
35
  yield self if block_given?
31
36
  end
32
37
 
33
- attr_accessor :name, :executable, :options, :env
38
+ attr_accessor :name, :executable, :options, :env, :output_stream
34
39
  attr_reader :redirections
35
40
 
36
41
  alias_method :command_environment, :env
@@ -87,8 +92,8 @@ module Mattock
87
92
  end
88
93
 
89
94
  def replace_us
90
- puts "Ceding execution to: "
91
- puts string_format
95
+ output_steeam.puts "Ceding execution to: "
96
+ output_stream.puts string_format
92
97
  Process.exec(command_environment, command)
93
98
  end
94
99
 
@@ -144,14 +149,18 @@ module Mattock
144
149
  collect_result(pid, out, err)
145
150
  end
146
151
 
152
+ def report(message, newline=true)
153
+ output_stream.print(message + (newline ? "\n" : ""))
154
+ end
155
+
147
156
  def run
148
- print string_format + " "
157
+ report string_format + " ", false
149
158
  result = execute
150
- puts "=> #{result.exit_code}"
151
- puts result.format_streams if verbose
159
+ report "=> #{result.exit_code}"
160
+ report result.format_streams if verbose
152
161
  return result
153
162
  ensure
154
- puts if verbose
163
+ report "" if verbose
155
164
  end
156
165
 
157
166
  def succeeds?
@@ -74,9 +74,9 @@ module Mattock
74
74
  if !@buffered_echo.nil?
75
75
  timeout = begin_echoing - Time.now
76
76
  if timeout < 0
77
- puts
78
- puts "Long running command output:"
79
- puts @buffered_echo.join
77
+ @command.report ""
78
+ @command.report "Long running command output:"
79
+ @command.report @buffered_echo.join
80
80
  @buffered_echo = nil
81
81
  end
82
82
  end
@@ -113,7 +113,7 @@ module Mattock
113
113
  begin
114
114
  while chunk = io.read_nonblock(4096)
115
115
  if @buffered_echo.nil?
116
- print chunk
116
+ @command.report chunk, false
117
117
  else
118
118
  @buffered_echo << chunk
119
119
  end
@@ -146,11 +146,7 @@ module Mattock
146
146
  end
147
147
  default_values.each do |field|
148
148
  next unless field.is? :defaulting
149
- value = field.default_value
150
- if Module === value and Configurable > value
151
- value = value.new
152
- value.class.set_defaults_on(value)
153
- end
149
+ value = field.build_default_value
154
150
  instance.__send__(field.writer_method, value)
155
151
  end
156
152
  end
@@ -1,3 +1,5 @@
1
+ require 'rake'
2
+
1
3
  module Mattock
2
4
  module Configurable
3
5
  class MissingRelativePaths < Exception; end
@@ -16,6 +18,11 @@ module Mattock
16
18
  setting :absolute_path
17
19
  setting :relative_path
18
20
 
21
+ alias abspath absolute_path
22
+ alias relpath relative_path
23
+
24
+ #No #path - ambiguous whether that would be abspath or pathname
25
+
19
26
  def initialize(rel_path)
20
27
  self.relative_path = rel_path unless rel_path == Configurable::RequiredField
21
28
  end
@@ -30,15 +37,21 @@ module Mattock
30
37
  end
31
38
  alias path_name pathname
32
39
 
40
+ if (false)
33
41
  def inspect
34
42
  "<path: #{
35
- if unset?(:absolute_path)
36
- "<<?>>/#{relative_path.inspect}"
43
+ if field_unset?(:absolute_path)
44
+ if field_unset?(:relative_path)
45
+ "<<?>>"
46
+ else
47
+ "?/#{relative_path}"
48
+ end
37
49
  else
38
50
  absolute_path.inspect
39
51
  end
40
52
  }>"
41
53
  end
54
+ end
42
55
  end
43
56
 
44
57
  module ClassMethods
@@ -72,6 +72,38 @@ module Mattock
72
72
  name
73
73
  end
74
74
 
75
+ def copy_from(instance)
76
+ return if unset_on?(instance)
77
+ copy_value(immediate_value_on(instance))
78
+ end
79
+
80
+ def build_default_value
81
+ if Module === @default_value and Configurable > @default_value
82
+ value = @default_value.new
83
+ value.class.set_defaults_on(value)
84
+ value
85
+ else
86
+ copy_value(@default_value)
87
+ end
88
+ end
89
+
90
+ def copy_value(value)
91
+ case value
92
+ when Symbol, Numeric, NilClass, TrueClass, FalseClass
93
+ value
94
+ else
95
+ if value.class == BasicObject
96
+ value
97
+ elsif value.respond_to?(:dup)
98
+ value.dup
99
+ elsif value.respond_to?(:clone)
100
+ value.clone
101
+ else
102
+ value
103
+ end
104
+ end
105
+ end
106
+
75
107
  def immediate_value_on(instance)
76
108
  instance.instance_variable_get(ivar_name)
77
109
  #instance.__send__(reader_method)
@@ -8,24 +8,20 @@ module Mattock
8
8
  attr_accessor :field_names
9
9
  attr_reader :source
10
10
 
11
- def filter_attribute
12
- raise NotImplementedError
13
- end
14
-
15
11
  def filter(field_names)
16
12
  field_names.find_all do |name|
17
13
  source.class.field_metadata(name).is?(filter_attribute)
18
14
  end
19
15
  end
20
16
 
21
- def value(field)
22
- source.__send__(field.reader_method)
17
+ def can_process(field, target)
18
+ target.respond_to?(field.writer_method)
23
19
  end
24
20
 
25
21
  def to(target)
26
22
  field_names.each do |name|
27
23
  field = source.class.field_metadata(name)
28
- next unless target.respond_to?(field.writer_method)
24
+ next unless can_process(field, target)
29
25
  target.__send__(field.writer_method, value(field))
30
26
  end
31
27
  end
@@ -36,8 +32,12 @@ module Mattock
36
32
  :copiable
37
33
  end
38
34
 
35
+ def can_process(field, target)
36
+ super and not( field.unset_on?(source) and field.unset_on?(target) )
37
+ end
38
+
39
39
  def value(field)
40
- field.immediate_value_on(source)
40
+ return field.copy_from(source)
41
41
  end
42
42
  end
43
43
 
@@ -1,5 +1,11 @@
1
+ require 'mattock/configurable/directory-structure'
2
+
1
3
  module Mattock
2
4
  module Configurable
5
+ def initialize_copy(original)
6
+ original.copy_settings_to(self)
7
+ end
8
+
3
9
  def copy_settings
4
10
  SettingsCopier.new(self)
5
11
  end
@@ -52,6 +58,7 @@ module Mattock
52
58
 
53
59
  #XXX deprecate
54
60
  def unset?(value)
61
+ warn "#unset? is deprecated - use field_unset? instead"
55
62
  value.nil?
56
63
  end
57
64
 
@@ -70,6 +77,7 @@ module Mattock
70
77
 
71
78
  class Struct
72
79
  include Configurable
80
+ include Configurable::DirectoryStructure
73
81
  end
74
82
  end
75
83
  end
data/lib/mattock/task.rb CHANGED
@@ -59,11 +59,10 @@ module Mattock
59
59
  Configurable.included(sub)
60
60
  Configurable::DirectoryStructure.included(sub)
61
61
  DeferredDefinition.add_settings(sub)
62
+ sub.setting :task_name
63
+ sub.setting :task_args
62
64
  end
63
65
 
64
- setting :task_name
65
- setting :task_args
66
-
67
66
  attr_accessor :base_task
68
67
 
69
68
  def resolve_configuration
@@ -0,0 +1,51 @@
1
+ require 'mattock/task'
2
+ module Mattock
3
+ class TemplateTask < Mattock::Rake::FileTask
4
+ setting :templates
5
+ setting :source_path
6
+ setting :local_variables, {}
7
+ setting :context
8
+
9
+ path :target
10
+
11
+ setting :search_dirs, []
12
+
13
+ def default_configuration(context)
14
+ super
15
+
16
+ self.context = context
17
+
18
+ if field_unset?(:task_name)
19
+ unless field_unset?(:source_path)
20
+ target.relative_path = source_path
21
+ end
22
+ end
23
+ end
24
+
25
+ def resolve_configuration
26
+ if field_unset?(:source_path)
27
+ self.source_path = File::basename(task_name)
28
+ end
29
+
30
+ if target.field_unset?(:relative_path)
31
+ target.absolute_path = task_name
32
+ end
33
+
34
+ self.templates ||=
35
+ begin
36
+ require 'valise'
37
+ Valise::read_only(*search_dirs).templates
38
+ end
39
+
40
+ resolve_paths
41
+
42
+ super
43
+ end
44
+
45
+ def action(args)
46
+ File::open(target.absolute_path, "w") do |target|
47
+ target.write(templates.find(source_path).contents.render(context, local_variables))
48
+ end
49
+ end
50
+ end
51
+ end
@@ -13,6 +13,14 @@ module Mattock
13
13
 
14
14
  def self.included(mod)
15
15
  mod.class_eval do
16
+ before :each do
17
+ @tempdir = File.join "/tmp", "test_mattock_#{$$}"
18
+
19
+ @original_PWD = Dir.pwd
20
+ FileUtils.mkdir_p @tempdir
21
+ Dir.chdir @tempdir
22
+ end
23
+
16
24
  let! :rake do
17
25
  ::Rake.application = ::Rake::Application.new
18
26
  ::Rake::TaskManager.record_task_metadata = true
@@ -43,14 +51,6 @@ module Mattock
43
51
  end
44
52
  end
45
53
 
46
- before :each do
47
- @tempdir = File.join "/tmp", "test_mattock_#{$$}"
48
-
49
- @original_PWD = Dir.pwd
50
- FileUtils.mkdir_p @tempdir
51
- Dir.chdir @tempdir
52
- end
53
-
54
54
  after :each do
55
55
  Dir.chdir @original_PWD
56
56
  FileUtils.rm_rf @tempdir
data/spec/configurable.rb CHANGED
@@ -82,6 +82,30 @@ describe Mattock::Configurable do
82
82
  path(:loose_path, "here")
83
83
  end
84
84
 
85
+ describe "distinctness" do
86
+ let :one do
87
+ DirectoryThing.new.tap do |thing|
88
+ thing.setup_defaults
89
+ end
90
+ end
91
+
92
+ let :other do
93
+ DirectoryThing.new.tap do |thing|
94
+ thing.setup_defaults
95
+ end
96
+ end
97
+
98
+ it "should have same values" do
99
+ one.bundle_workdir.relative_path.should == other.bundle_workdir.relative_path
100
+ end
101
+
102
+ it "should have different actual objects" do
103
+ one.bundle_workdir.relative_path.should_not equal other.bundle_workdir.relative_path
104
+ one.bundle_workdir.should_not equal other.bundle_workdir
105
+ end
106
+
107
+ end
108
+
85
109
  def subject
86
110
  DirectoryThing.new.tap do |thing|
87
111
  thing.setup_defaults
@@ -183,7 +207,10 @@ describe Mattock::Configurable do
183
207
  class LeftStruct
184
208
  include Mattock::Configurable
185
209
 
186
- setting(:normal, 1)
210
+ setting(:normal, "1")
211
+ setting(:nested, nested{
212
+ setting :value, "2"
213
+ })
187
214
  setting(:no_copy, 2).isnt(:copiable)
188
215
  setting(:no_proxy, 3).isnt(:proxiable)
189
216
  setting(:no_nothing, 4).isnt(:copiable).isnt(:proxiable)
@@ -193,7 +220,7 @@ describe Mattock::Configurable do
193
220
  class RightStruct
194
221
  include Mattock::Configurable
195
222
 
196
- required_fields(:normal, :no_copy, :no_proxy, :no_nothing)
223
+ required_fields(:normal, :nested, :no_copy, :no_proxy, :no_nothing)
197
224
  end
198
225
 
199
226
  let :left do
@@ -204,24 +231,33 @@ describe Mattock::Configurable do
204
231
  RightStruct.new.setup_defaults
205
232
  end
206
233
 
234
+ it "should make copies not references" do
235
+ left.copy_settings_to(right)
236
+ right.normal.should == left.normal
237
+ right.normal.should_not equal(left.normal)
238
+ right.nested.value.should == left.nested.value
239
+ right.nested.should_not equal(left.nested)
240
+ right.nested.value.should_not equal left.nested.value
241
+ end
242
+
207
243
  it "should not copy no_copy" do
208
244
  left.copy_settings_to(right)
209
- right.unset?(right.normal).should be_false
210
- right.normal.should == 1
211
- right.unset?(right.no_copy).should be_true
212
- right.unset?(right.no_proxy).should be_false
245
+ right.field_unset?(:normal).should be_false
246
+ right.normal.should == "1"
247
+ right.field_unset?(:no_copy).should be_true
248
+ right.field_unset?(:no_proxy).should be_false
213
249
  right.no_proxy.should == 3
214
- right.unset?(right.no_nothing).should be_true
250
+ right.field_unset?(:no_nothing).should be_true
215
251
  end
216
252
 
217
253
  it "should not proxy no_proxy" do
218
254
  left.proxy_settings.to(right)
219
- right.unset?(right.normal).should be_false
220
- right.normal.should == 1
221
- right.unset?(right.no_copy).should be_false
255
+ right.field_unset?(:normal).should be_false
256
+ right.normal.should == "1"
257
+ right.field_unset?(:no_copy).should be_false
222
258
  right.no_copy.should == 2
223
- right.unset?(right.no_proxy).should be_true
224
- right.unset?(right.no_nothing).should be_true
259
+ right.field_unset?(:no_proxy).should be_true
260
+ right.field_unset?(:no_nothing).should be_true
225
261
  end
226
262
  end
227
263
  end
@@ -1,4 +1,5 @@
1
1
  require 'rspec'
2
+ require 'rspec/core/formatters/base_formatter'
2
3
  require 'file-sandbox'
3
4
  require 'cadre/rspec'
4
5
 
metadata CHANGED
@@ -1,98 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mattock
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.5.3
4
+ version: 0.7.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Judson Lester
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-10-11 00:00:00.000000000 Z
11
+ date: 2013-11-26 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ~>
17
+ - !ruby/object:Gem::Version
18
+ version: 0.0.1
15
19
  prerelease: false
16
- type: :development
17
20
  name: corundum
18
21
  version_requirements: !ruby/object:Gem::Requirement
19
22
  requirements:
20
23
  - - ~>
21
24
  - !ruby/object:Gem::Version
22
25
  version: 0.0.1
23
- none: false
26
+ type: :development
27
+ - !ruby/object:Gem::Dependency
24
28
  requirement: !ruby/object:Gem::Requirement
25
29
  requirements:
26
30
  - - ~>
27
31
  - !ruby/object:Gem::Version
28
- version: 0.0.1
29
- none: false
30
- - !ruby/object:Gem::Dependency
32
+ version: '10.0'
31
33
  prerelease: false
32
- type: :runtime
33
34
  name: rake
34
35
  version_requirements: !ruby/object:Gem::Requirement
35
36
  requirements:
36
37
  - - ~>
37
38
  - !ruby/object:Gem::Version
38
- segments:
39
- - 10
40
- - 0
41
39
  version: '10.0'
42
- none: false
40
+ type: :runtime
41
+ - !ruby/object:Gem::Dependency
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
- - - ~>
44
+ - - ! '>='
46
45
  - !ruby/object:Gem::Version
47
- segments:
48
- - 10
49
- - 0
50
- version: '10.0'
51
- none: false
52
- - !ruby/object:Gem::Dependency
46
+ version: 0.9.1
53
47
  prerelease: false
54
- type: :runtime
55
48
  name: valise
56
49
  version_requirements: !ruby/object:Gem::Requirement
57
50
  requirements:
58
51
  - - ! '>='
59
52
  - !ruby/object:Gem::Version
60
- segments:
61
- - 0
62
- - 9
63
- - 1
64
53
  version: 0.9.1
65
- none: false
54
+ type: :runtime
55
+ - !ruby/object:Gem::Dependency
66
56
  requirement: !ruby/object:Gem::Requirement
67
57
  requirements:
68
- - - ! '>='
58
+ - - ! '>'
69
59
  - !ruby/object:Gem::Version
70
- segments:
71
- - 0
72
- - 9
73
- - 1
74
- version: 0.9.1
75
- none: false
76
- - !ruby/object:Gem::Dependency
60
+ version: '0'
77
61
  prerelease: false
78
- type: :runtime
79
62
  name: tilt
80
63
  version_requirements: !ruby/object:Gem::Requirement
81
64
  requirements:
82
65
  - - ! '>'
83
66
  - !ruby/object:Gem::Version
84
- segments:
85
- - 0
86
- version: '0'
87
- none: false
88
- requirement: !ruby/object:Gem::Requirement
89
- requirements:
90
- - - ! '>'
91
- - !ruby/object:Gem::Version
92
- segments:
93
- - 0
94
67
  version: '0'
95
- none: false
68
+ type: :runtime
96
69
  description: ! " If Rake won't do it by itself, you oughtta Mattock.\n\n If you
97
70
  survived the pun, you might enjoy this gem.\n\n Features:\n\n * Extensions to
98
71
  Tasklibs to support powerful deerpaths.\n * A commandline library that supports
@@ -123,6 +96,7 @@ files:
123
96
  - lib/mattock/bundle-command-task.rb
124
97
  - lib/mattock/tasklib.rb
125
98
  - lib/mattock/task.rb
99
+ - lib/mattock/template-task.rb
126
100
  - lib/mattock/configurable.rb
127
101
  - lib/mattock/configurable/field-processor.rb
128
102
  - lib/mattock/configurable/proxy-value.rb
@@ -147,33 +121,29 @@ files:
147
121
  homepage: http://nyarly.github.com/mattock/
148
122
  licenses:
149
123
  - MIT
124
+ metadata: {}
150
125
  post_install_message:
151
126
  rdoc_options:
152
127
  - --inline-source
153
128
  - --main
154
129
  - doc/README
155
130
  - --title
156
- - mattock-0.5.3 RDoc
131
+ - mattock-0.7.0 RDoc
157
132
  require_paths:
158
133
  - lib/
159
134
  required_ruby_version: !ruby/object:Gem::Requirement
160
135
  requirements:
161
136
  - - ! '>='
162
137
  - !ruby/object:Gem::Version
163
- segments:
164
- - 0
165
- hash: 509890867
166
138
  version: '0'
167
- none: false
168
139
  required_rubygems_version: !ruby/object:Gem::Requirement
169
140
  requirements:
170
141
  - - ! '>='
171
142
  - !ruby/object:Gem::Version
172
143
  version: '0'
173
- none: false
174
144
  requirements: []
175
145
  rubyforge_project: mattock
176
- rubygems_version: 1.8.24
146
+ rubygems_version: 2.1.10
177
147
  signing_key:
178
148
  specification_version: 3
179
149
  summary: A powerful companion to Rake