Class: TheCity::User
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
user_basic.
-
#first ⇒ Object
readonly
user_basic.
-
#gender ⇒ Object
readonly
user_basic.
-
#id ⇒ Object
readonly
user_basic.
-
#last ⇒ Object
readonly
user_basic.
-
#name ⇒ Object
readonly
user_basic.
-
#permissions ⇒ TheCity::Permissions
Returns the permissions for the current user.
-
#profile_picture ⇒ Object
readonly
user_basic.
-
#title ⇒ Object
readonly
user_basic.
Attributes inherited from Base
Instance Method Summary collapse
-
#admin? ⇒ Boolean
Returns true/false if the current user is an admin on the current church (Group Admin, Account Admin, etc).
-
#birthdate ⇒ Date
Returns the user’s birthdate as a ruby Date object.
-
#groups ⇒ Array<TheCity::Group>
Returns the groups that the user belongs to.
- #is_in_group_with_title?(group_id, title = nil) ⇒ Boolean
-
#member? ⇒ Boolean
Returns true/false if the current user is a member of the current church.
- #method_missing(method_sym, *arguments, &block) ⇒ Object
-
#staff? ⇒ Boolean
Returns true/false if the current user is on staff at the current church.
Methods inherited from Base
#[], attr_reader, define_attribute_method, define_predicate_method, define_uri_method, from_response, #initialize, #memoize, object_attr_reader, uri_attr_reader
Constructor Details
This class inherits a constructor from TheCity::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/the_city/user.rb', line 26 def method_missing(method_sym, *arguments, &block) if method_sym.to_s =~ /^is_in_group_(\d+)\??$/ is_in_group_with_title?($1.to_i, arguments.first) else super end end |
Instance Attribute Details
#email ⇒ Object (readonly)
user_basic
5 6 7 |
# File 'lib/the_city/user.rb', line 5 def email @email end |
#first ⇒ Object (readonly)
user_basic
5 6 7 |
# File 'lib/the_city/user.rb', line 5 def first @first end |
#gender ⇒ Object (readonly)
user_basic
5 6 7 |
# File 'lib/the_city/user.rb', line 5 def gender @gender end |
#id ⇒ Object (readonly)
user_basic
5 6 7 |
# File 'lib/the_city/user.rb', line 5 def id @id end |
#last ⇒ Object (readonly)
user_basic
5 6 7 |
# File 'lib/the_city/user.rb', line 5 def last @last end |
#name ⇒ Object (readonly)
user_basic
5 6 7 |
# File 'lib/the_city/user.rb', line 5 def name @name end |
#permissions ⇒ TheCity::Permissions
Returns the permissions for the current user
57 58 59 |
# File 'lib/the_city/user.rb', line 57 def @permissions ||= @client. if (@client and @client.current_user.id == id) end |
#profile_picture ⇒ Object (readonly)
user_basic
5 6 7 |
# File 'lib/the_city/user.rb', line 5 def profile_picture @profile_picture end |
#title ⇒ Object (readonly)
user_basic
5 6 7 |
# File 'lib/the_city/user.rb', line 5 def title @title end |
Instance Method Details
#admin? ⇒ Boolean
Returns true/false if the current user is an admin on the current church (Group Admin, Account Admin, etc). If you need to check for a specific admin privilege, you will need to go through TheCity::Permissions object.
65 66 67 |
# File 'lib/the_city/user.rb', line 65 def admin? @attrs[:admin] || .admin? rescue nil end |
#birthdate ⇒ Date
Returns the user’s birthdate as a ruby Date object.
50 51 52 |
# File 'lib/the_city/user.rb', line 50 def birthdate @bday ||= Date.strptime(@attrs[:birthdate], '%m/%d/%Y') rescue nil end |
#groups ⇒ Array<TheCity::Group>
Returns the groups that the user belongs to
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/the_city/user.rb', line 12 def groups memoize(:groups) do if @attrs[:groups].any? Array(@attrs[:groups]).map do |g| TheCity::Group.new(g) end elsif @client @client.my_groups else [] end end end |
#is_in_group_with_title?(group_id, title = nil) ⇒ Boolean
Returns true/false if the current user has an active role in the group (group_id).
41 42 43 44 45 |
# File 'lib/the_city/user.rb', line 41 def is_in_group_with_title?(group_id, title=nil) return groups.any? {|g| g.id == group_id } if title.nil? titles = [title].flatten return groups.any? {|g| (g.id == group_id and titles.any? {|t| t.to_s.downcase == g.role_title.downcase } ) } end |
#member? ⇒ Boolean
Returns true/false if the current user is a member of the current church.
72 73 74 |
# File 'lib/the_city/user.rb', line 72 def member? @attrs[:member] || .member? rescue nil end |
#staff? ⇒ Boolean
Returns true/false if the current user is on staff at the current church.
79 80 81 |
# File 'lib/the_city/user.rb', line 79 def staff? @attrs[:staff] || .staff? rescue nil end |