class Spage::Serializers::Page

Serializer for the Page resource

Public Class Methods

new(page, update: false) click to toggle source
# File lib/spage/serializers/page.rb, line 8
def initialize(page, update: false)
  @page = page
  @ivars = ivars(update)
end

Public Instance Methods

as_json() click to toggle source
# File lib/spage/serializers/page.rb, line 17
def as_json
  to_hash
end
to_hash() click to toggle source
# File lib/spage/serializers/page.rb, line 21
def to_hash
  {
    'page' => Hash[
      @ivars.map do |name|
        [name[1..-1], @page.instance_variable_get(name)]
      end
    ]
  }
end
to_json(obj = nil) click to toggle source
# File lib/spage/serializers/page.rb, line 13
def to_json(obj = nil)
  as_json.to_json(obj)
end

Private Instance Methods

ivars(update) click to toggle source
# File lib/spage/serializers/page.rb, line 33
def ivars(update)
  if update
    @page.instance_variables.select do |name|
      update_attrs.include?(name[1..-1])
    end
  else
    @page.instance_variables
  end
end
update_attrs() click to toggle source

rubocop: disable Metrics/MethodLength

# File lib/spage/serializers/page.rb, line 44
def update_attrs
  %w[
    name
    domain
    subdomain
    url
    branding
    css_body_background_color
    css_font_color
    css_light_font_color
    css_greens
    css_yellows
    css_oranges
    css_reds
    css_blues
    css_border_color
    css_graph_color
    css_link_color
    css_no_data
    hidden_from_search
    viewers_must_be_team_members
    allow_page_subscribers
    allow_incident_subscribers
    allow_email_subscribers
    allow_sms_subscribers
    allow_rss_atom_feeds
    allow_webhook_subscribers
    notifications_from_email
    time_zone
    notifications_email_footer
  ]
end