Sha256: f87c2d867ffef31b6cf63eaef2732ea538eaf103524f26af09695cbf5f60dc0b

Contents?: true

Size: 778 Bytes

Versions: 1

Compression:

Stored size: 778 Bytes

Contents

require 'plist'

module Rack
  class Newsstand
    class Issue < Sequel::Model
      plugin :json_serializer, naked: true, except: :id
      plugin :validation_helpers
      plugin :timestamps, force: true, update_on_create: true
      plugin :schema
      plugin :typecast_on_load

      self.dataset = :newsstand_issues
      self.strict_param_setting = false
      self.raise_on_save_failure = false

      def to_plist_node
        {
          name: self.name,
          date: self.published_at,
          covers: (self.cover_urls || {}).to_hash,
          assets: (self.asset_urls || []).to_a
        }.to_plist(false)
      end

      def validate
        super

        validates_presence [:name, :published_at]
        validates_unique :name
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-newsstand-0.1.2 ./lib/rack/newsstand/models/issue.rb