Class: OpenShift::UserModel
- Inherits:
-
Model
- Object
- Model
- OpenShift::UserModel
show all
- Defined in:
- lib/openshift-origin-common/models/user_model.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Model
attr_accessor, attr_reader, attr_writer, #attributes, #attributes=, #deleted?, exclude_attributes, excludes_attributes, gen_uuid, include_attributes, includes_attributes, #new_record?, #persisted?, primary_key, require_update_attributes, requires_update_attributes, #reset_state, #to_xml
Constructor Details
Returns a new instance of UserModel.
4
5
6
|
# File 'lib/openshift-origin-common/models/user_model.rb', line 4
def initialize()
super()
end
|
Class Method Details
.find(login, id) ⇒ Object
8
9
10
11
12
13
|
# File 'lib/openshift-origin-common/models/user_model.rb', line 8
def self.find(login, id)
hash = DataStore.instance.find(self.name,login,id)
return nil unless hash
hash_to_obj(hash)
end
|
.find_all(login, opts = nil, &block) ⇒ Object
22
23
24
25
26
27
28
29
30
|
# File 'lib/openshift-origin-common/models/user_model.rb', line 22
def self.find_all(login, opts=nil, &block)
hash_list = DataStore.instance.find_all(self.name, login, opts, &block)
unless block_given?
return hash_list if hash_list.empty?
hash_list.map! do |hash|
hash_to_obj(hash)
end
end
end
|
.find_by_uuid(uuid) ⇒ Object
15
16
17
18
19
20
|
# File 'lib/openshift-origin-common/models/user_model.rb', line 15
def self.find_by_uuid(uuid)
hash = DataStore.instance.find_by_uuid(self.name,uuid)
return nil unless hash
hash_to_obj(hash)
end
|
Instance Method Details
#delete(login) ⇒ Object
32
33
34
35
|
# File 'lib/openshift-origin-common/models/user_model.rb', line 32
def delete(login)
id_var = self.class.pk || "uuid"
DataStore.instance.delete(self.class.name, login, instance_variable_get("@#{id_var}"))
end
|
#save(login) ⇒ Object
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
|
# File 'lib/openshift-origin-common/models/user_model.rb', line 37
def save(login)
id_var = self.class.pk || "uuid"
if persisted?
if self.class.requires_update_attributes
changed_attrs = {}
unless changes.empty?
changes.each do |key, value|
value = value[1]
unless self.class.excludes_attributes.include? key.to_sym
(changed_attrs, key, value)
end
end
end
self.class.requires_update_attributes.each do |key|
key = key.to_s
value = instance_variable_get("@#{key}")
(changed_attrs, key, value)
end
DataStore.instance.save(self.class.name, login, instance_variable_get("@#{id_var}"), changed_attrs) unless changed_attrs.empty?
else
DataStore.instance.save(self.class.name, login, instance_variable_get("@#{id_var}"), self.attributes(true))
end
else
DataStore.instance.create(self.class.name, login, instance_variable_get("@#{id_var}"), self.attributes(true))
end
@previously_changed = changes
@changed_attributes.clear
@new_record = false
@persisted = true
@deleted = false
self
end
|