Module: Arbor::Utils
Constant Summary collapse
- INFLECTIONS =
{ 'person' => 'persons' }
Instance Method Summary collapse
- #attempt(enum) ⇒ Object
- #get_resource_name(type) ⇒ Object
- #left_pad(array, num) ⇒ Object
- #parse_resource_name(type) ⇒ Object
- #validate(choice, options) ⇒ Object
Instance Method Details
#attempt(enum) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/arbor/utils.rb', line 32 def attempt(enum) exception = nil enum.each do begin return yield rescue => e exception = e next end end raise exception end |
#get_resource_name(type) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/arbor/utils.rb', line 11 def get_resource_name(type) case type when Class # do reverse serialiser lookup instead pluralize(type.name).underscore else pluralize(type.to_s) end end |
#left_pad(array, num) ⇒ Object
28 29 30 |
# File 'lib/arbor/utils.rb', line 28 def left_pad(array, num) num.times { array.unshift(nil) } end |
#parse_resource_name(type) ⇒ Object
7 8 9 |
# File 'lib/arbor/utils.rb', line 7 def parse_resource_name(type) validate(get_resource_name(type), Arbor::RESOURCES) end |
#validate(choice, options) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/arbor/utils.rb', line 21 def validate(choice, ) unless .include?(choice.to_sym) raise ArgumentError, "#{choice} is not a valid option: #{}" end choice end |