Class: Employee
Defined Under Namespace
Classes: Slimtimer
Instance Method Summary
collapse
append_features, #credential_after_save, #validate_credential_fields
append_features, #initialize
append_features
Instance Method Details
#authorized_for?(options) ⇒ Boolean
35
36
37
38
39
40
41
42
43
44
|
# File 'app/models/employee.rb', line 35
def authorized_for?(options)
return true unless options.try(:[],:action)
case options[:action].to_sym
when :delete
( Activity::Labor.count( :all, :conditions => ['employee_id = ?', id] ) > 0 ) ? false : true
else
true
end
end
|
#ensure_not_referenced_on_destroy ⇒ Object
31
32
33
|
# File 'app/models/employee.rb', line 31
def ensure_not_referenced_on_destroy
( errors.add_to_base "Can't destroy a referenced employee" and return false ) unless authorized_for? :action => :delete
end
|
#name ⇒ Object
17
18
19
20
21
|
# File 'app/models/employee.rb', line 17
def name
[
first_name, last_name
].find_all{|x| x.try(:length).try(:>,0)}.join(' ')
end
|
#short_name ⇒ Object
23
24
25
26
27
28
29
|
# File 'app/models/employee.rb', line 23
def short_name
if first_name.length > 0 and last_name.length > 0
(first_name[0...1] + last_name).downcase
else
(first_name.length > 0) ? first_name.downcase : last_name.downcase
end
end
|
#with_unsaved_associated ⇒ Object
There were some issues in rails 2.3.2 that caused associations (slimtimer/credential/etc) to not save without this hack we may have to do it for all active record objects in the project …
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'app/models/employee.rb', line 48
def with_unsaved_associated
associations_for_update.all? do |association|
association_proxy = instance_variable_get("@#{association.name}")
if association_proxy
records = association_proxy
records = [records] unless records.is_a? Array
records.select {|r| r.changed? and not r.readonly?}.all?{|r| yield r} else
true
end
association_proxy
end
end
|