Module Picker
In: lib/picker.rb

インスタンスに対する respond_to? で正しいことが仮定されるメッセージ:

  • id
  • input_parameter

Methods

Public Instance methods

選択する最小単位を返す。 適切なキーがなければ false を返す。

[Source]

    # File lib/picker.rb, line 14
14:   def picked_atom
15:     return false unless picked_keys
16:     return picked_keys[0] if picked_keys.size == 1
17:     # the order of the following array is significant.
18:     %w|person organization company post group|.each do |k|
19:       return k if picked_keys.include?(k)
20:     end
21:     return "lump" # FIXME
22:   end

選択するキーたちを返す。 適切なキーでなければ false を返す。

[Source]

    # File lib/picker.rb, line 7
 7:   def picked_keys
 8:     return false if input_parameter.blank?
 9:     input_parameter.split(',')
10:   end

受け取ったオブジェクトから関連づいたオブジェクトの配列を返す。

[Source]

    # File lib/picker.rb, line 34
34:   def picked_references(x)
35:     return [x] if picked_keys.size == 1
36:     case picked_atom
37:     when "person"
38:       return picked_keys.map {|k| k == "person" ? x : x.__send__("preferred_#{k}")}
39:     when "organization", "post"
40:       return picked_keys.map {|k| k == picked_atom ? x : x.__send__(k)}
41:     else
42:       raise ArgumentError, "invalid picked atom: #{picked_atom}"
43:     end
44:   end

受け取ったハッシュからオブジェクトの配列を返す。

[Source]

    # File lib/picker.rb, line 25
25:   def picked_values(x)
26:     picked_keys.map do |k|
27:       id = x[k.to_sym]
28:       model_class = k.classify.constantize
29:       id.blank? ? model_class.new : model_class.find_by_id(id)
30:     end
31:   end

[Validate]