module Fides

Constants

SUPPORTED_ADAPTERS
VERSION

Public Instance Methods

add_polymorphic_triggers(opts) click to toggle source
# File lib/fides.rb, line 17
def add_polymorphic_triggers(opts)
  raise ArgumentError, "missing :associated_models from options hash" if !opts.has_key?(:associated_models) 
  raise ArgumentError, "missing :polymorphic_model from options hash" if !opts.has_key?(:polymorphic_model)

  associated_models = opts[:associated_models]
  polymorphic_model = opts[:polymorphic_model]
  interface = opts.has_key?(:interface_name) ? opts[:interface_name] : interface_name(polymorphic_model)

  execution_statements = get_sql_generator_class.executable_add_statements(interface, associated_models, polymorphic_model)
  execution_statements.each { |statement| execute statement }
end
remove_polymorphic_triggers(opts) click to toggle source
# File lib/fides.rb, line 29
def remove_polymorphic_triggers(opts)
  raise ArgumentError, "missing :polymorphic_model from options hash" if !opts.has_key?(:polymorphic_model)
  
  polymorphic_model = opts[:polymorphic_model]
  interface = opts.has_key?(:interface_name) ? opts[:interface_name] : interface_name(polymorphic_model)

  execution_statements = get_sql_generator_class.executable_remove_statements(interface)
  execution_statements.each { |statement| execute statement }
end

Private Instance Methods

get_sql_generator_class() click to toggle source
# File lib/fides.rb, line 41
def get_sql_generator_class
  db_adapter = ActiveRecord::Base.configurations[Rails.env]['adapter']
  raise DatabaseAdapterError.new(db_adapter) unless SUPPORTED_ADAPTERS.include?(db_adapter)
  return "Fides::#{db_adapter.capitalize}Writer".constantize
end
interface_name(model_name) click to toggle source
# File lib/fides.rb, line 47
def interface_name(model_name)
  model_name.constantize.reflect_on_all_associations.select { |r| r if r.options[:polymorphic] }.first.name
end