hocon 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57938b00093e55e8bc196496cc5d491d16d76a2e
4
- data.tar.gz: 700b53343336fb33116a0de444a2d04f2881e405
3
+ metadata.gz: 381d63a664f791ef19243206e6df57fba65f8344
4
+ data.tar.gz: 9eef67a35bdb45b99d617fe9358d778be75c1210
5
5
  SHA512:
6
- metadata.gz: bfedb58b6b68d16ee07e307f1f714e49efb1228147476fe8d6cbc788be924963fd4ebade645135c71b04306f49cc63adefd89b0855829aa6747daeb54f44ee5f
7
- data.tar.gz: 209bf58ccc186f9a849e75be0fc0c33af4f08460b88c6dcfdc5a0c484dcc881523b18fb96e306fd4577aa71b3336b859c5578d1926c4f2d4223b35177a172022
6
+ metadata.gz: d4c6571dd9fdd9bbb6616123f7a5215d8e5c84f80fa2e130507f24a67a743bd4ec4317c542d5ca5fb7b02369aef15088df36a8c069adfe232e56cbed3c84f914
7
+ data.tar.gz: e1a1351ee91715a8ab1918befcea8967c7d931e13e569506c2f458025a59d7c667ab8f4d259aff00804a21eff2691b97190ee401ead386b2a407eaf0de02e571
data/lib/hocon.rb CHANGED
@@ -1,2 +1,13 @@
1
+ require 'hocon/config_factory'
2
+
1
3
  module Hocon
2
- end
4
+ def self.load(file)
5
+ config = Hocon::ConfigFactory.parse_file(file)
6
+ return config.root.unwrapped
7
+ end
8
+
9
+ def self.parse(string)
10
+ config = Hocon::ConfigFactory.parse_string(string)
11
+ return config.root.unwrapped
12
+ end
13
+ end
@@ -1,15 +1,15 @@
1
- require 'hocon'
1
+ module Hocon
2
+ class ConfigError < StandardError
3
+ def initialize(origin, message, cause)
4
+ super(message)
5
+ @origin = origin
6
+ @cause = cause
7
+ end
2
8
 
3
- class Hocon::ConfigError < StandardError
4
- def initialize(origin, message, cause)
5
- super(message)
6
- @origin = origin
7
- @cause = cause
8
- end
9
-
10
- class ConfigParseError < Hocon::ConfigError
11
- end
9
+ class ConfigParseError < Hocon::ConfigError
10
+ end
12
11
 
13
- class ConfigWrongTypeError < Hocon::ConfigError
12
+ class ConfigWrongTypeError < Hocon::ConfigError
13
+ end
14
14
  end
15
15
  end
@@ -1,13 +1,14 @@
1
- require 'hocon'
2
1
  require 'hocon/config_parse_options'
3
2
  require 'hocon/impl/parseable'
4
3
 
5
- class Hocon::ConfigFactory
6
- def self.parse_file(file_path, options = Hocon::ConfigParseOptions.defaults)
7
- Hocon::Impl::Parseable.new_file(file_path, options).parse.to_config
8
- end
4
+ module Hocon
5
+ class ConfigFactory
6
+ def self.parse_file(file_path, options = Hocon::ConfigParseOptions.defaults)
7
+ Hocon::Impl::Parseable.new_file(file_path, options).parse.to_config
8
+ end
9
9
 
10
- def self.parse_string(string, options = Hocon::ConfigParseOptions.defaults)
11
- Hocon::Impl::Parseable.new_string(string, options).parse.to_config
10
+ def self.parse_string(string, options = Hocon::ConfigParseOptions.defaults)
11
+ Hocon::Impl::Parseable.new_string(string, options).parse.to_config
12
+ end
12
13
  end
13
14
  end
@@ -1,4 +1,4 @@
1
- require 'hocon'
2
-
3
- module Hocon::ConfigObject
4
- end
1
+ module Hocon
2
+ module ConfigObject
3
+ end
4
+ end
@@ -1,53 +1,53 @@
1
- require 'hocon'
1
+ module Hocon
2
+ class ConfigParseOptions
3
+ attr_accessor :syntax, :origin_description, :allow_missing, :includer
2
4
 
3
- class Hocon::ConfigParseOptions
4
- attr_accessor :syntax, :origin_description, :allow_missing, :includer
5
-
6
- def self.defaults
7
- self.new(nil, nil, true, nil)
8
- end
5
+ def self.defaults
6
+ self.new(nil, nil, true, nil)
7
+ end
9
8
 
