Class: Clerk::Role

Inherits:
ApplicationRecord show all
Defined in:
app/models/clerk/role.rb

Class Method Summary collapse

Methods inherited from ApplicationRecord

clerk_table_name, clerk_table_name_nc, transaction

Class Method Details

._delete_record(constraints) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/clerk/role.rb', line 43

def self._delete_record(constraints)
  delete_id = constraints["id"]
  if delete_id.nil?
    raise ActiveRecord::RecordNotFound.new("Must pass an id to delete a role", self)
  end

  begin
    response = Clerk.api.delete("/roles/#{delete_id}")
  rescue
    raise Clerk::Errors::ClerkServerError.new("Failed to delete the role", self)
  end


  if response.status != 200
    raise Clerk::Errors::ClerkServerError.new("Failed to delete the role", self)
  end

  # overriden function returns the number of rows affected
  return 1      
end

._insert_record(values) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/clerk/role.rb', line 8

def self._insert_record(values)
  begin 
    response = Clerk.api.post('/roles', values)
    id = JSON.parse(response.body)["id"]
  rescue
    raise Clerk::Errors::ClerkServerError.new("Failed to save the role", self)
  end        

  if response.status != 200 or id.nil?
    raise Clerk::Errors::ClerkServerError.new("Failed to save the role", self)
  end
  
  return id
end

._update_record(values, constraints) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/clerk/role.rb', line 23

def self._update_record(values, constraints)
  update_id = constraints["id"]
  if update_id.nil?
    raise ActiveRecord::RecordNotFound.new("Must pass an id to update a role", self)
  end

  begin
    response = Clerk.api.patch("/roles/#{update_id}", values.merge!(constraints))
  rescue
    raise Clerk::Errors::ClerkServerError.new("Failed to update the role", self)
  end

  if response.status != 200
    raise Clerk::Errors::ClerkServerError.new("Failed to update the role", self)
  end

  # overriden function returns the number of rows affected
  return 1
end

.delete_allObject



70
71
72
# File 'app/models/clerk/role.rb', line 70

def self.delete_all
  raise Clerk::Errors::MethodDisabled.new("delete_all is disabled for Clerk::Role") 
end

.destroy_allObject



74
75
76
# File 'app/models/clerk/role.rb', line 74

def self.destroy_all
  raise Clerk::Errors::MethodDisabled.new("destroy_all is disabled for Clerk::Role")
end

.update_all(updates) ⇒ Object

disable bulk calls



66
67
68
# File 'app/models/clerk/role.rb', line 66

def self.update_all(updates)
  raise Clerk::Errors::MethodDisabled.new("update_all is disabled for Clerk::Role")
end