Last active
October 5, 2016 21:59
-
-
Save flash-gordon/6fb8dfcb235149f377a51181555294cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module CommandPlugins | |
module ActiveRecordTimestamps | |
class HashWithTimestamps | |
def initialize(input) | |
@input = input | |
end | |
def [](*args) | |
tuple = @input[*args] | |
now = Time.zone.now | |
if tuple[:created_at] | |
tuple[:updated_at] = now | |
else | |
tuple[:created_at] = now | |
tuple[:updated_at] = now | |
end | |
tuple | |
end | |
end | |
def self.included(klass) | |
super | |
klass.input HashWithTimestamps.new(klass.input) | |
end | |
end | |
end | |
ROM.plugins do | |
adapter :sql do | |
register :timestamps, CommandPlugins::ActiveRecordTimestamps, type: :command | |
end | |
end | |
class CreateAccount < ROM::Commands::Create[:sql] | |
register_as :create | |
relation :accounts | |
result :one | |
use :timestamps | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment