class ActiveForce::ModelGenerator

Constants

Attribute

Public Instance Methods

create_model_file() click to toggle source
# File lib/generators/active_force/model/model_generator.rb, line 7
def create_model_file
  @table_name = file_name.capitalize
  @class_name = @table_name.gsub '__c', ''
  template "model.rb.erb", "app/models/#{@class_name.downcase}.rb" if table_exists?
end

Protected Instance Methods

attribute_line(attribute) click to toggle source
# File lib/generators/active_force/model/model_generator.rb, line 40
def attribute_line attribute
  "field :#{ attribute.field },#{ space_justify attribute.field }  from: '#{ attribute.column }'"
end
attributes() click to toggle source
# File lib/generators/active_force/model/model_generator.rb, line 17
def attributes 
  @attributes ||= sfdc_columns.map do |column|
    Attribute.new column_to_field(column), column
  end
  @attributes - [:id]
end
column_to_field(column) click to toggle source
# File lib/generators/active_force/model/model_generator.rb, line 36
def column_to_field column
  column.underscore.gsub("__c", "").to_sym
end
sfdc_columns() click to toggle source
# File lib/generators/active_force/model/model_generator.rb, line 24
def sfdc_columns
  @columns ||= ActiveForce::SObject.sfdc_client.describe(@table_name).fields.map do |field|
    field.name
  end
end
space_justify(field_name) click to toggle source
# File lib/generators/active_force/model/model_generator.rb, line 44
def space_justify field_name
  longest_field = attributes.map { |attr| attr.field.length } .max
  justify_count = longest_field - field_name.length
  " " * justify_count
end
table_exists?() click to toggle source
# File lib/generators/active_force/model/model_generator.rb, line 30
def table_exists?
  !! sfdc_columns
  rescue Faraday::Error::ResourceNotFound
    puts "The specified table name is not found. Be sure to append __c if it's custom"
end