class Adalog::ActiveRecordRepo
Attributes
base_relation[R]
record_class[R]
Public Class Methods
new(record_class, **repo_options)
click to toggle source
# File lib/adalog/active_record_repo.rb, line 6 def initialize(record_class, **repo_options) @record_class = record_class @base_relation = determine_base_relation(repo_options) end
Public Instance Methods
all()
click to toggle source
# File lib/adalog/active_record_repo.rb, line 42 def all record_class.all.to_a end
fetch(**options)
click to toggle source
# File lib/adalog/active_record_repo.rb, line 12 def fetch(**options) where_options = options.fetch(:where, {}) order_options = options.fetch(:order, :none) relation = relation_from_options(where_options, order_options) if options[:first] relation.first(options[:first]) elsif options[:last] relation.last(options[:last]) else relation.to_a end end
insert(attr_hash = {}, **attr_args)
click to toggle source
# File lib/adalog/active_record_repo.rb, line 26 def insert(attr_hash = {}, **attr_args) attrs = attr_hash.merge(attr_args) record = record_class.new(**attrs) if record.valid? if record.save [:ok, record] else wtf = "Unknown Non-validation error in call to #{record_class}#save" [:error, [wtf]] end else [:error, record.errors.full_messages] end end