Codeminer42/cm42-central

View on GitHub
config/initializers/attachinary.rb

Summary

Maintainability
A
0 mins
Test Coverage
require "attachinary/orm/active_record"

module Attachinary
  module FileMixin
    def as_json(options = {})
      super(only: [:id, :public_id, :format, :version, :resource_type], methods: [:path])
    end

    def to_csv
      attributes.except("id", "attachinariable_id", "created_at", "updated_at").to_json
    end
  end

  module ViewHelpersExtension
    def attachinary_file_field_options(model, relation, options={})
      options = super(model, relation, options)
      options[:html][:data][:attachinary][:files].map!(&:attributes)
      options
    end
  end

  module ViewHelpers
    prepend ViewHelpersExtension
  end
end