Class: TheCity::User

Inherits:
Base
  • Object
show all
Defined in:
lib/the_city/user.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#attrs

Instance Method Summary collapse

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

#emailObject (readonly)

user_basic



5
6
7
# File 'lib/the_city/user.rb', line 5

def email
  @email
end

#firstObject (readonly)

user_basic



5
6
7
# File 'lib/the_city/user.rb', line 5

def first
  @first
end

#genderObject (readonly)

user_basic



5
6
7
# File 'lib/the_city/user.rb', line 5

def gender
  @gender
end

#idObject (readonly)

user_basic



5
6
7
# File 'lib/the_city/user.rb', line 5

def id
  @id
end

#lastObject (readonly)

user_basic



5
6
7
# File 'lib/the_city/user.rb', line 5

def last
  @last
end

#nameObject (readonly)

user_basic



5
6
7
# File 'lib/the_city/user.rb', line 5

def name
  @name
end

#permissionsTheCity::Permissions

Returns the permissions for the current user



57
58
59
# File 'lib/the_city/user.rb', line 57

def permissions
  @permissions ||= @client.permissions if (@client and @client.current_user.id == id)
end

#profile_pictureObject (readonly)

user_basic



5
6
7
# File 'lib/the_city/user.rb', line 5

def profile_picture
  @profile_picture
end

#titleObject (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.

Returns:

  • (Boolean)


65
66
67
# File 'lib/the_city/user.rb', line 65

def admin?
  @attrs[:admin] || permissions.admin? rescue nil
end

#birthdateDate

Returns the user’s birthdate as a ruby Date object.

Returns:

  • (Date)


50
51
52
# File 'lib/the_city/user.rb', line 50

def birthdate
  @bday ||= Date.strptime(@attrs[:birthdate], '%m/%d/%Y') rescue nil
end

#groupsArray<TheCity::Group>

Returns the groups that the user belongs to

Returns:



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

Note:

Returns true/false if the current user has an active role in the group (group_id).

Examples:

see if the user is a leader in group 1234

current_user.is_in_group_with_title(1234, :leader)

Parameters:

  • group_id (Integer)

    the id of TheCity::Group in question.

  • title (Array<String>) (defaults to: nil)

    the title or titles of the user’s active role.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


72
73
74
# File 'lib/the_city/user.rb', line 72

def member?
  @attrs[:member] || permissions.member? rescue nil
end

#staff?Boolean

Returns true/false if the current user is on staff at the current church.

Returns:

  • (Boolean)


79
80
81
# File 'lib/the_city/user.rb', line 79

def staff?
  @attrs[:staff] || permissions.staff? rescue nil
end