pushtype / push_type

PushType is a modern, open source content management system for Ruby on Rails.
http://www.pushtype.org
Other
290 stars 32 forks source link

enable ActiveRecord::Dirty API for fields #30

Closed kirillian closed 7 years ago

kirillian commented 7 years ago

This change enables the ActiveModel::Dirty syntax that is to be expected for native ActiveRecord classes:

class Foo < PushType::Node
  field :bar
end

foo = Foo.new
foo.bar = "baz"
foo.bar_changed? #=> true

I was recently motivated by a rather complicated validation I needed recently where I needed to verify an audio file and wanted conditional validation and quickly realized that I didn't have it, but knew it was easy to piggyback onto Rails' built-in features:

field :audio_recording_url, :string
before_validation :inspect_metadata, :if => :audio_recording_url_changed?

def inspect_metadata
  # perform metadata inspection
end
aaronrussell commented 7 years ago

Awesome, thanks for this 👍