Sha256: e63dcbf70a08f59dc878f8440893f23dd55f44972b54a2fd0bb7dd8c712859e2

Contents?: true

Size: 1.64 KB

Versions: 4

Compression:

Stored size: 1.64 KB

Contents

Item
===

An item is a concrete record. It can be part of a collection.

You can access data by using dot operator `item.name_of_attribte_you_wanna_access`.

Sometimes data gets converted when accessed. For example parseable dates will be returned as Date or DateTime.

## Setter

An item proxy contains setter methods, in order to set/change values.

```
  record = Feedback.find(id: 'z12f-3asm3ngals') #<LHS::Data @_proxy=#<LHS::Item>>
  rcord.recommended = false
```

## Build

Build and persist new items from scratch.

```ruby
feedback = Feedback.build(recommended: true)
feedback.save
```

## Save

You can persist changes like you would usually do with `save`.
`save` will return false if persisting fails. `save!` instead will raise an exception.

```ruby
  feedback = Feedback.find('1z-5r1fkaj')
  feedback.recommended = false
  feedback.save
```

## Update

`update` will return false if persisting fails. `update!` instead will an raise exception.

```ruby
feedback = Feedback.find('1z-5r1fkaj')
feedback.update(recommended: false)
```

## Destroy

You can delete records remotely by calling `destroy` on an item.

```ruby
  feedback = Feedback.find('1z-5r1fkaj')
  feedback.destroy
```

## Validation

In order to validate objects before persisting them, you can use the `valid?` (`validate` alias) method.
The specific endpoint has to support validations with the `persist=false` parameter. 
The endpoint has to be enabled (opt-in) for validations in the service configuration.

```
class User < LHS::Service
  endpoint ':datastore/v2/users', validates: true
end

user = User.build(email: 'im not an email address')
unless user.valid?
  fail(user.errors[:email])
end
```

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lhs-1.6.1 docs/items.md
lhs-1.6.0 docs/items.md
lhs-1.5.0 docs/items.md
lhs-1.4.0 docs/items.md