Class: UseTheForce::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/use_the_force/base.rb

Defined Under Namespace

Classes: Relation

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.

Raises:

  • (NotImplementedError)


148
149
150
# File 'lib/use_the_force/base.rb', line 148

def initialize
  raise NotImplementedError
end

Class Method Details

.allObject



85
86
87
# File 'lib/use_the_force/base.rb', line 85

def all
  Relation.new(client, target: self).where
end

.clientObject



143
144
145
# File 'lib/use_the_force/base.rb', line 143

def client
  @@client ||= Restforce.new(**configuration)
end

.configurationObject



131
132
133
134
135
136
137
138
139
140
141
# File 'lib/use_the_force/base.rb', line 131

def configuration
  {
    username: UseTheForce.username,
    password: UseTheForce.pw,
    api_version: UseTheForce.api_version,
    client_id: UseTheForce.client_id,
    client_secret: UseTheForce.client_secret,
    security_token: UseTheForce.security_token,
    instance_url: UseTheForce.instance_url
  }
end

.create(**attributes) ⇒ Object



73
74
75
# File 'lib/use_the_force/base.rb', line 73

def create(**attributes)
  Relation.new(client, target: self).create(**attributes)
end

.destroy(id) ⇒ Object



81
82
83
# File 'lib/use_the_force/base.rb', line 81

def destroy(id)
  Relation.new(client, target: self).destroy(id)
end

.fields(*list) ⇒ Object



115
116
117
# File 'lib/use_the_force/base.rb', line 115

def fields(*list)
  @@fields = list
end

.find(id) ⇒ Object



93
94
95
# File 'lib/use_the_force/base.rb', line 93

def find(id)
  Relation.new(client, target: self).find(id)
end

.find!(id) ⇒ Object



97
98
99
100
101
102
# File 'lib/use_the_force/base.rb', line 97

def find!(id)
  unless (record = find(id))
    raise UseTheForce::RecordNotFound
  end
  record
end

.find_byObject



104
105
106
# File 'lib/use_the_force/base.rb', line 104

def find_by(**)
  where(**)&.first
end

.find_by!Object



108
109
110
111
112
113
# File 'lib/use_the_force/base.rb', line 108

def find_by!(**)
  unless (record = where(**)&.first)
    raise UseTheForce::RecordNotFound
  end
  record
end

.read_fieldsObject



123
124
125
# File 'lib/use_the_force/base.rb', line 123

def read_fields
  @@fields
end

.read_table_nameObject



127
128
129
# File 'lib/use_the_force/base.rb', line 127

def read_table_name
  @@table_name
end

.table_name(name) ⇒ Object



119
120
121
# File 'lib/use_the_force/base.rb', line 119

def table_name(name)
  @@table_name = name.to_s
end

.update(id, **attributes) ⇒ Object



77
78
79
# File 'lib/use_the_force/base.rb', line 77

def update(id, **attributes)
  Relation.new(client, target: self).update(id, **attributes)
end

.whereObject



89
90
91
# File 'lib/use_the_force/base.rb', line 89

def where(**)
  Relation.new(client, target: self).where(**)
end