Sha256: 254c12c2ca597500c80c8a14405207b8458a7d1f4937b138e094ee1e2f89ee9c

Contents?: true

Size: 1.68 KB

Versions: 5

Compression:

Stored size: 1.68 KB

Contents

=begin
  ActiveSalesforce
  Copyright 2006 Doug Chasman
 
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
 
     http://www.apache.org/licenses/LICENSE-2.0
 
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
=end

require 'rubygems'
require_gem 'rails', ">= 1.0.0"

require 'pp'


module ActiveSalesforce  
  class EntityDefinition
    attr_reader :name, :columns, :column_name_to_column, :api_name_to_column, :relationships, :key_prefix
    
    def initialize(connection, name, columns, relationships, custom, key_prefix)
      @connection = connection
      @name = name
      @columns = columns
      @relationships = relationships
      @custom = custom
      @key_prefix = key_prefix
      
      @column_name_to_column = {}          
      @columns.each { |column| @column_name_to_column[column.name] = column }
      
      @api_name_to_column = {}
      @columns.each { |column| @api_name_to_column[column.api_name] = column }
    end
    
    def custom?
      @custom
    end
    
    def api_name
      @custom ? name + "__c" : name
    end
    
    def layouts
      return @layouts if @layouts
      
      # Lazy load Layout information
      response = @connection.binding.describeLayout(:sObjectType => api_name)
      @layouts = @connection.get_result(response, :describeLayout)
    end
    
  end
  
end    

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activesalesforce-0.4.2 lib/entity_definition.rb
activesalesforce-0.3.9 lib/entity_definition.rb
activesalesforce-0.4.0 lib/entity_definition.rb
activesalesforce-0.4.3 lib/entity_definition.rb
activesalesforce-0.4.4 lib/entity_definition.rb