Class: GettextSimpleRails::ModelInspector
- Inherits:
-
Object
- Object
- GettextSimpleRails::ModelInspector
- Defined in:
- lib/gettext_simple_rails/model_inspector.rb
Defined Under Namespace
Classes: Attribute
Instance Attribute Summary collapse
-
#clazz ⇒ Object
readonly
Returns the value of attribute clazz.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
- #gettext_key ⇒ Object
- #gettext_key_one ⇒ Object
- #gettext_key_other ⇒ Object
-
#initialize(clazz) ⇒ ModelInspector
constructor
A new instance of ModelInspector.
- #paperclip_attachments ⇒ Object
- #relationship_gettext_key(name) ⇒ Object
-
#relationships ⇒ Object
TODO: Maybe this should yield a ModelInspector::Relationship instead?.
- #snake_name ⇒ Object
Constructor Details
#initialize(clazz) ⇒ ModelInspector
Returns a new instance of ModelInspector.
17 18 19 |
# File 'lib/gettext_simple_rails/model_inspector.rb', line 17 def initialize(clazz) @clazz = clazz end |
Instance Attribute Details
#clazz ⇒ Object (readonly)
Returns the value of attribute clazz.
15 16 17 |
# File 'lib/gettext_simple_rails/model_inspector.rb', line 15 def clazz @clazz end |
Class Method Details
.model_classes ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 |
# 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 |
Instance Method Details
#attributes ⇒ Object
21 22 23 24 25 |
# File 'lib/gettext_simple_rails/model_inspector.rb', line 21 def attributes @clazz.attribute_names.each do |attribute_name| yield ::GettextSimpleRails::ModelInspector::Attribute.new(self, attribute_name) end end |
#gettext_key ⇒ Object
41 42 43 |
# File 'lib/gettext_simple_rails/model_inspector.rb', line 41 def gettext_key return "models.name.#{snake_name}" end |
#gettext_key_one ⇒ Object
45 46 47 |
# File 'lib/gettext_simple_rails/model_inspector.rb', line 45 def gettext_key_one return "#{gettext_key}.one" end |
#gettext_key_other ⇒ Object
49 50 51 |
# File 'lib/gettext_simple_rails/model_inspector.rb', line 49 def gettext_key_other return "#{gettext_key}.other" end |
#paperclip_attachments ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/gettext_simple_rails/model_inspector.rb', line 27 def if !::Kernel.const_defined?("Paperclip") return [] end Paperclip::AttachmentRegistry.names_for(@clazz).each do |name| yield(name) end end |
#relationship_gettext_key(name) ⇒ Object
60 61 62 |
# File 'lib/gettext_simple_rails/model_inspector.rb', line 60 def relationship_gettext_key(name) return "models.attributes.#{snake_name}.#{name}" end |
#relationships ⇒ Object
TODO: Maybe this should yield a ModelInspector::Relationship instead?
54 55 56 57 58 |
# File 'lib/gettext_simple_rails/model_inspector.rb', line 54 def relationships @clazz.reflections.each do |key, reflection| yield key, reflection end end |
#snake_name ⇒ Object
37 38 39 |
# File 'lib/gettext_simple_rails/model_inspector.rb', line 37 def snake_name return ::StringCases.camel_to_snake(clazz.name) end |