Sha256: 8fdbd1b2f4a14b4df9c81bee0b749fbe60a60381880d4041748da1f122d27664

Contents?: true

Size: 1.09 KB

Versions: 9

Compression:

Stored size: 1.09 KB

Contents

class GettextSimpleRails::Translators::ActiveRecordAttributesTranslator
  def detected?
    ::Kernel.const_defined?("ActiveRecord")
  end
  
  def translations
    @translations_hash = {
      "activerecord" => {
        "attributes" => {},
        "models" => {}
      }
    }
    attributes_hash = @translations_hash["activerecord"]["attributes"]
    models_hash = @translations_hash["activerecord"]["models"]
    
    GettextSimpleRails::ModelInspector.model_classes do |inspector|
      lower_class_name = StringCases.camel_to_snake(inspector.clazz.name)
      models_hash[lower_class_name] = {
        "one" => inspector.clazz.name,
        "other" => inspector.clazz.name
      }
      attributes_hash[lower_class_name] = {} unless attributes_hash.key?(lower_class_name)
      attributes = attributes_hash[lower_class_name]
      
      inspector.attributes do |attribute|
        attributes[attribute.name.to_s] = attribute.name.to_s
      end
      
      inspector.relationships do |name, reflection|
        attributes[name.to_s] = name.to_s
      end
    end
    
    return @translations_hash
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gettext_simple_rails-0.0.19 lib/gettext_simple_rails/translators/active_record_attributes_translator.rb
gettext_simple_rails-0.0.17 lib/gettext_simple_rails/translators/active_record_attributes_translator.rb
gettext_simple_rails-0.0.16 lib/gettext_simple_rails/translators/active_record_attributes_translator.rb
gettext_simple_rails-0.0.15 lib/gettext_simple_rails/translators/active_record_attributes_translator.rb
gettext_simple_rails-0.0.14 lib/gettext_simple_rails/translators/active_record_attributes_translator.rb
gettext_simple_rails-0.0.13 lib/gettext_simple_rails/translators/active_record_attributes_translator.rb
gettext_simple_rails-0.0.12 lib/gettext_simple_rails/translators/active_record_attributes_translator.rb
gettext_simple_rails-0.0.11 lib/gettext_simple_rails/translators/active_record_attributes_translator.rb
gettext_simple_rails-0.0.10 lib/gettext_simple_rails/translators/active_record_attributes_translator.rb