Class: Hocon::Impl::Parseable::ParseableString

Inherits:
Hocon::Impl::Parseable show all
Defined in:
lib/hocon/impl/parseable.rb

Overview

NOTE: skipping ‘ParseableReader` until we know we need it (probably should

have done that with `ParseableNotFound`)

Constant Summary

Constants inherited from Hocon::Impl::Parseable

MAX_INCLUDE_DEPTH

Instance Method Summary collapse

Methods inherited from Hocon::Impl::Parseable

#content_type, #fixup_options, force_parsed_to_object, #guess_syntax, #include_context, new_file, new_not_found, new_resources, new_string, #options, #origin, #parse, #parse_config_document, #parse_document, #parse_document_from_origin, #parse_value, #parse_value_from_origin, #post_construct, #raw_parse_document, #raw_parse_document_from_io, #raw_parse_value, #raw_parse_value_from_io, #reader, relative_to, #relative_to, syntax_from_extension, trace

Methods included from ConfigParseable

#options, #origin, #parse

Constructor Details

#initialize(string, options) ⇒ ParseableString

Returns a new instance of ParseableString.



356
357
358
359
360
# File 'lib/hocon/impl/parseable.rb', line 356

def initialize(string, options)
  super()
  @input = string
  post_construct(options)
end

Instance Method Details

#create_originObject



381
382
383
# File 'lib/hocon/impl/parseable.rb', line 381

def create_origin
  Hocon::Impl::SimpleConfigOrigin.new_simple("String")
end

#custom_readerObject



362
363
364
365
366
367
368
369
# File 'lib/hocon/impl/parseable.rb', line 362

def custom_reader
  if Hocon::Impl::ConfigImpl.trace_loads_enabled
    self.class.trace("Loading config from a String: #{@input}")
  end
  # we return self here, which will cause `open` to be called on us, so
  # we can provide an implementation of that.
  self
end

#openObject



371
372
373
374
375
376
377
378
379
# File 'lib/hocon/impl/parseable.rb', line 371

def open
  if block_given?
    StringIO.open(@input) do |f|
      yield f
    end
  else
    StringIO.open(@input)
  end
end

#to_sObject



385
386
387
# File 'lib/hocon/impl/parseable.rb', line 385

def to_s
  "#{self.class.name.split('::').last} (#{@input})"
end