Module: Komagire::ActiveRecordExtension

Defined in:
lib/komagire/active_record_extension.rb

Instance Method Summary collapse

Instance Method Details

#composed_of_komagire_id_list(part_id, attribute, content_class_name, options = {}) ⇒ Object

Options Hash (options):

  • :komagire (Hash) — default: {}

    options that are passed to the Komagire::KeyList



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/komagire/active_record_extension.rb', line 32

def composed_of_komagire_id_list(part_id, attribute, content_class_name, options={})
  komagire_options = options.delete(:komagire) || {}
  options = {
    class_name: 'Komagire::IdList',
    mapping: [[attribute.to_s, 'csids']],
    allow_nil: false,
    constructor: lambda { |cskeys|
      Komagire::IdList.new(content_class_name, cskeys, komagire_options)
    },
    converter: lambda { |value|
      Komagire::IdList.new(content_class_name, value, komagire_options)
    },
  }.merge(options)
  composed_of part_id, options
end

#composed_of_komagire_key_list(part_id, attribute, content_class_name, content_class_attribute, options = {}) ⇒ Object

Options Hash (options):

  • :komagire (Hash) — default: {}

    options that are passed to the Komagire::KeyList



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/komagire/active_record_extension.rb', line 11

def composed_of_komagire_key_list(part_id, attribute, content_class_name, content_class_attribute, options={})
  komagire_options = options.delete(:komagire) || {}
  options = {
    class_name: 'Komagire::KeyList',
    mapping: [[attribute.to_s, 'cskeys']],
    allow_nil: false,
    constructor: lambda { |cskeys|
      Komagire::KeyList.new(content_class_name, content_class_attribute, cskeys, komagire_options)
    },
    converter: lambda { |value|
      Komagire::KeyList.new(content_class_name, content_class_attribute, value, komagire_options)
    },
  }.merge(options)
  composed_of part_id, options
end