Class Mirror
In: app/models/mirror.rb
Parent: ActiveRecord::Base

Methods

Constants

F_DELETE_EXCLUDED = 'delete-excluded'
F_COMPRESS = 'compress'
F_HARD_LINKS = 'hard-links'
F_PARTIAL = 'partial'
F_PRESERVE_PERMS = 'preserve-permissions'
F_DEREFERENCE = 'dereference'
F_DEBUG = 'debug'
S_SUCCESS = 'success'
S_FAILURE = 'failure'
S_DELAYED = 'delay'
P_LOW = 'low'
P_MED = 'medium'
P_HIGH = 'high'
T_RSYNC = 'rsync'
T_FTP = 'ftp'

Public Class methods

Get array of allowed values for "flags"

[Source]

    # File app/models/mirror.rb, line 44
44:   def self.allowed_flags
45:     [F_DELETE_EXCLUDED, F_COMPRESS, F_HARD_LINKS, F_PARTIAL,
46:     F_PRESERVE_PERMS, F_DEREFERENCE, F_DEBUG]
47:   end

Get array of allowed values for "kind"

[Source]

    # File app/models/mirror.rb, line 60
60:   def self.allowed_kinds
61:     [T_RSYNC, T_FTP]
62:   end

Get array of allowed values for "priority"

[Source]

    # File app/models/mirror.rb, line 55
55:   def self.allowed_priorities
56:     [P_LOW, P_MED, P_HIGH]
57:   end

Get array of allowed values for "status"

[Source]

    # File app/models/mirror.rb, line 50
50:   def self.allowed_status
51:     [S_SUCCESS, S_FAILURE, S_DELAYED]
52:   end
== Custom find() variants =========

[Source]

    # File app/models/mirror.rb, line 84
84:   def self.findOverview
85:     find_by_sql("SELECT id, name, active, size, last_update, status," +
86:                 " update_timespec, homepage, local_dir," +
87:                 " HOUR(SEC_TO_TIME(UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(last_update))) AS age" +
88:                 " FROM mirrors")
89:   end

[Source]

    # File app/models/mirror.rb, line 92
92:   def self.find_names
93:     find_by_sql("SELECT id, name FROM mirrors")
94:   end

[Source]

    # File app/models/mirror.rb, line 65
65:   def initialize(*params)
66:     super(*params)
67:     
68:     self.kind             ||= T_RSYNC
69:     self.priority         ||= P_MED
70:     self.size             ||= 0
71:     self.update_timespec  ||= "+1d"
72:     self.last_update      ||= Time.at(0)
73:     self.active             = true if(self.active.nil?)
74:     self.flags            ||= []
75:     self.exclude_patterns ||= []
76:   end

Public Instance methods

Custom Field Encodings, initialization etc ==

[Source]

     # File app/models/mirror.rb, line 166
166:   def after_find
167:     decode_fields
168:   end

[Source]

     # File app/models/mirror.rb, line 141
141:   def exclude_patterns
142:     @conv_exclude_patterns ||= read_attribute('exclude_patterns').to_s.split(/\n+/)
143:   end

[Source]

     # File app/models/mirror.rb, line 145
145:   def exclude_patterns=(value)
146:     write_attribute('exclude_patterns', (value.class <= Array) ? value.join("\n") : value.to_s)
147:     @conv_exclude_patterns = nil
148:   end

Custom accessors ==

[Source]

     # File app/models/mirror.rb, line 131
131:   def flags
132:     @conv_flags ||= read_attribute('flags').split(/\s*,\s*/)
133:   end

[Source]

     # File app/models/mirror.rb, line 135
135:   def flags=(value)
136:     write_attribute('flags', (value.class <= Array) ? value.join(',') : value.to_s)
137:     @conv_flags = nil
138:   end

[Source]

     # File app/models/mirror.rb, line 151
151:   def update_timespec
152:     # No handling for nil, since this is a required attribute
153:     @conv_update_timespec ||= Dsadmin::TimeSpec.create(read_attribute('update_timespec'))
154:   end

[Source]

     # File app/models/mirror.rb, line 156
156:   def update_timespec=(spec)
157:     write_attribute('update_timespec', spec.to_s)
158:     @conv_update_timespec = nil
159:   end

[Source]

     # File app/models/mirror.rb, line 116
116:   def validate
117:     if(remote_port && (remote_port <= 0))
118:       errors.add(:remote_port, "may not be negative")
119:     end
120:     
121:     fdiff = self.flags - Mirror.allowed_flags
122:     errors.add(:flags, "contains invalid values: #{fdiff.to_s}") if(fdiff.size > 0)
123:   end

Private Instance methods

[Source]

     # File app/models/mirror.rb, line 175
175:   def decode_fields
176:     self[:remote_port]        = nil if((self[:remote_port] != nil) && (self[:remote_port].strip == ""))
177:     self[:remote_user]        = nil if((self[:remote_user] != nil) && (self[:remote_user].strip == ""))
178:     self[:remote_passwd]      = nil if((self[:remote_passwd] != nil) && (self[:remote_passwd].strip == ""))
179:   end

[Validate]