instrument 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.1.2
2
+
3
+ * controls may now accept a delegate object, which methods will be relayed to
4
+ * controls and control builders now have a proper respond_to? method
5
+ * controls now have a formats method that lists all available formats
6
+
1
7
  == 0.1.1
2
8
 
3
9
  * controls may now optionally accept a block during initialization
@@ -168,6 +168,53 @@ module Instrument
168
168
  downcase
169
169
  end
170
170
 
171
+ ##
172
+ # Returns a list of formats that this control may be rendered as.
173
+ #
174
+ # @return [Array] the available formats
175
+ def self.formats
176
+ return [] if self.control_name == nil
177
+ all_templates = []
178
+ all_formats = []
179
+ for load_path in $CONTROL_PATH
180
+ full_name = File.expand_path(
181
+ File.join(load_path, self.control_name))
182
+
183
+ # Check to make sure the requested template is within the load path
184
+ # to avoid inadvertent rendering of say, /etc/passwd
185
+ next if full_name.index(File.expand_path(load_path)) != 0
186
+
187
+ all_templates.concat(Dir.glob(full_name + ".*"))
188
+ end
189
+ for template in all_templates
190
+ next if File.directory?(template)
191
+ all_formats << template[/^.*\.([-_a-zA-Z0-9]+)\..*$/, 1]
192
+ end
193
+ return all_formats.uniq.reject { |f| f.nil? }
194
+ end
195
+
196
+ ##
197
+ # Returns true if the control responds to the given message.
198
+ #
199
+ # @return [Boolean] if the control responds
200
+ def respond_to?(method, include_private=false)
201
+ if method.to_s =~ /^to_/
202
+ format = method.to_s.gsub(/^to_/, "")
203
+ return self.class.formats.include?(format)
204
+ else
205
+ control_class = self.class.lookup(method.to_s)
206
+ if control_class != nil
207
+ return true
208
+ else
209
+ if options[:delegate] != nil &&
210
+ options[:delegate].respond_to?(method)
211
+ return true
212
+ end
213
+ end
214
+ end
215
+ super
216
+ end
217
+
171
218
  ##
172
219
  # Relays to_format messages to the render method.
173
220
  #
@@ -180,15 +227,20 @@ module Instrument
180
227
  def method_missing(method, *params, &block)
181
228
  if method.to_s =~ /^to_/
182
229
  format = method.to_s.gsub(/^to_/, "")
183
- self.send(:render, format, *params, &block)
230
+ self.render(format, *params, &block)
184
231
  else
185
232
  control_class = self.class.lookup(method.to_s)
186
233
  if control_class != nil
187
234
  control_class.new(*params, &block)
188
235
  else
189
- raise NoMethodError,
190
- "undefined method `#{method}' for " +
191
- "#{self.inspect}:#{self.class.name}"
236
+ if options[:delegate] != nil &&
237
+ options[:delegate].respond_to?(method)
238
+ options[:delegate].send(method, *params, &block)
239
+ else
240
+ raise NoMethodError,
241
+ "undefined method `#{method}' for " +
242
+ "#{self.inspect}:#{self.class.name}"
243
+ end
192
244
  end
193
245
  end
194
246
  end
@@ -49,6 +49,16 @@ module Instrument
49
49
  return self.method_missing(:select, *params, &block)
50
50
  end
51
51
 
52
+ ##
53
+ # Returns true if the control builder responds to the given message.
54
+ #
55
+ # @return [Boolean] if the control builder responds
56
+ def respond_to?(method, include_private=false)
57
+ control_class = ::Instrument::Control.lookup(method.to_s)
58
+ return true if control_class != nil
59
+ super
60
+ end
61
+
52
62
  ##
53
63
  # Initializes Instrument::Control subclasses by name.
54
64
  #
@@ -27,7 +27,7 @@ unless defined? Instrument::VERSION
27
27
  module VERSION #:nodoc:
28
28
  MAJOR = 0
29
29
  MINOR = 1
30
- TINY = 1
30
+ TINY = 2
31
31
 
32
32
  STRING = [MAJOR, MINOR, TINY].join('.')
33
33
  end
@@ -15,7 +15,7 @@ end
15
15
  class Select < Instrument::Control
16
16
  end
17
17
 
18
- describe Instrument::ControlBuilder do
18
+ describe Instrument::ControlBuilder, "extending another object" do
19
19
  class ExtendedObject
20
20
  include Instrument::ControlBuilder
21
21
  end
@@ -34,4 +34,20 @@ describe Instrument::ControlBuilder do
34
34
  @extended_object.bogus
