Sha256: 9159a1cfa9c5bbbd275fee403d6e482946ad659ccf0e1c0bdf2eab177e5ae50e

Contents?: true

Size: 1.22 KB

Versions: 21

Compression:

Stored size: 1.22 KB

Contents

module Salesforce
  class Columns
    include Enumerable
    attr_accessor :by_name, :by_original_name, :table_name

    def initialize(table_name)
      self.table_name = table_name
      fields = Connection.fields(table_name)
      self.by_name          = {}
      self.by_original_name = {}
      fields.each do |field|
        column = Column.new(field)
        by_name[column.name] = column
        by_original_name[column.original_name] = column
      end
    end
    
    def each(&block)
      all.each(&block)
    end
    
    def all
      @all ||= by_name.values.flatten
    end
    
    def editable
      @editable ||= select(&:editable?)
    end
    
    def createable
      select(&:createable?)
    end
    
    def updateable
      select(&:updateable?)
    end
    
    def id_column
      find { |col| col.name.to_sym == :id }
    end
    
    def names
      map(&:name)
    end
    
    def soql_selector
      @soql_selector ||= by_original_name.keys.sort.join(',')
    end
    
    def ==(other)
      other && self.all.map(&:name) == other.all.map(&:name)
    end
    
    def find_by_name(name)
      column = by_name[name.to_s]
      raise ColumnNotFound.new(name, table_name) unless column
      column
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
activeforce-5.0.0 lib/salesforce/columns.rb
activeforce-1.10.5 lib/salesforce/columns.rb
activeforce-1.10.4 lib/salesforce/columns.rb
activeforce-4.0.0 lib/salesforce/columns.rb
activeforce-1.10.3 lib/salesforce/columns.rb
activeforce-3.1.0 lib/salesforce/columns.rb
activeforce-1.10.2 lib/salesforce/columns.rb
activeforce-3.0.0 lib/salesforce/columns.rb
activeforce-2.1.1 lib/salesforce/columns.rb
activeforce-1.10.1 lib/salesforce/columns.rb
activeforce-2.1.0 lib/salesforce/columns.rb
activeforce-1.10.0 lib/salesforce/columns.rb
activeforce-2.0.1 lib/salesforce/columns.rb
activeforce-2.0.0 lib/salesforce/columns.rb
activeforce-1.9.1 lib/salesforce/columns.rb
activeforce-1.9.0 lib/salesforce/columns.rb
activeforce-1.8.0 lib/salesforce/columns.rb
activeforce-1.7.1 lib/salesforce/columns.rb
activeforce-1.7.0 lib/salesforce/columns.rb
activeforce-1.6.0 lib/salesforce/columns.rb