Class: UseTheForce::Base
- Inherits:
-
Object
- Object
- UseTheForce::Base
- Defined in:
- lib/use_the_force/base.rb
Defined Under Namespace
Classes: Relation
Class Method Summary collapse
- .all ⇒ Object
- .client ⇒ Object
- .configuration ⇒ Object
- .create(**attributes) ⇒ Object
- .destroy(id) ⇒ Object
- .fields(*list) ⇒ Object
- .find(id) ⇒ Object
- .find!(id) ⇒ Object
- .find_by ⇒ Object
- .find_by! ⇒ Object
- .read_fields ⇒ Object
- .read_table_name ⇒ Object
- .table_name(name) ⇒ Object
- .update(id, **attributes) ⇒ Object
- .where ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
148 149 150 |
# File 'lib/use_the_force/base.rb', line 148 def initialize raise NotImplementedError end |
Class Method Details
.all ⇒ Object
85 86 87 |
# File 'lib/use_the_force/base.rb', line 85 def all Relation.new(client, target: self).where end |
.client ⇒ Object
143 144 145 |
# File 'lib/use_the_force/base.rb', line 143 def client @@client ||= Restforce.new(**configuration) end |
.configuration ⇒ Object
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_by ⇒ Object
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_fields ⇒ Object
123 124 125 |
# File 'lib/use_the_force/base.rb', line 123 def read_fields @@fields end |
.read_table_name ⇒ Object
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 |