Module: Sinja::Sequel::Core
- Extended by:
- Forwardable
- Defined in:
- lib/sinja/sequel/core.rb
Class Method Summary collapse
Instance Method Summary collapse
- #after_create ⇒ Object
- #serialize_linkage(**options) ⇒ Object
- #serialize_model(**options) ⇒ Object
- #sort(collection, fields) ⇒ Object
- #validate! ⇒ Object
Class Method Details
.included(_) ⇒ Object
48 49 50 |
# File 'lib/sinja/sequel/core.rb', line 48 def self.included(_) abort "You must `prepend' Sinja::Sequel::Core, not `include' it!" end |
.prepended(base) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sinja/sequel/core.rb', line 13 def self.prepended(base) base.sinja.configure do |c| c.conflict_exceptions << ::Sequel::ConstraintViolation c.not_found_exceptions << ::Sequel::NoMatchingRow c.validation_exceptions << ::Sequel::ValidationFailed c.validation_formatter = proc do |e| e.errors.keys.each do |column| if assocs = e.model.class.autoreloading_associations[column] # copy errors attached to a FK column to the relevant association assocs.each do |assoc| e.errors[assoc] = e.errors[column] end e.errors.delete(column) end end typeof = e.model.class.associations .map { |k| [k, :relationships] }.to_h .tap { |h| h.default = :attributes } e.errors.flat_map do |ee| next [[nil, ee]] if ee.is_a?(::Sequel::LiteralString) key, = *ee Array().map do || [key, "#{key} #{}", typeof[key]] end end end end base.prepend(Pagination) if ::Sequel::Model.db.dataset.respond_to?(:paginate) end |
Instance Method Details
#after_create ⇒ Object
68 69 70 71 |
# File 'lib/sinja/sequel/core.rb', line 68 def after_create resource.save(:validate=>false) resource.pk end |
#serialize_linkage(**options) ⇒ Object
73 74 75 76 |
# File 'lib/sinja/sequel/core.rb', line 73 def serialize_linkage(*, **) [:skip_collection_check] = true super end |
#serialize_model(**options) ⇒ Object
78 79 80 81 |
# File 'lib/sinja/sequel/core.rb', line 78 def serialize_model(*, **) [:skip_collection_check] = true super end |
#sort(collection, fields) ⇒ Object
58 59 60 |
# File 'lib/sinja/sequel/core.rb', line 58 def sort(collection, fields) collection.order(*fields.map { |k, v| ::Sequel.send(v, k) }) end |
#validate! ⇒ Object
64 65 66 |
# File 'lib/sinja/sequel/core.rb', line 64 def validate! raise ::Sequel::ValidationFailed, resource unless resource.valid? end |