13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/ixtlan/models/configuration.rb', line 13
def self.included(model)
model.send(:include, DataMapper::Resource)
model.send(:include, UpdateChildren)
model.property :id, ::DataMapper::Types::Serial
model.property :session_idle_timeout, Integer, :required => true
model.property :keep_audit_logs, Integer, :required => true
model.property :password_sender_email, String, :format => :email_address, :required => false, :length => 64
model.property :login_url, String, :required => false, :length => 128
model.property :notification_sender_email, String, :format => :email_address, :required => false, :length => 64
model.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
model.property :errors_dump_directory, String, :required => false, :length => 192
model.property :logfiles_directory, String, :required => false, :length => 192
model.timestamps :updated_at
model.modified_by ::Ixtlan::Models::USER, :updated_by
model.has model.n, :locales, :model => ::Ixtlan::Models::LOCALE, :through => DataMapper::Resource
model.class_eval <<-EOS, __FILE__, __LINE__
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!({
:skip_types => true,
:skip_empty_tags => true,
:methods => [:updated_by, :locales],
:updated_by => {
:methods => [],
:exclude => [:created_at, :updated_at, :hashed_password, :created_by_id, :updated_by_id, :language]
},
:locales => {
:methods => [],
:exclude => [:created_at]
},
:exclude => [:updated_by_id, :id]
})
end
to_x(opts, doc)
end
EOS
end
|