Module: AsJsonPresentable::ClassMethods
- Defined in:
- lib/as_json_presentable.rb
Instance Method Summary collapse
-
#define_json_presenter_class(klass) ⇒ Object
Allows the user to explicitly set the presenter class if the default naming convention isn’t desired.
-
#json_presenter_class ⇒ Object
Returns the presenter class if it has been explicitly set or can be implied through naming conventions, or returns nil if no presenter class exists.
Instance Method Details
#define_json_presenter_class(klass) ⇒ Object
Allows the user to explicitly set the presenter class if the default naming convention isn’t desired.
33 34 35 |
# File 'lib/as_json_presentable.rb', line 33 def define_json_presenter_class(klass) @json_presenter_class = klass end |
#json_presenter_class ⇒ Object
Returns the presenter class if it has been explicitly set or can be implied through naming conventions, or returns nil if no presenter class exists.
By default, the presenter class is inferred to be named after the model class, but with the suffix of “Presenter”.
e.g. If you have a model class called Foo, its presenter is assumed to be called FooPresenter
Alternatively, the presenter class can be explicitly defined with ::defined_json_presenter_class
50 51 52 53 54 55 |
# File 'lib/as_json_presentable.rb', line 50 def json_presenter_class return @json_presenter_class if defined?(@json_presenter_class) klass_name = "#{self.name}Presenter" @json_presenter_class = Module.const_get(klass_name) if Module.const_defined?(klass_name) end |