Sha256: 8d2e4282a09cb625f464ca7cbc2eaedae6a34edb377058ca7bae9258b06d8590

Contents?: true

Size: 783 Bytes

Versions: 6

Compression:

Stored size: 783 Bytes

Contents

# frozen_string_literal: true

module LedgerSync
  module Domains
    class Operation
      class Resource
        include LedgerSync::Domains::Operation::Mixin

        def resource_class
          @resource_class ||= inferred_resource_class
        end

        def validation_error_message
          errors.messages.map do |e|
            "#{e.path.first.to_s.gsub('_', ' ').capitalize} #{e.text}"
          end.to_sentence
        end

        private

        def inferred_resource_class
          name = self.class.to_s.split('::')
          name.pop # remove serializer/operation class from name
          resource = name.pop.singularize # pluralized resource module name

          self.class.const_get((name + [resource]).join('::'))
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ledger_sync-domains-1.2.1 lib/ledger_sync/domains/operation/resource.rb
ledger_sync-domains-1.2.0 lib/ledger_sync/domains/operation/resource.rb
ledger_sync-domains-1.1.4 lib/ledger_sync/domains/operation/resource.rb
ledger_sync-domains-1.1.3 lib/ledger_sync/domains/operation/resource.rb
ledger_sync-domains-1.1.1 lib/ledger_sync/domains/operation/resource.rb
ledger_sync-domains-1.1.0 lib/ledger_sync/domains/operation/resource.rb