Class: ViewModels::Extensions::ModelReader::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/view_models/extensions/model_reader.rb

Overview

Bundles the model reader options and extracts the relevant structured data.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*attributes_and_options) ⇒ Options

Returns a new instance of Options.



38
39
40
# File 'lib/view_models/extensions/model_reader.rb', line 38

def initialize *attributes_and_options
  split attributes_and_options
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



36
37
38
# File 'lib/view_models/extensions/model_reader.rb', line 36

def attributes
  @attributes
end

#filtersObject (readonly)

Returns the value of attribute filters.



36
37
38
# File 'lib/view_models/extensions/model_reader.rb', line 36

def filters
  @filters
end

Instance Method Details

#split(options) ⇒ Object

Extract filter_through options from the options hash if there are any.

Parameters:

  • options (Hash)

    the options to split



45
46
47
48
49
50
51
52
# File 'lib/view_models/extensions/model_reader.rb', line 45

def split options
  @filters = if options.last.kind_of?(Hash)
    [*(options.pop[:filter_through])].reverse
  else
    []
  end
  @attributes = options
end

#to_aArray

Render the options to an array

Returns:

  • (Array)

    The attributes and the filters in this order



57
58
59
# File 'lib/view_models/extensions/model_reader.rb', line 57

def to_a
  [attributes, filters]
end