Module: Datagrid::Utils
- Defined in:
- lib/datagrid/utils.rb
Constant Summary collapse
- TRUTH =
[true, 1, "1", "true", "yes", "on"]
Class Method Summary collapse
- .add_html_classes(options, *classes) ⇒ Object
- .booleanize(value) ⇒ Object
- .extract_position_from_options(array, options) ⇒ Object
- .string_like?(value) ⇒ Boolean
- .warn_once(message) ⇒ Object
Class Method Details
.add_html_classes(options, *classes) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/datagrid/utils.rb', line 22 def add_html_classes(, *classes) = .clone [:class] ||= "" if [:class].is_a?(Array) [:class] += classes else # suppose that it is a String [:class] += " " unless [:class].blank? [:class] += classes.join(" ") end end |
.booleanize(value) ⇒ Object
8 9 10 |
# File 'lib/datagrid/utils.rb', line 8 def booleanize(value) TRUTH.include?(value) end |
.extract_position_from_options(array, options) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/datagrid/utils.rb', line 39 def (array, ) position = .extract!(:before, :after) if position[:before] array.index {|c| c.name.to_sym == position[:before].to_sym } elsif position[:after] array.index {|c| c.name.to_sym == position[:after].to_sym } + 1 else -1 end end |
.string_like?(value) ⇒ Boolean
35 36 37 |
# File 'lib/datagrid/utils.rb', line 35 def string_like?(value) value.is_a?(Symbol) || value.is_a?(String) end |
.warn_once(message) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/datagrid/utils.rb', line 12 def warn_once() @warnings ||= {} if @warnings[] false else warn @warnings[] = true end end |