maestro_plugin 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  Maestro Ruby Plugin Gem
2
2
  =======================
3
+ [![Gem Version](https://badge.fury.io/rb/maestro_plugin.png)](http://badge.fury.io/rb/maestro_plugin)
4
+ [![Code Climate](https://codeclimate.com/github/maestrodev/maestro-ruby-plugin.png)](https://codeclimate.com/github/maestrodev/maestro-ruby-plugin)
3
5
 
4
6
  Library For Creating Ruby Based Maestro Plugins
5
7
  =======
@@ -318,6 +318,16 @@ module Maestro
318
318
  value = default if !default.nil? && (value.nil? || (value.respond_to?(:empty?) && value.empty?))
319
319
  value
320
320
  end
321
+
322
+ # Helper that renders a field as an int
323
+ def get_int_field(field, default = 0)
324
+ as_int(get_field(field), default)
325
+ end
326
+
327
+ # Helper that renders a field as a boolean
328
+ def get_boolean_field(field)
329
+ as_boolean(get_field(field))
330
+ end
321
331
 
322
332
  def fields
323
333
  workitem['fields']
@@ -336,6 +346,42 @@ module Maestro
336
346
  fields[LINKS_META] << {'name' => name, 'url' => url}
337
347
  end
338
348
 
349
+ # Field Utility methods
350
+
351
+ # Return numeric version of value
352
+ def as_int(value, default = 0)
353
+ res = default
354
+
355
+ if value
356
+ if value.is_a?(Fixnum)
357
+ res = value
358
+ elsif value.respond_to?(:to_i)
359
+ res = value.to_i
360
+ end
361
+ end
362
+
363
+ res
364
+ end
365
+
366
+ # Return boolean version of a value
367
+ def as_boolean(value)
368
+ res = false
369
+
370
+ if value
371
+ if value.is_a?(TrueClass) || value.is_a?(FalseClass)
372
+ res = value
373
+ elsif value.is_a?(Fixnum)
374
+ res = value != 0
375
+ elsif value.respond_to?(:to_s)
376
+ value = value.to_s.downcase
377
+
378
+ res = (value == 't' || value == 'true')
379
+ end
380
+ end
381
+
382
+ res
383
+ end
384
+
339
385
  private
340
386
 
341
387
  def send_workitem_message
@@ -1,5 +1,5 @@
1
1
  module Maestro
2
2
  module Plugin
3
- VERSION = '0.0.16'
3
+ VERSION = '0.0.17'
4
4
  end
5
5
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: maestro_plugin
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.16
5
+ version: 0.0.17
6
6
  platform: ruby
7
7
  authors:
8
8
  - Etienne Pelletier
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2013-08-11 00:00:00 Z
13
+ date: 2013-08-26 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: logging