class Restforce::Concerns::Picklists::PicklistValues

Attributes

fields[R]

Public Class Methods

new(fields, field, options = {}) click to toggle source
Calls superclass method
# File lib/restforce/concerns/picklists.rb, line 32
def initialize(fields, field, options = {})
  @fields = fields
  @field = field
  @valid_for = options.delete(:valid_for)
  raise "#{field} is not a dependent picklist" if @valid_for && !dependent?

  super(picklist_values)
end

Private Instance Methods

controlling_field() click to toggle source
# File lib/restforce/concerns/picklists.rb, line 73
def controlling_field
  @_controlling_field ||= fields.find { |f| f['name'] == field['controllerName'] }
end
controlling_picklist() click to toggle source
# File lib/restforce/concerns/picklists.rb, line 62
def controlling_picklist
  @_controlling_picklist ||= controlling_field['picklistValues'].
                             find do |picklist_entry|
                               picklist_entry['value'] == @valid_for
                             end
end
dependent?() click to toggle source

Returns true of the given field is dependent on another field.

# File lib/restforce/concerns/picklists.rb, line 54
def dependent?
  !!field['dependentPicklist']
end
field() click to toggle source
# File lib/restforce/concerns/picklists.rb, line 77
def field
  @_field ||= fields.find { |f| f['name'] == @field }
end
index() click to toggle source
# File lib/restforce/concerns/picklists.rb, line 69
def index
  @_index ||= controlling_field['picklistValues'].index(controlling_picklist)
end
picklist_values() click to toggle source
# File lib/restforce/concerns/picklists.rb, line 45
def picklist_values
  if valid_for?
    field['picklistValues'].select { |picklist_entry| valid? picklist_entry }
  else
    field['picklistValues']
  end
end
valid?(picklist_entry) click to toggle source

Returns true if the picklist entry is valid for the controlling picklist.

See www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_des cribesobjects_describesobjectresult.htm

# File lib/restforce/concerns/picklists.rb, line 85
def valid?(picklist_entry)
  valid_for = picklist_entry['validFor'].ljust(16, 'A').unpack1('m').
              unpack('C*')
  (valid_for[index >> 3] & (0x80 >> (index % 8))).positive?
end
valid_for?() click to toggle source
# File lib/restforce/concerns/picklists.rb, line 58
def valid_for?
  !!@valid_for
end