Skip to content

Commit c7c692d

Browse files
committed
Refactor code to use consistent naming conventions
1 parent 2a0fe18 commit c7c692d

File tree

11 files changed

+95
-354
lines changed

11 files changed

+95
-354
lines changed

docusaurus/docs/tutorial-ruby-couchbase-orm/02-installation.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Before installing Couchbase ORM, ensure that you have the following prerequisite
88

99
1. **Ruby**: Couchbase ORM requires Ruby version 2.7 or higher. You can check your Ruby version by running the following command in your terminal:
1010

11-
```
11+
```sh
1212
ruby -v
1313
```
1414

@@ -20,7 +20,7 @@ Before installing Couchbase ORM, ensure that you have the following prerequisite
2020

2121
3. **Bundler** (optional): Bundler is a dependency management tool for Ruby. While not strictly required, it is recommended to use Bundler to manage your Ruby project's dependencies. You can install Bundler by running the following command:
2222

23-
```
23+
```sh
2424
gem install bundler
2525
```
2626

@@ -75,17 +75,19 @@ To use Couchbase ORM in your Ruby application, you need to configure the connect
7575
username: my_username
7676
password: my_password
7777

78-
production:
79-
connection_string: couchbase://localhost
80-
bucket: my_app_production
81-
username: my_username
82-
password: my_password
78+
production:
79+
connection_string: <%= ENV['COUCHBASE_CONNECTION_STRING'] %>
80+
bucket: <%= ENV['COUCHBASE_BUCKET'] %>
81+
username: <%= ENV['COUCHBASE_USER'] %>
82+
password: <%= ENV['COUCHBASE_PASSWORD'] %>
8383
```
8484
8585
Replace the values for `connection_string`, `bucket`, `username`, and `password` with your actual Couchbase Server connection details.
8686

8787
Couchbase ORM will automatically load the configuration based on the current Rails environment.
8888

89+
You can also set the connection details using environment variables in the production environment to avoid storing sensitive information in the source code.
90+
8991
2. **Non-Rails Applications**:
9092

9193
For non-Rails applications, you can configure the connection settings programmatically. Add the following code to your application's initialization file or before you start using Couchbase ORM:

docusaurus/docs/tutorial-ruby-couchbase-orm/03-defining-models.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ Here's an example of using attribute options:
6767
```ruby
6868
class User < CouchbaseOrm::Base
6969
attribute :name, :string, default: 'Unknown'
70-
# attribute :email, :string, alias: :contact_email
71-
# attribute :age, :integer, readonly: true
7270
end
7371
```
7472

docusaurus/docs/tutorial-ruby-couchbase-orm/04-querying.md

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -37,54 +37,26 @@ author3.save
3737
author4.save
3838

3939
# Find authors by ID
40-
puts "Find by ID:"
4140
puts Author.find(author1.id).inspect
4241

4342
# Find the first author with a specific name
44-
puts "\nFind by name:"
4543
puts Author.find_by(name: 'John Doe').inspect
4644

4745
# Where
48-
puts "\nWhere:"
4946
puts Author.where(active: true).to_a.inspect
5047
```
5148

52-
Output of the above code:
53-
```
54-
Find by ID:
55-
#<Author id: "author-1-tIqa9xA5k", name: "John Doe", age: 30, active: true>
56-
57-
Find by name:
58-
#<Author id: "author-1-tIqa9xA5k", name: "John Doe", age: 30, active: true>
59-
60-
Where:
61-
[#<Author id: "author-1-tIqa9xA5k", name: "John Doe", age: 30, active: true>, #<Author id: "author-1-tIqaAdJC-", name: "Alice Brown", age: 40, active: true>]
62-
```
63-
64-
6549
## 4.2. Where Clauses
6650

6751
The `where` method allows you to specify conditions to filter the records based on attribute values. You can chain multiple `where` clauses together to build more complex queries.
6852

6953
```ruby
7054
# Where
71-
puts "\nWhere chain:"
7255
puts Author.where(active: true).where('age >= 30').to_a.inspect
7356

74-
puts "\nWhere with regex:"
7557
puts Author.where("name like '%John%'").to_a.inspect
7658
```
7759

78-
Output
79-
```
80-
Where chain:
81-
[#<Author id: "author-1-tJFHUZcxT", name: "John Doe", age: 30, active: true>, #<Author id: "author-1-tJFHWh88k", name: "Alice Brown", age: 40, active: true>]
82-
83-
Where with regex:
84-
[#<Author id: "author-1-tJFHUZcxT", name: "John Doe", age: 30, active: true>]
85-
```
86-
87-
8860
CouchbaseOrm supports various comparison operators and placeholders in the `where` clauses, such as `=`, `>`, `<`, `>=`, `<=`, `LIKE`, and more.
8961

9062
## 4.3. Ordering
@@ -93,23 +65,12 @@ You can specify the order in which the retrieved records should be sorted using
9365

9466
```ruby
9567
# Order authors by name
96-
puts "\nOrder by name:"
9768
puts Author.order(:name).to_a.inspect
9869

9970
# Order authors by age in descending order
100-
puts "\nOrder by age (descending):"
10171
puts Author.order(age: :desc).to_a.inspect
10272
```
10373

104-
Output
105-
```
106-
Order by name:
107-
[#<Author id: "author-1-tJFHWh88k", name: "Alice Brown", age: 40, active: true>, #<Author id: "author-1-tJFHW6h7V", name: "Jane Smith", age: 25, active: false>, #<Author id: "author-1-tJFHUZcxT", name: "John Doe", age: 30, active: true>]
108-
109-
Order by age (descending):
110-
[#<Author id: "author-1-tJFHWh88k", name: "Alice Brown", age: 40, active: true>, #<Author id: "author-1-tJFHUZcxT", name: "John Doe", age: 30, active: true>, #<Author id: "author-1-tJFHW6h7V", name: "Jane Smith", age: 25, active: false>]
111-
```
112-
11374
You can also chain multiple `order` clauses to sort by multiple attributes.
11475