35
35
  end).should raise_error(NoMethodError)
36
36
  end
37
+
38
+ it "should respond to a normal message" do
39
+ @extended_object.should respond_to(:to_s)
40
+ end
41
+
42
+ it "should not respond to a bogus message" do
43
+ @extended_object.should_not respond_to(:bogus)
44
+ end
45
+
46
+ it "should respond to a valid control name message" do
47
+ @extended_object.should respond_to(:image_control)
48
+ end
49
+
50
+ it "should not respond to an invalid control name message" do
51
+ @extended_object.should_not respond_to(:bogus_control)
52
+ end
37
53
  end
@@ -100,6 +100,55 @@ describe Instrument::Control do
100
100
  SelectControl.new.to_xml
101
101
  end).should raise_error(ZeroDivisionError)
102
102
  end
103
+
104
+ it "should correctly delegate messages to the delegate object" do
105
+ SelectControl.new(:delegate => [1,2,3]).size.should == 3
106
+ end
107
+
108
+ it "should have the correct list of formats" do
109
+ SelectControl.formats.sort.should == [
110
+ "atom", "html", "json", "txt", "xhtml", "xml"
111
+ ]
112
+ end
113
+
114
+ it "should have no formats listed for the base class" do
115
+ Instrument::Control.formats.should == []
116
+ end
117
+
118
+ it "should respond to a normal message" do
119
+ SelectControl.new.should respond_to(:render)
120
+ end
121
+
122
+ it "should not respond to a bogus message" do
123
+ SelectControl.new.should_not respond_to(:bogus)
124
+ end
125
+
126
+ it "should respond to valid subclass messages" do
127
+ Instrument::Control.new.should respond_to(:select_control)
128
+ SelectControl.new.should respond_to(:select_control)
129
+ end
130
+
131
+ it "should not respond to invalid subclass messages" do
132
+ SelectControl.new.should_not respond_to(:bogus_control)
133
+ end
134
+
135
+ it "should respond to a valid format conversion message" do
136
+ SelectControl.new.should respond_to(:to_atom)
137
+ end
138
+
139
+ it "should not respond to an invalid format conversion message" do
140
+ SelectControl.new.should_not respond_to(:to_bogus)
141
+ end
142
+
143
+ it "should respond to messages available on a delegated object" do
144
+ SelectControl.new(:delegate => []).should respond_to(:<<)
145
+ SelectControl.new(:delegate => 42).should respond_to(:>>)
146
+ SelectControl.new(:delegate => 42).should respond_to(:<<)
147
+ end
148
+
149
+ it "should not respond to messages unavailable on a delegated object" do
150
+ SelectControl.new(:delegate => []).should_not respond_to(:>>)
151
+ end
103
152
  end
104
153
 
105
154
  describe Instrument::Control, "when rendered as XHTML with Haml" do
@@ -20,7 +20,7 @@ namespace :gem do
20
20
 
21
21
  s.author = "Bob Aman"
22
22
  s.email = "bob@sporkmonger.com"
23
- s.homepage = "http://sporkmonger.com/"
23
+ s.homepage = "http://#{PKG_NAME}.rubyforge.org/"
24
24
  s.rubyforge_project = RUBY_FORGE_PROJECT
25
25
  end
26
26
 
@@ -10,12 +10,25 @@ namespace :git do
10
10
 
11
11
  desc "Create a new tag in the Git repository"
12
12
  task :create do
13
+ changelog = File.open("CHANGELOG", "r") { |file| file.read }
14
+ puts "-" * 80
15
+ puts changelog
16
+ puts "-" * 80
17
+ puts
18
+
13
19
  v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
14
20
  abort "Versions don't match #{v} vs #{PKG_VERSION}" if v != PKG_VERSION
15
21
 
16
22
  tag = "#{PKG_NAME}-#{PKG_VERSION}"
17
23
  msg = "Release #{PKG_NAME}-#{PKG_VERSION}"
18
24
 
25
+ existing_tags = `git tag -l instrument-*`.split("\n")
26
+ if existing_tags.include?(tag)
27
+ warn("Tag already exists, deleting...")
28
+ unless system "git tag -d #{tag}"
29
+ abort "Tag deletion failed."
30
+ end
31
+ end
19
32
  puts "Creating git tag '#{tag}'..."
20
33
  unless system "git tag -a -m \"#{msg}\" #{tag}"
21
34
  abort "Tag creation failed."
@@ -9,6 +9,7 @@ namespace :gem do
9
9
  pkg = "pkg/#{GEM_SPEC.full_name}"
10
10
 
11
11
  rf = RubyForge.new
