Class: NOSJ::RailsEncoder
- Inherits:
-
Object
- Object
- NOSJ::RailsEncoder
- Defined in:
- lib/nosj/rails.rb,
sig/nosj.rbs
Overview
Defined by require "nosj/rails", which also installs it as
ActiveSupport::JSON::Encoding.json_encoder.
Instance Attribute Summary collapse
-
#options ⇒ Hash[Symbol, untyped]
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #encode(value) ⇒ String
-
#initialize(options = nil) ⇒ RailsEncoder
constructor
A new instance of RailsEncoder.
Constructor Details
#initialize(options = nil) ⇒ RailsEncoder
Returns a new instance of RailsEncoder.
51 52 53 |
# File 'lib/nosj/rails.rb', line 51 def initialize( = nil) @options = || {} end |
Instance Attribute Details
#options ⇒ Hash[Symbol, untyped] (readonly)
Returns the value of attribute options.
49 50 51 |
# File 'lib/nosj/rails.rb', line 49 def @options end |
Instance Method Details
#encode(value) ⇒ String
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/nosj/rails.rb', line 55 def encode(value) value = value.as_json(@options.dup) unless @options.empty? if @options.fetch(:escape, true) escape_html = @options.fetch(:escape_html_entities) do ActiveSupport::JSON::Encoding.escape_html_entities_in_json end NOSJ.generate_rails_native(value, !!escape_html, escape_js_separators?) else NOSJ.generate_rails_native(value, false, false) end end |