Sha256: 71c950ef616d1b7dd16687795a7c15542ba3a242f3f0ea0e34eebec8d324454c

Contents?: true

Size: 791 Bytes

Versions: 2

Compression:

Stored size: 791 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,
          title: self.title,
          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

2 entries across 2 versions & 1 rubygems

Version Path
rack-newsstand-0.1.0 ./lib/rack/newsstand/models/issue.rb
rack-newsstand-0.0.3 ./lib/rack/newsstand/models/issue.rb