11576

@@ -121,39 +82,25 @@ The `pluck` method allows you to retrieve specific attributes from the matched r
12182

12283
```ruby
12384
# Pluck names of all authors
124-
puts "\nPluck names:"
12585
puts Author.order(:name).pluck(:name).inspect
12686
```
12787

128-
Output
129-
```
130-
Pluck names:
131-
["Alice Brown", "Jane Smith", "John Doe"]
132-
```
133-
13488
## 4.5. Destroying Records
13589

13690
To delete multiple records that match specific conditions, you can use the `.each(&:destroy)` method. It deletes the records from the database and returns the number of records deleted.
13791

92+
- `:destroy`: Deletes a single record.
93+
- `delete_all`: Deletes all records that match the specified conditions.
94+
13895
```ruby
13996
# Destroy all inactive authors
140-
puts "\nDestroy all inactive authors:"
141-
authors = Author.where(active: false).to_a
142-
puts authors.inspect
14397
Author.where(active: false).each(&:destroy)
14498

145-
# Check remaining authors
146-
puts "\nRemaining authors:"
147-
puts Author.all.to_a.inspect
148-
```
99+
# Destroy all authors who are inactive
100+
Author.where(active: false).delete_all
149101

150-
Output
151-
```
152-
Remaining authors:
153-
[#<Author id: "author-1-tK5S-hJY3", name: "Alice Brown", age: 40, active: true>, #<Author id: "author-1-tK5SzrgQL", name: "John Doe", age: 30, active: true>]
154102
```
155103

156-
Be cautious when using `.each(&:destroy)` as it permanently deletes the matched records from the database.
157104

158105
These are just a few examples of the querying capabilities provided by CouchbaseOrm. You can combine these methods in various ways to construct complex and specific queries based on your application's requirements.
159106

@@ -205,9 +152,3 @@ comments.each do |comment|
205152
puts "Title: #{comment.title}, Author: #{comment.author}, Category: #{comment.category}, Ratings: #{comment.ratings}"
206153
end
207154
```
208-
209-
Output
210-
```
211-
Title: First Comment, Author: Anne McCaffrey, Category: S-F, Ratings: 5
212-
Title: Second Comment, Author: Anne McCaffrey, Category: S-F, Ratings: 4
213-
```

docusaurus/docs/tutorial-ruby-couchbase-orm/05-persistence.md

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,17 @@ class Task < CouchbaseOrm::Base
1313
attribute :completed, :boolean, default: false
1414
end
1515

16-
task1 = Task.new(title: 'Task 1', description: 'Description of Task 1')
17-
task1.save
18-
puts "Task 1 created with id: #{task1.id}, #{task1.inspect}"
16+
task = Task.new(title: 'Task 1', description: 'Description of Task 1')
17+
task.save
1918
```
2019

2120
Alternatively, you can use the `create` method to create a new record in a single step:
2221

2322
```ruby
24-
task1 = Task.create(title: 'Task 1', description: 'Description of Task 1')
25-
```
26-
Output of the above code:
27-
```
28-
Task 1 created with id: task-1-tLJM721QY, #<Task id: "task-1-tLJM721QY", title: "Task 1", description: "Description of Task 1", completed: false>
23+
task = Task.create(title: 'Task 1', description: 'Description of Task 1')
2924
```
3025

26+
3127
The `create` method instantiates a new instance of the model, sets the attributes, and saves it to the database.
3228

3329
## 5.2. Saving Records
@@ -36,16 +32,12 @@ The `save` method is used to persist a record to the database, whether it's a ne
3632

3733
```ruby
3834
# Update an existing task
39-
task2 = Task.create(title: 'Task 2', description: 'Description of Task 2')
40-
task2.description = 'Updated description of Task 2'
41-
task2.save
42-
puts "Task 2 updated with id: #{task2.id}, #{task2.inspect}"
35+
task = Task.create(title: 'Task 2', description: 'Description of Task 2')
36+
task.description = 'Updated description of Task 2'
37+
task.save
4338
```
4439

45-
Output of the above code:
46-
```
47-
Task 2 updated with id: task-1-tLJM895Xq, #<Task id: "task-1-tLJM895Xq", title: "Task 2", description: "Updated description of Task 2", completed: false>
48-
```
40+
4941

5042
If the record is new (i.e., it doesn't have an ID), `save` will create a new document in Couchbase Server. If the record already exists, `save` will update the existing document with the modified attributes.
5143

@@ -55,14 +47,8 @@ To update an existing record, you can modify its attributes and then call the `s
5547

5648
```ruby
5749
# Update specific fields of a task
58-
task3 = Task.create(title: 'Task 3', description: 'Description of Task 3')
59-
task3.update(description: 'Updated description of Task 3', completed: true)
60-
puts "Task 3 updated with id: #{task3.id}, #{task3.inspect}"
61-
```
62-
63-
Output of the above code:
64-
```
65-
Task 3 updated with id: task-1-tLJMA6cBp, #<Task id: "task-1-tLJMA6cBp", title: "Task 3", description: "Updated description of Task 3", completed: true>
50+
task = Task.create(title: 'Task 3', description: 'Description of Task 3')
51+
task.update(description: 'Updated description of Task 3', completed: true)
6652
```
6753

6854
CouchbaseOrm automatically tracks the changes made to the attributes and updates only the modified fields in the database.

0 commit comments

Comments
 (0)