Sha256: cacbf1a22956ba33134504415107020786ef932dc7953858965cbc4d47ce4560

Contents?: true

Size: 988 Bytes

Versions: 12

Compression:

Stored size: 988 Bytes

Contents

module Maestrano::Connector::Rails
  module EntityHelper
    def self.snake_name(entity)
      class_name = entity.class.name.underscore.split('/').last
      if entity.is_a?(Maestrano::Connector::Rails::SubEntityBase)
        name = ''
        Entities.constants&.each do |c|
          klass = Entities.const_get(c)
          next unless klass.respond_to?(:formatted_external_entities_names)

          external_class_names = klass.formatted_external_entities_names.values
          break name = c if camel_case_format(external_class_names).include?(class_name.camelize)

          connec_class_names = klass.formatted_connec_entities_names.values
          break name = c if camel_case_format(connec_class_names).include?(class_name.camelize)
        end
        name.to_s.underscore.to_sym
      else
        class_name.to_sym
      end
    end

    def self.camel_case_format(array_of_class_names)
      array_of_class_names.map { |name| name.titleize.delete(' ') }
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
maestrano-connector-rails-2.3.6 app/helpers/maestrano/connector/rails/entity_helper.rb
maestrano-connector-rails-2.3.5 app/helpers/maestrano/connector/rails/entity_helper.rb
maestrano-connector-rails-2.3.4 app/helpers/maestrano/connector/rails/entity_helper.rb
maestrano-connector-rails-2.3.3 app/helpers/maestrano/connector/rails/entity_helper.rb
maestrano-connector-rails-2.3.2 app/helpers/maestrano/connector/rails/entity_helper.rb
maestrano-connector-rails-2.3.1 app/helpers/maestrano/connector/rails/entity_helper.rb
maestrano-connector-rails-2.3.0 app/helpers/maestrano/connector/rails/entity_helper.rb
maestrano-connector-rails-2.2.1 app/helpers/maestrano/connector/rails/entity_helper.rb
maestrano-connector-rails-2.2.0 app/helpers/maestrano/connector/rails/entity_helper.rb
maestrano-connector-rails-2.1.3 app/helpers/maestrano/connector/rails/entity_helper.rb
maestrano-connector-rails-2.1.2 app/helpers/maestrano/connector/rails/entity_helper.rb
maestrano-connector-rails-2.1.1 app/helpers/maestrano/connector/rails/entity_helper.rb