class GettextSimpleRails::ModelInspector

Attributes

clazz[R]

Public Class Methods

model_classes() { |model_inspector| ... } click to toggle source
# File lib/gettext_simple_rails/model_inspector.rb, line 2
def self.model_classes
  clazzes = []
  ::Rails.application.eager_load!
  
  ::Object.constants.each do |clazz|
    clazz = clazz.to_s.constantize
    next unless clazz.class == Class
    next unless clazz < ActiveRecord::Base
    yield ::GettextSimpleRails::ModelInspector.new(clazz)
  end
end
new(clazz) click to toggle source
# File lib/gettext_simple_rails/model_inspector.rb, line 16
def initialize(clazz)
  @clazz = clazz
end

Public Instance Methods

attributes() { |attribute| ... } click to toggle source
# File lib/gettext_simple_rails/model_inspector.rb, line 20
def attributes
  @clazz.attribute_names.each do |attribute_name|
    yield ::GettextSimpleRails::ModelInspector::Attribute.new(self, attribute_name)
  end
end
gettext_key() click to toggle source
# File lib/gettext_simple_rails/model_inspector.rb, line 37
def gettext_key
  return "models.name.#{snake_name}"
end
gettext_key_one() click to toggle source
# File lib/gettext_simple_rails/model_inspector.rb, line 41
def gettext_key_one
  return "#{gettext_key}.one"
end
gettext_key_other() click to toggle source
# File lib/gettext_simple_rails/model_inspector.rb, line 45
def gettext_key_other
  return "#{gettext_key}.other"
end
paperclip_attachments() { |name| ... } click to toggle source
# File lib/gettext_simple_rails/model_inspector.rb, line 26
def paperclip_attachments
  return [] unless ::Kernel.const_defined?("Paperclip")
  Paperclip::AttachmentRegistry.names_for(@clazz).each do |name|
    yield(name)
  end
end
relationship_gettext_key(name) click to toggle source
# File lib/gettext_simple_rails/model_inspector.rb, line 56
def relationship_gettext_key(name)
  return "models.attributes.#{snake_name}.#{name}"
end
relationships() { |key, reflection| ... } click to toggle source

TODO: Maybe this should yield a ModelInspector::Relationship instead?

# File lib/gettext_simple_rails/model_inspector.rb, line 50
def relationships
  @clazz.reflections.each do |key, reflection|
    yield key, reflection
  end
end
snake_name() click to toggle source
# File lib/gettext_simple_rails/model_inspector.rb, line 33
def snake_name
  return ::StringCases.camel_to_snake(clazz.name)
end