Class: Hocon::Impl::Parseable

Inherits:
Object
  • Object
show all
Defined in:
lib/hocon/impl/parseable.rb

Direct Known Subclasses

ParseableFile, ParseableString

Defined Under Namespace

Classes: ParseableFile, ParseableString

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.force_parsed_to_object(value) ⇒ Object



88
89
90
91
92
93
94
95
96
# File 'lib/hocon/impl/parseable.rb', line 88

def self.force_parsed_to_object(value)
  if value.is_a? Hocon::Impl::AbstractConfigObject
    value
  else
    raise Hocon::ConfigError::ConfigWrongTypeError.new(value.origin, "",
                                                       "object at file root",
                                                       value.value_type.name)
  end
end

.new_file(file_path, options) ⇒ Object



68
69
70
# File 'lib/hocon/impl/parseable.rb', line 68

def self.new_file(file_path, options)
  ParseableFile.new(file_path, options)
end

.new_string(string, options) ⇒ Object



72
73
74
# File 'lib/hocon/impl/parseable.rb', line 72

def self.new_string(string, options)
  ParseableString.new(string, options)
end

Instance Method Details

#guess_syntaxObject



76
77
78
# File 'lib/hocon/impl/parseable.rb', line 76

def guess_syntax
  nil
end

#include_contextObject



84
85
86
# File 'lib/hocon/impl/parseable.rb', line 84

def include_context
  @include_context
end

#optionsObject



80
81
82
# File 'lib/hocon/impl/parseable.rb', line 80

def options
  @initial_options
end

#parseObject



98
99
100
# File 'lib/hocon/impl/parseable.rb', line 98

def parse
  self.class.force_parsed_to_object(parse_value(options))
end

#parse_value(base_options) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/hocon/impl/parseable.rb', line 102

def parse_value(base_options)
  # note that we are NOT using our "initialOptions",
  # but using the ones from the passed-in options. The idea is that
  # callers can get our original options and then parse with different
  # ones if they want.
  options = fixup_options(base_options)

  # passed-in options can override origin
  origin =
      if options.origin_description
        Hocon::Impl::SimpleConfigOrigin.new_simple(options.origin_description)
      else
        @initial_origin
      end
  parse_value_from_origin(origin, options)
end