Module: Api::UtilsSerializerHelper

Instance Method Summary collapse

Instance Method Details

#badges(obj = nil) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/serializers/concerns/api/utils_serializer_helper.rb', line 83

def badges(obj = nil)
  obj = object if obj.nil?
  if obj.class.method_defined? :badges
    obj.badges.map do |badge|
      {
        id: badge.id,
        name: badge.name,
        description: badge.description,
        custom_fields: badge.custom_fields
      }
    end
  else
    []
  end
end

#documents(obj = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/serializers/concerns/api/utils_serializer_helper.rb', line 4

def documents(obj = nil)
  obj = object if obj.nil?
  if obj.documents.attached?
    obj.documents.attachments.map do |document|
      url = Rails.application.routes.url_helpers.rails_blob_url(document)
      if document.variable?
        variant = document.variant(resize: '400x400^')
        url_variant = Rails.application.routes.url_helpers.rails_representation_url(variant)
      else
        url_variant = url
      end
      {
        id: document.blob.id,
        content_type: document.blob.content_type,
        filename: document.blob.filename,
        url_variant: url_variant,
        url: url
      }
    end
  else
    []
  end
end

#documents_feedObject



28
29
30
31
32
33
# File 'app/serializers/concerns/api/utils_serializer_helper.rb', line 28

def documents_feed
  unless object.feed.nil?
    attachments = get_feed_attachments(object)
    attachments.flatten
  end
end

#feed_idObject



99
100
101
# File 'app/serializers/concerns/api/utils_serializer_helper.rb', line 99

def feed_id
  object.feed.id
end

#geoloc(obj = nil) ⇒ Object



60
61
62
63
64
65
66
# File 'app/serializers/concerns/api/utils_serializer_helper.rb', line 60

def geoloc(obj = nil)
  obj = object if obj.nil?
  {
    lat: obj.latitude,
    lng: obj.longitude
  }
end

#get_feed_attachments(obj) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/serializers/concerns/api/utils_serializer_helper.rb', line 35

def get_feed_attachments(obj)
  includes = %i[documents_attachments]

  obj.feed.posts.includes(includes).map do |post|
    next unless post.documents.attached?

    post.documents.attachments.map do |document|
      url = Rails.application.routes.url_helpers.rails_blob_url(document)
      if document.variable?
        variant = document.variant(resize: '400x400^')
        url_variant = Rails.application.routes.url_helpers.rails_representation_url(variant)
      else
        url_variant = url
      end
      {
        id: document.blob.id,
        content_type: document.blob.content_type,
        filename: document.blob.filename,
        url_variant: url_variant,
        url: url
      }
    end
  end
end

#interests(obj = nil) ⇒ Object



68
69
70
71
# File 'app/serializers/concerns/api/utils_serializer_helper.rb', line 68

def interests(obj = nil)
  obj = object if obj.nil?
  obj.interests.map(&:id)
end

#ressources(obj = nil) ⇒ Object



78
79
80
81
# File 'app/serializers/concerns/api/utils_serializer_helper.rb', line 78

def ressources(obj = nil)
  obj = object if obj.nil?
  obj.ressources.map(&:ressource_name)
end

#scope?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'app/serializers/concerns/api/utils_serializer_helper.rb', line 103

def scope?
  defined?(current_user).nil?
end

#skills(obj = nil) ⇒ Object



73
74
75
76
# File 'app/serializers/concerns/api/utils_serializer_helper.rb', line 73

def skills(obj = nil)
  obj = object if obj.nil?
  obj.skills.map(&:skill_name)
end