Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
show all
- Includes:
- ActiveDisablable
- Defined in:
- app/models/user.rb
Overview
Table name: users
id :integer not null, primary key
name :string(25)
email :string(100)
created_at :datetime not null
updated_at :datetime not null
Constant Summary
collapse
- VALID_NAME_REGEX =
VALIDATIONS<============================================================ BASICS
/\A\w+.*\s.*\z/i
- VALID_EMAIL_REGEX =
/\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
Instance Method Summary
collapse
#destroy, #destroy_fully, #disable, #disabled?, #enable, #enabled?, included, #recovery
Instance Method Details
#able?(module_, ability) ⇒ Boolean
97
98
99
|
# File 'app/models/user.rb', line 97
def able?(module_, ability)
all_abilities.select { |ab| ab.module.id == module_.id && ab.ability.id == ability.id }.count > 0
end
|
#all_abilities ⇒ Object
90
91
92
93
94
95
|
# File 'app/models/user.rb', line 90
def all_abilities
abilities = []
abilities << self.abilities if (self.abilities)
abilities << self.groups.collect { |g| g.abilities } if (self.groups)
abilities.flatten.flatten.uniq
end
|
#define_abilities(modules_and_abilities) ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'app/models/user.rb', line 101
def define_abilities(modules_and_abilities)
self.abilities.each do |u_ability|
u_ability.delete
end
labilities = []
modules_and_abilities.each do |module_and_ability|
labilities << abilities.build(module_and_ability)
end
self.abilities = labilities
end
|
#feed ⇒ Object
66
67
68
69
|
# File 'app/models/user.rb', line 66
def feed
Micropost.where("user_id = ?", id)
end
|
#follow!(other_user) ⇒ Object
75
76
77
|
# File 'app/models/user.rb', line 75
def follow!(other_user)
relationships.create!(followed_id: other_user.id)
end
|
#following?(other_user) ⇒ Boolean
71
72
73
|
# File 'app/models/user.rb', line 71
def following?(other_user)
relationships.find_by_followed_id(other_user.id)
end
|
#groups ⇒ Object
83
84
85
86
87
88
|
# File 'app/models/user.rb', line 83
def groups
ret = []
ret << self.primary_group if (self.primary_group)
ret << self.secundary_groups if (self.secundary_groups)
ret.flatten.uniq
end
|
#unfollow!(other_user) ⇒ Object
79
80
81
|
# File 'app/models/user.rb', line 79
def unfollow!(other_user)
relationships.find_by_followed_id(other_user.id).destroy
end
|