Module: Bugly::Util

Defined in:
lib/bugly.rb

Class Method Summary collapse

Class Method Details

.convert_to_bugly_object(resp, api_key) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/bugly.rb', line 50

def self.convert_to_bugly_object(resp, api_key)
  types = {
    'issue' => Issue,
    'project' => Project,
    'milestone' => Milestone,
    'category' => Category,
    'view' => View,
    'user' => User,
    'changeset' => Changeset,
    'comment' => Comment,
    'page' => Page
  }
  case resp
  when Array
    resp.map { |i| convert_to_bugly_object(i, api_key) }
  when Hash
    # Try converting to a known object class.  If none available, fall back to generic APIResource
    if klass_name = resp[:object]
      klass = types[klass_name]
    end
    klass ||= BuglyObject
    klass.construct_from(resp, api_key)
  else
    resp
  end
end

.file_readable(file) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/bugly.rb', line 77

def self.file_readable(file)
  begin
    File.open(file) { |f| }
  rescue
    false
  else
    true
  end
end

.objects_to_ids(h) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/bugly.rb', line 35

def self.objects_to_ids(h)
  case h
  when APIResource
    h.id
  when Hash
    res = {}
    h.each { |k, v| res[k] = objects_to_ids(v) unless v.nil? }
    res
  when Array
    h.map { |v| objects_to_ids(v) }
  else
    h
  end
end

.symbolize_names(object) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/bugly.rb', line 87

def self.symbolize_names(object)
  case object
  when Hash
    new = {}
    object.each do |key, value|
      key = (key.to_sym rescue key) || key
      new[key] = symbolize_names(value)
    end
    new
  when Array
    object.map { |value| symbolize_names(value) }
  else
    object
  end
end