Class: ActiveModel::Exporter
- Inherits:
-
Object
- Object
- ActiveModel::Exporter
- Defined in:
- lib/active_model/exporter.rb,
lib/active_model/exporter/types.rb,
lib/active_model/exporter/version.rb
Constant Summary collapse
- TYPES =
%i[csv xls].freeze
- VERSION =
"0.7.1"
Class Attribute Summary collapse
-
._attributes ⇒ Object
Returns the value of attribute _attributes.
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
- #filter(attrs) ⇒ Object
-
#initialize(object, options = {}) ⇒ Exporter
constructor
A new instance of Exporter.
- #values ⇒ Object
Constructor Details
#initialize(object, options = {}) ⇒ Exporter
Returns a new instance of Exporter.
24 25 26 27 |
# File 'lib/active_model/exporter.rb', line 24 def initialize(object, = {}) @object = object @scope = [:scope] end |
Class Attribute Details
._attributes ⇒ Object
Returns the value of attribute _attributes.
6 7 8 |
# File 'lib/active_model/exporter.rb', line 6 def _attributes @_attributes end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
22 23 24 |
# File 'lib/active_model/exporter.rb', line 22 def object @object end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
22 23 24 |
# File 'lib/active_model/exporter.rb', line 22 def scope @scope end |
Class Method Details
.attributes(*attrs) ⇒ Object
13 14 15 |
# File 'lib/active_model/exporter.rb', line 13 def attributes(*attrs) @_attributes.concat(attrs) end |
.exporter_for(resource) ⇒ Object
17 18 19 |
# File 'lib/active_model/exporter.rb', line 17 def exporter_for(resource) "#{resource.class.name}Exporter".safe_constantize end |
.inherited(base) ⇒ Object
8 9 10 11 |
# File 'lib/active_model/exporter.rb', line 8 def inherited(base) super base._attributes = (_attributes || []).dup end |
Instance Method Details
#attributes ⇒ Object
43 44 45 |
# File 'lib/active_model/exporter.rb', line 43 def attributes self.class._attributes.dup end |
#filter(attrs) ⇒ Object
39 40 41 |
# File 'lib/active_model/exporter.rb', line 39 def filter(attrs) attrs end |
#values ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/active_model/exporter.rb', line 29 def values attrs = filter(attributes) attributes.map do |attr| if attrs.include?(attr) next send(attr) if respond_to?(attr) object.send(attr) end end end |