Module: Datagrid::Utils

Defined in:
lib/datagrid/utils.rb

Constant Summary collapse

TRUTH =
[true, 1, "1", "true", "yes", "on"]

Class Method Summary collapse

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(options, *classes)
  options = options.clone
  options[:class] ||= ""
  if options[:class].is_a?(Array)
    options[:class] += classes
  else
    # suppose that it is a String
    options[:class] += " " unless options[:class].blank?
    options[:class] += classes.join(" ")
  end
  options
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 extract_position_from_options(array, options)
  position = options.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

Returns:

  • (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(message)
  @warnings ||= {}
  if @warnings[message] 
    false
  else
    warn message
    @warnings[message] = true
  end
end