Sha256: 5a6e76ad4e6c56908ae2fd78064b8b0311dc8f6ab8529ad6109a20292c836d60

Contents?: true

Size: 1.98 KB

Versions: 1

Compression:

Stored size: 1.98 KB

Contents

require 'dm-core'
require 'ixtlan/modified_by'
require 'dm-serializer'
require 'ixtlan/models/update_children'
module Ixtlan
  module Models
    class Configuration
      include DataMapper::Resource
      include UpdateChildren

      LOCALE = Object.full_const_get(Models::LOCALE)

      def self.default_storage_name
        "Configuration"
      end

      property :id, Serial

      property :session_idle_timeout, Integer, :required => true

      property :keep_audit_logs, Integer, :required => true

      property :password_sender_email, String, :format => :email_address, :required => false, :length => 64

      property :notification_sender_email, String, :format => :email_address, :required => false, :length => 64

      property :notification_recipient_emails, String, :format => Proc.new { |email| emails = email.split(','); emails.find_all { |e| e =~ DataMapper::Validate::Format::Email::EmailAddress }.size == emails.size}, :required => false, :length => 254 #honour mysql max varchar length

      property :errors_dump_directory, String, :required => false, :length => 192
      property :logfiles_directory, String, :required => false, :length => 192

      timestamps :updated_at

      modified_by ::Ixtlan::Models::USER, :updated_by

      has n, :locales, :model => ::Ixtlan::Models::LOCALE, :through => Resource

      def self.instance
        # HACK: return a new object in case there is none in the database
        # to allow rails rake tasks to work with an empty database
        begin
          get(1) || new(:id => 1, :session_idle_timeout => 5, :keep_audit_logs => 7)
        rescue
          auto_migrate!
          new(:id => 1, :session_idle_timeout => 5, :keep_audit_logs => 7)
        end
      end

      alias :to_x :to_xml_document
      def to_xml_document(opts, doc = nil)
        unless(opts[:methods] || opts[:exclude])
          opts.merge!({:methods => [:updated_by, :locales], :exclude => [:updated_by_id, :id]})
        end
        to_x(opts, doc)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ixtlan-0.3.0 lib/ixtlan/models/configuration.rb