12
+ rf.configure
12
13
  puts 'Logging in...'
13
14
  rf.login
14
15
 
@@ -31,9 +31,11 @@ namespace :spec do
31
31
  t.fail_on_error = false
32
32
  end
33
33
 
34
- desc "Browse the code coverage report."
35
- task :rcov_browse => :rcov do
36
- Rake.browse("coverage/index.html")
34
+ namespace :rcov do
35
+ desc "Browse the code coverage report."
36
+ task :browse => "spec:rcov" do
37
+ Rake.browse("coverage/index.html")
38
+ end
37
39
  end
38
40
  end
39
41
 
@@ -41,3 +43,47 @@ desc "Alias to spec:verify"
41
43
  task "spec" => "spec:verify"
42
44
 
43
45
  task "clobber" => ["spec:clobber_rcov"]
46
+
47
+ module Rake
48
+ def self.browse(filepath)
49
+ if RUBY_PLATFORM =~ /mswin/
50
+ system(filepath)
51
+ else
52
+ try_browsers = lambda do
53
+ result = true
54
+ if !(`which firefox 2>&1` =~ /no firefox/)
55
+ system("firefox #{filepath}")
56
+ elsif !(`which mozilla 2>&1` =~ /no mozilla/)
57
+ system("mozilla #{filepath}")
58
+ elsif !(`which netscape 2>&1` =~ /no netscape/)
59
+ system("netscape #{filepath}")
60
+ elsif !(`which links 2>&1` =~ /no links/)
61
+ system("links #{filepath}")
62
+ elsif !(`which lynx 2>&1` =~ /no lynx/)
63
+ system("lynx #{filepath}")
64
+ else
65
+ result = false
66
+ end
67
+ result
68
+ end
69
+ opened = false
70
+ if RUBY_PLATFORM =~ /darwin/
71
+ opened = true
72
+ system("open #{filepath}")
73
+ elsif !(`which gnome-open 2>&1` =~ /no gnome-open/)
74
+ success =
75
+ !(`gnome-open #{filepath} 2>&1` =~ /There is no default action/)
76
+ if !success
77
+ opened = try_browsers.call()
78
+ else
79
+ opened = true
80
+ end
81
+ else
82
+ opened = try_browsers.call()
83
+ end
84
+ if !opened
85
+ puts "Don't know how to browse to location."
86
+ end
87
+ end
88
+ end
89
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instrument
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Aman
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-27 00:00:00 -04:00
12
+ date: 2008-06-05 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -60,7 +60,6 @@ files:
60
60
  - spec/instrument/control_spec.rb
61
61
  - spec/spec.opts
62
62
  - spec/spec_helper.rb
63
- - tasks/browse.rake
64
63
  - tasks/clobber.rake
65
64
  - tasks/gem.rake
66
65
  - tasks/git.rake
@@ -74,7 +73,7 @@ files:
74
73
  - Rakefile
75
74
  - README
76
75
  has_rdoc: true
77
- homepage: http://sporkmonger.com/
76
+ homepage: http://instrument.rubyforge.org/
78
77
  post_install_message:
79
78
  rdoc_options:
80
79
  - --main
@@ -1,43 +0,0 @@
1
- module Rake
2
- def self.browse(filepath)
3
- if RUBY_PLATFORM =~ /mswin/
4
- system(filepath)
5
- else
6
- try_browsers = lambda do
7
- result = true
8
- if !(`which firefox 2>&1` =~ /no firefox/)
9
- system("firefox #{filepath}")
10
- elsif !(`which mozilla 2>&1` =~ /no mozilla/)
11
- system("mozilla #{filepath}")
12
- elsif !(`which netscape 2>&1` =~ /no netscape/)
13
- system("netscape #{filepath}")
14
- elsif !(`which links 2>&1` =~ /no links/)
15
- system("links #{filepath}")
16
- elsif !(`which lynx 2>&1` =~ /no lynx/)
17
- system("lynx #{filepath}")
18
- else
19
- result = false
20
- end
21
- result
22
- end
23
- opened = false
24
- if RUBY_PLATFORM =~ /darwin/
25
- opened = true
26
- system("open #{filepath}")
27
- elsif !(`which gnome-open 2>&1` =~ /no gnome-open/)
28
- success =
29
- !(`gnome-open #{filepath} 2>&1` =~ /There is no default action/)
30
- if !success
31
- opened = try_browsers.call()
32
- else
33
- opened = true
34
- end
35
- else
36
- opened = try_browsers.call()
37
- end
38
- if !opened
39
- puts "Don't know how to browse to location."
40
- end
41
- end
42
- end
43
- end