Class: RubyJard::Decorators::RailsDecorator
- Inherits:
-
Object
- Object
- RubyJard::Decorators::RailsDecorator
- Defined in:
- lib/ruby_jard/decorators/rails_decorator.rb
Overview
A collection of rails-specific decorators. Why? Because Rails is magic, and it is like stepping on a minefield. Rails objects can trigger side-effects (like calling database queries, or even API queries). And from the end-user perspective, Rails’ internal variables are useless. They care more about database attributes, which requires some extra steps to display if I don’t want to use ‘#inspect`.
Defined Under Namespace
Classes: ActiveRecordBaseDecorator, ActiveRecordRelationDecorator
Instance Method Summary collapse
- #decorate_multiline(variable, first_line_limit:, lines:, line_limit:, depth: 0) ⇒ Object
- #decorate_singleline(variable, line_limit:, depth: 0) ⇒ Object
-
#initialize(generic_decorator) ⇒ RailsDecorator
constructor
A new instance of RailsDecorator.
- #match?(variable) ⇒ Boolean
Constructor Details
#initialize(generic_decorator) ⇒ RailsDecorator
Returns a new instance of RailsDecorator.
157 158 159 160 161 162 163 |
# File 'lib/ruby_jard/decorators/rails_decorator.rb', line 157 def initialize(generic_decorator) @generic_decorator = generic_decorator @sub_decorators = [ @active_record_base_decorator = ActiveRecordBaseDecorator.new(generic_decorator), @active_record_relation_decorator = ActiveRecordRelationDecorator.new(generic_decorator) ] end |
Instance Method Details
#decorate_multiline(variable, first_line_limit:, lines:, line_limit:, depth: 0) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/ruby_jard/decorators/rails_decorator.rb', line 183 def decorate_multiline(variable, first_line_limit:, lines:, line_limit:, depth: 0) @sub_decorators.each do |sub_decorator| next unless sub_decorator.match?(variable) return sub_decorator.decorate_multiline( variable, first_line_limit: first_line_limit, lines: lines, line_limit: line_limit, depth: depth ) end nil end |
#decorate_singleline(variable, line_limit:, depth: 0) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/ruby_jard/decorators/rails_decorator.rb', line 171 def decorate_singleline(variable, line_limit:, depth: 0) @sub_decorators.each do |sub_decorator| next unless sub_decorator.match?(variable) return sub_decorator.decorate_singleline( variable, line_limit: line_limit, depth: depth ) end nil end |
#match?(variable) ⇒ Boolean
165 166 167 168 169 |
# File 'lib/ruby_jard/decorators/rails_decorator.rb', line 165 def match?(variable) @sub_decorators.any? { |sub_decorator| sub_decorator.match?(variable) } rescue StandardError false end |