Sha256: a14bf7225be21f5a333c2c132456c69a52cdddda9920b152c348e19de3bba4e8
Contents?: true
Size: 992 Bytes
Versions: 3
Compression:
Stored size: 992 Bytes
Contents
module ActiveModel class Exporter class << self attr_accessor :_attributes def inherited(base) base._attributes = (_attributes || []).dup end def attributes(*attrs) @_attributes.concat(attrs) attrs.each do |attr| define_method(attr) do object.send(attr) end unless method_defined?(attr) end end def exporter_for(resource) if resource.respond_to?(:to_ary) ArrayExporter else "#{resource.class.name}Exporter".safe_constantize end end end attr_accessor :object, :scope def initialize(object, options = {}) @object = object @scope = options[:scope] end def values attrs = filter(attributes) attributes.map { |attr| send(attr) if attrs.include?(attr) } end def filter(attrs) attrs end private def attributes self.class._attributes.dup end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
active_model_exporters-0.0.5 | lib/active_model/exporter.rb |
active_model_exporters-0.0.4 | lib/active_model/exporter.rb |
active_model_exporters-0.0.3 | lib/active_model/exporter.rb |