Class: RecordFormatter::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/record_formatter/base.rb

Constant Summary collapse

DEFAULT_SCOPE =
:all
VALID_OPTIONS =
%i(scope)

Instance Method Summary collapse

Constructor Details

#initialize(klass, options = {}) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
# File 'lib/record_formatter/base.rb', line 10

def initialize klass, options={}
  @klass = klass
  @models = {}
  @options = options.slice!(VALID_OPTIONS)
end

Instance Method Details

#columns(*attributes) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/record_formatter/base.rb', line 16

def columns *attributes
  defaults = attributes.extract_options!

  attributes.each do |name|
    model.add_column name, defaults
  end
end

#deployable_recordsObject



24
25
26
# File 'lib/record_formatter/base.rb', line 24

def deployable_records
  @klass.select(columns_for_select).send(defined_scope)
end