Class: SfCli::Sf::Sobject::Schema::Fields

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/sf_cli/sf/sobject/schema.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ Fields

Returns a new instance of Fields.



253
254
255
# File 'lib/sf_cli/sf/sobject/schema.rb', line 253

def initialize(schema)
  @fields = schema['fields'].map{|h| Field.new(**h)}
end

Instance Method Details

#each(&block) ⇒ Object



257
258
259
# File 'lib/sf_cli/sf/sobject/schema.rb', line 257

def each(&block)
  fields.each &block
end

#find_by(name: nil, label: nil) ⇒ Object



265
266
267
268
269
270
271
272
273
274
275
# File 'lib/sf_cli/sf/sobject/schema.rb', line 265

def find_by(name: nil, label: nil)
  return nil if name.nil? && label.nil?

  attr_name = name.nil? ? :label : :name
  val       = name || label

  find do |field|
    attr_val = field.__send__(attr_name.to_sym)
    attr_val == val.to_s
  end
end

#name_and_labelsObject



277
278
279
# File 'lib/sf_cli/sf/sobject/schema.rb', line 277

def name_and_labels
  map{|field| [field.name, field.label]}
end

#to_aObject



261
262
263
# File 'lib/sf_cli/sf/sobject/schema.rb', line 261

def to_a
  fields
end