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.
16 17 18 |
# File 'lib/gettext_simple_rails/model_inspector.rb', line 16 def initialize(clazz) @clazz = clazz end |
Instance Attribute Details
#clazz ⇒ Object (readonly)
Returns the value of attribute clazz.
14 15 16 |
# File 'lib/gettext_simple_rails/model_inspector.rb', line 14 def clazz @clazz end |
Class Method Details
.model_classes ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 |
# 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
20 21 22 23 24 |
# 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 ⇒ Object
37 38 39 |
# File 'lib/gettext_simple_rails/model_inspector.rb', line 37 def gettext_key return "models.name.#{snake_name}" end |
#gettext_key_one ⇒ Object
41 42 43 |
# File 'lib/gettext_simple_rails/model_inspector.rb', line 41 def gettext_key_one return "#{gettext_key}.one" end |
#gettext_key_other ⇒ Object
45 46 47 |
# File 'lib/gettext_simple_rails/model_inspector.rb', line 45 def gettext_key_other return "#{gettext_key}.other" end |
#paperclip_attachments ⇒ Object
26 27 28 29 30 31 |
# File 'lib/gettext_simple_rails/model_inspector.rb', line 26 def return [] unless ::Kernel.const_defined?("Paperclip") Paperclip::AttachmentRegistry.names_for(@clazz).each do |name| yield(name) end end |
#relationship_gettext_key(name) ⇒ Object
56 57 58 |
# File 'lib/gettext_simple_rails/model_inspector.rb', line 56 def relationship_gettext_key(name) return "models.attributes.#{snake_name}.#{name}" end |
#relationships ⇒ Object
TODO: Maybe this should yield a ModelInspector::Relationship instead?
50 51 52 53 54 |
# 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 ⇒ Object
33 34 35 |
# File 'lib/gettext_simple_rails/model_inspector.rb', line 33 def snake_name return ::StringCases.camel_to_snake(clazz.name) end |