Class: Komagire::KeyList

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/komagire/key_list.rb

Direct Known Subclasses

IdList

Defined Under Namespace

Classes: Converter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content_class_name, attribute, cskeys, options = {}) ⇒ KeyList

Returns a new instance of KeyList.

Parameters:

  • content_class_name (String)
  • attribute (Symbol)
  • cskeys (String)

    comma separated keys

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :delimiter (String) — default: Komagire::DEFAULT_DELIMITER


18
19
20
21
22
23
24
25
# File 'lib/komagire/key_list.rb', line 18

def initialize(content_class_name, attribute, cskeys, options = {})
  @content_class_name = content_class_name
  @attribute = attribute
  @delimiter = options[:delimiter] || Komagire::DEFAULT_DELIMITER
  @sort = options[:sort] || false
  @cskeys = _convert(cskeys)
  super(_find_by_cskeys)
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



11
12
13
# File 'lib/komagire/key_list.rb', line 11

def attribute
  @attribute
end

#content_class_nameObject (readonly)

Returns the value of attribute content_class_name.



11
12
13
# File 'lib/komagire/key_list.rb', line 11

def content_class_name
  @content_class_name
end

Instance Method Details

#cskeysString

comma separated keys

Returns:

  • (String)


30
31
32
33
# File 'lib/komagire/key_list.rb', line 30

def cskeys
  key_values = compact.map(&@attribute).uniq.tap {|values| values.sort! if @sort }
  ([''] + key_values + ['']).join(@delimiter)
end

#freezeObject



35
36
37
38
39
40
41
42
# File 'lib/komagire/key_list.rb', line 35

def freeze
  case __getobj__
  when ActiveRecord::Relation
    # avoid ActiveRecord::Relation is frozen
  else
    super
  end
end