Attributes
Basic
attribute
ruby
attribute :uuid, from: String, to: :id, as: String, format: :uuid
ruby
attribute :uuid, from: [String, NilClass], to: :id, as: [String, NilClass], format: :uuid, required: false
string
ruby
string! :uuid, to: :id
ruby
string? :uuid, to: :id
integer
ruby
integer! :rating, min: 1, max: 10
ruby
integer? :rating, min: 1, max: 10
float
ruby
float! :rating
ruby
float? :rating
boolean
ruby
boolean! :published
ruby
# not supported
Options
The following options are available for the attribute
method:
from
;to
;as
;format
;min
;max
.
For helpers these options are also available, with the exception of the from
option.
You can find out about supported values for format
here.
Helpers
uuid
ruby
uuid! :id
ruby
string! :id, format: :uuid
ruby
uuid? :id
ruby
string? :id, format: :uuid
money
ruby
money! :box_office
ruby
integer! :box_office_cents
string! :box_office_currency
ruby
money? :box_office
ruby
integer? :box_office_cents
string? :box_office_currency
duration
ruby
duration! :episode_duration
ruby
attribute :episode_duration, from: String, as: ActiveSupport::Duration, format: { from: :duration }
ruby
duration? :episode_duration
ruby
attribute :episode_duration, from: [String, NilClass], as: [ActiveSupport::Duration, NilClass], format: { from: :duration }, required: false
date
ruby
date! :premiered_on
ruby
attribute :premiered_on, from: String, as: Date, format: { from: :date }
ruby
date? :premiered_on
ruby
attribute :premiered_on, from: [String, NilClass], as: [Date, NilClass], format: { from: :date }, required: false
time
ruby
time! :premiered_at
ruby
attribute :premiered_at, from: String, as: Time, format: { from: :time }
ruby
time? :premiered_at
ruby
attribute :premiered_at, from: [String, NilClass], as: [Time, NilClass], format: { from: :time }, required: false
datetime
ruby
datetime! :premiered_at
ruby
attribute :premiered_at, from: String, as: DateTime, format: { from: :datetime }
ruby
datetime? :premiered_at
ruby
attribute :premiered_at, from: [String, NilClass], as: [DateTime, NilClass], format: { from: :datetime }, required: false