Module: Fixturama::Utils

Defined in:
lib/fixturama/utils.rb

Class Method Summary collapse

Class Method Details

.array(list) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/fixturama/utils.rb', line 25

def array(list)
  case list
  when NilClass then []
  when Array    then list
  else [list]
  end
end

.clone(item) ⇒ Object



21
22
23
# File 'lib/fixturama/utils.rb', line 21

def clone(item)
  item.respond_to?(:dup) ? item.dup : item
end

.constantize(item) ⇒ Object



17
18
19
# File 'lib/fixturama/utils.rb', line 17

def constantize(item)
  Kernel.const_get(item.to_s)
end

.matched_hash_args?(actual, expected) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/fixturama/utils.rb', line 33

def matched_hash_args?(actual, expected)
  return unless actual.is_a?(Hash) && expected.is_a?(Hash)

  expected.all? { |key, val| actual[key] == val }
end

.symbolize(item) ⇒ Object



5
6
7
# File 'lib/fixturama/utils.rb', line 5

def symbolize(item)
  item.to_s.to_sym
end

.symbolize_array(data) ⇒ Object



13
14
15
# File 'lib/fixturama/utils.rb', line 13

def symbolize_array(data)
  Array(data).map { |item| symbolize(item) }
end

.symbolize_hash(data) ⇒ Object



9
10
11
# File 'lib/fixturama/utils.rb', line 9

def symbolize_hash(data)
  Hash(data).transform_keys { |key| symbolize(key)}
end