Module: Datagrid::Utils
- Defined in:
- lib/datagrid/utils.rb
Overview
:nodoc:
Constant Summary collapse
- TRUTH =
[true, 1, "1", "true", "yes", "on"]
Class Method Summary collapse
- .add_html_classes(options, *classes) ⇒ Object
- .apply_args(*args, &block) ⇒ Object
- .booleanize(value) ⇒ Object
- .extract_position_from_options(array, options) ⇒ Object
- .string_like?(value) ⇒ Boolean
- .warn_once(message, delay = 5) ⇒ Object
Class Method Details
.add_html_classes(options, *classes) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/datagrid/utils.rb', line 21 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 |
.apply_args(*args, &block) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/datagrid/utils.rb', line 49 def apply_args(*args, &block) return block.call(*args) if block.arity < 0 args = args.clone (args.size - block.arity).times do args.pop end block.call(*args) 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
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/datagrid/utils.rb', line 38 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
34 35 36 |
# File 'lib/datagrid/utils.rb', line 34 def string_like?(value) value.is_a?(Symbol) || value.is_a?(String) end |
.warn_once(message, delay = 5) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/datagrid/utils.rb', line 12 def warn_once(, delay = 5) @warnings ||= {} = @warnings[] return false if && >= Time.now - delay warn @warnings[] = Time.now true end |