10
- def initialize(syntax, origin_description, allow_missing, includer)
11
- @syntax = syntax
12
- @origin_description = origin_description
13
- @allow_missing = allow_missing
14
- @includer = includer
15
- end
9
+ def initialize(syntax, origin_description, allow_missing, includer)
10
+ @syntax = syntax
11
+ @origin_description = origin_description
12
+ @allow_missing = allow_missing
13
+ @includer = includer
14
+ end
16
15
 
17
- def allow_missing?
18
- @allow_missing
19
- end
16
+ def allow_missing?
17
+ @allow_missing
18
+ end
20
19
 
21
- def with_syntax(syntax)
22
- if @syntax == syntax
23
- self
24
- else
25
- Hocon::ConfigParseOptions.new(syntax,
26
- @origin_description,
27
- @allow_missing,
28
- @includer)
20
+ def with_syntax(syntax)
21
+ if @syntax == syntax
22
+ self
23
+ else
24
+ Hocon::ConfigParseOptions.new(syntax,
25
+ @origin_description,
26
+ @allow_missing,
27
+ @includer)
28
+ end
29
29
  end
30
- end
31
30
 
32
- def with_includer(includer)
33
- if @includer == includer
34
- self
35
- else
36
- Hocon::ConfigParseOptions.new(@syntax,
37
- @origin_description,
38
- @allow_missing,
39
- includer)
31
+ def with_includer(includer)
32
+ if @includer == includer
33
+ self
34
+ else
35
+ Hocon::ConfigParseOptions.new(@syntax,
36
+ @origin_description,
37
+ @allow_missing,
38
+ includer)
39
+ end
40
40
  end
41
- end
42
41
 
43
- def append_includer(includer)
44
- if @includer == includer
45
- self
46
- elsif @includer
47
- with_includer(@includer.with_fallback(includer))
48
- else
49
- with_includer(includer)
42
+ def append_includer(includer)
43
+ if @includer == includer
44
+ self
45
+ elsif @includer
46
+ with_includer(@includer.with_fallback(includer))
47
+ else
48
+ with_includer(includer)
49
+ end
50
50
  end
51
- end
52
51
 
53
- end
52
+ end
53
+ end
@@ -1,46 +1,46 @@
1
- require 'hocon'
1
+ module Hocon
2
+ class ConfigRenderOptions
3
+ def initialize(origin_comments, comments, formatted, json)
4
+ @origin_comments = origin_comments
5
+ @comments = comments
6
+ @formatted = formatted
7
+ @json = json
8
+ end
2
9
 
3
- class Hocon::ConfigRenderOptions
4
- def initialize(origin_comments, comments, formatted, json)
5
- @origin_comments = origin_comments
6
- @comments = comments
7
- @formatted = formatted
8
- @json = json
9
- end
10
+ attr_writer :origin_comments, :comments, :formatted, :json
10
11
 
11
- attr_writer :origin_comments, :comments, :formatted, :json
12
+ def origin_comments?
13
+ @origin_comments
14
+ end
15
+ def comments?
16
+ @comments
17
+ end
18
+ def formatted?
19
+ @formatted
20
+ end
21
+ def json?
22
+ @json
23
+ end
12
24
 
13
- def origin_comments?
14
- @origin_comments
15
- end
16
- def comments?
17
- @comments
18
- end
19
- def formatted?
20
- @formatted
21
- end
22
- def json?
23
- @json
24
- end
25
-
26
- #
27
- # Returns the default render options which are verbose (commented and
28
- # formatted). See {@link ConfigRenderOptions#concise} for stripped-down
29
- # options. This rendering will not be valid JSON since it has comments.
30
- #
31
- # @return the default render options
32
- #
33
- def self.defaults
34
- Hocon::ConfigRenderOptions.new(true, true, true, true)
35
- end
25
+ #
26
+ # Returns the default render options which are verbose (commented and
27
+ # formatted). See {@link ConfigRenderOptions#concise} for stripped-down
28
+ # options. This rendering will not be valid JSON since it has comments.
29
+ #
30
+ # @return the default render options
31
+ #
32
+ def self.defaults
33
+ ConfigRenderOptions.new(true, true, true, true)
34
+ end
36
35
 
37
- #
38
- # Returns concise render options (no whitespace or comments). For a
39
- # resolved {@link Config}, the concise rendering will be valid JSON.
40
- #
41
- # @return the concise render options
42
- #
43
- def self.concise
44
- Hocon::ConfigRenderOptions.new(false, false, false, true)
36
+ #
37
+ # Returns concise render options (no whitespace or comments). For a
38
+ # resolved {@link Config}, the concise rendering will be valid JSON.
39
+ #
40
+ # @return the concise render options
41
+ #
42
+ def self.concise
43
+ ConfigRenderOptions.new(false, false, false, true)
44
+ end
45
45
  end
