Class: WCC::Data::Nucleus::User

Inherits:
Base show all
Defined in:
lib/wcc/data/nucleus/user.rb

Constant Summary collapse

SAVE_ATTRS =
%i[arena_id rock_id user_reviewed_at]

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mapper::JSONResponse

#new_from_response

Methods included from Mapper::RESTConfiguration

#endpoint, #endpoint_config, #inherited, #set_endpoint

Methods included from Mapper::RESTQuery

#create, #find, #list

Methods included from Mapper::Attributes

included

Class Method Details

.search(string, options = {}) ⇒ Object



44
45
46
# File 'lib/wcc/data/nucleus/user.rb', line 44

def self.search(string, options={})
  list(options.merge(search: string))
end

Instance Method Details

#addressObject



25
26
27
# File 'lib/wcc/data/nucleus/user.rb', line 25

def address
  @address ||= Address.new self[:address].merge("user_id" => id)
end

#contactObject



21
22
23
# File 'lib/wcc/data/nucleus/user.rb', line 21

def contact
  @contact ||= Contact.new self[:contact].merge("user_id" => id)
end

#saveObject



33
34
35
# File 'lib/wcc/data/nucleus/user.rb', line 33

def save
  update_attributes saveable_attributes
end

#saveable_attributesObject



37
38
39
40
41
42
# File 'lib/wcc/data/nucleus/user.rb', line 37

def saveable_attributes
  attributes
    .select { |key, _| SAVE_ATTRS.include?(key.to_sym) }
    .merge(contact: contact.attributes)
    .merge(address: address.attributes)
end

#update_attributes(attrs = {}) ⇒ Object



29
30
31
# File 'lib/wcc/data/nucleus/user.rb', line 29

def update_attributes(attrs={})
  self.class.endpoint.update(id, user: attrs)
end