Class: ActiveModel::Serializer::Fieldset

Inherits:
Object
  • Object
show all
Defined in:
lib/active_model/serializer/fieldset.rb

Instance Method Summary collapse

Constructor Details

#initialize(fields, root = nil) ⇒ Fieldset

Returns a new instance of Fieldset.



4
5
6
7
# File 'lib/active_model/serializer/fieldset.rb', line 4

def initialize(fields, root = nil)
  @root       = root
  @raw_fields = fields
end

Instance Method Details

#fieldsObject



9
10
11
# File 'lib/active_model/serializer/fieldset.rb', line 9

def fields
  @fields ||= parsed_fields
end

#fields_for(serializer) ⇒ Object



13
14
15
16
# File 'lib/active_model/serializer/fieldset.rb', line 13

def fields_for(serializer)
  key = serializer.json_key
  fields[key.to_sym] || fields[key.pluralize.to_sym]
end