46
- end
46
+ end
@@ -1,7 +1,7 @@
1
- require 'hocon'
2
-
3
- module Hocon::ConfigSyntax
4
- JSON = 0
5
- CONF = 1
6
- PROPERTIES = 2
7
- end
1
+ module Hocon
2
+ module ConfigSyntax
3
+ JSON = 0
4
+ CONF = 1
5
+ PROPERTIES = 2
6
+ end
7
+ end
@@ -1,26 +1,26 @@
1
- require 'hocon'
1
+ module Hocon
2
+ #
3
+ # The type of a configuration value (following the <a
4
+ # href="http://json.org">JSON</a> type schema).
5
+ #
6
+ module ConfigValueType
7
+ OBJECT = 0
8
+ LIST = 1
9
+ NUMBER = 2
10
+ BOOLEAN = 3
11
+ NULL = 4
12
+ STRING = 5
2
13
 
3
- #
4
- # The type of a configuration value (following the <a
5
- # href="http://json.org">JSON</a> type schema).
6
- #
7
- module Hocon::ConfigValueType
8
- OBJECT = 0
9
- LIST = 1
10
- NUMBER = 2
11
- BOOLEAN = 3
12
- NULL = 4
13
- STRING = 5
14
-
15
- def self.name(config_value_type)
16
- case config_value_type
17
- when OBJECT then "OBJECT"
18
- when LIST then "LIST"
19
- when NUMBER then "NUMBER"
20
- when BOOLEAN then "BOOLEAN"
21
- when NULL then "NULL"
22
- when STRING then "STRING"
23
- else raise ConfigBugError, "Unrecognized value type '#{config_value_type}'"
14
+ def self.name(config_value_type)
15
+ case config_value_type
16
+ when OBJECT then "OBJECT"
17
+ when LIST then "LIST"
18
+ when NUMBER then "NUMBER"
19
+ when BOOLEAN then "BOOLEAN"
20
+ when NULL then "NULL"
21
+ when STRING then "STRING"
22
+ else raise ConfigBugError, "Unrecognized value type '#{config_value_type}'"
23
+ end
24
24
  end
25
25
  end
26
- end
26
+ end
data/lib/hocon/impl.rb CHANGED
@@ -1,5 +1,4 @@
1
- require 'hocon'
2
-
3
- module Hocon::Impl
4
-
5
- end
1
+ module Hocon
2
+ module Impl
3
+ end
4
+ end
@@ -360,7 +360,7 @@ class Hocon::Impl::Parser
360
360
  while !key.nil?
361
361
  # for ruby: convert string keys to symbols
362
362
  if key.is_a?(String)
363
- key = key.to_sym
363
+ key = key
364
364
  end
365
365
  keys.push(key)
366
366
  if remaining.nil?
@@ -496,7 +496,7 @@ class Hocon::Impl::Parser
496
496
 
497
497
  # for ruby: convert string keys to symbols
498
498
  if key.is_a?(String)
499
- key = key.to_sym
499
+ key = key
500
500
  end
501
501
 
502
502
  remaining = path.remainder
@@ -579,10 +579,10 @@ class Hocon::Impl::Parser
579
579
 
580
580
  # special-case the first element
581
581
  if t.token == Tokens::CLOSE_SQUARE
582
- SimpleConfigList.new(t.append_comments(array_origin), [])
582
+ return SimpleConfigList.new(t.append_comments(array_origin), [])
583
583
  elsif (Tokens.value?(t.token)) ||
584
584
  (t.token == Tokens::OPEN_CURLY) ||
585
- (to.token == Tokens::OPEN_SQUARE)
585
+ (t.token == Tokens::OPEN_SQUARE)
586
586
  v = parse_value(t)
587
587
  v = add_any_comments_after_any_comma(v)
588
588
  values.push(v)
@@ -879,4 +879,4 @@ class Hocon::Impl::Parser
879
879
  include_context)
880
880
  context.parse
881
881
  end
882
- end
882
+ end
@@ -67,4 +67,8 @@ class Hocon::Impl::SimpleConfigList < Hocon::Impl::AbstractConfigValue
67
67
  sb << "]"
68
68
  end
69
69
  end
70
- end
70
+
71
+ def new_copy(origin)
72
+ Hocon::Impl::SimpleConfigList.new(origin, @value)
73
+ end
74
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hocon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Price