typesafe_config 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/README.md +15 -0
  2. metadata +3 -40
  3. data/lib/typesafe/config/config_error.rb +0 -12
  4. data/lib/typesafe/config/config_factory.rb +0 -9
  5. data/lib/typesafe/config/config_object.rb +0 -4
  6. data/lib/typesafe/config/config_parse_options.rb +0 -53
  7. data/lib/typesafe/config/config_render_options.rb +0 -46
  8. data/lib/typesafe/config/config_syntax.rb +0 -7
  9. data/lib/typesafe/config/config_value_type.rb +0 -26
  10. data/lib/typesafe/config/impl/abstract_config_object.rb +0 -64
  11. data/lib/typesafe/config/impl/abstract_config_value.rb +0 -130
  12. data/lib/typesafe/config/impl/config_concatenation.rb +0 -136
  13. data/lib/typesafe/config/impl/config_float.rb +0 -9
  14. data/lib/typesafe/config/impl/config_impl.rb +0 -10
  15. data/lib/typesafe/config/impl/config_impl_util.rb +0 -78
  16. data/lib/typesafe/config/impl/config_int.rb +0 -31
  17. data/lib/typesafe/config/impl/config_number.rb +0 -27
  18. data/lib/typesafe/config/impl/config_string.rb +0 -37
  19. data/lib/typesafe/config/impl/full_includer.rb +0 -4
  20. data/lib/typesafe/config/impl/origin_type.rb +0 -9
  21. data/lib/typesafe/config/impl/parseable.rb +0 -151
  22. data/lib/typesafe/config/impl/parser.rb +0 -882
  23. data/lib/typesafe/config/impl/path.rb +0 -59
  24. data/lib/typesafe/config/impl/path_builder.rb +0 -36
  25. data/lib/typesafe/config/impl/resolve_status.rb +0 -18
  26. data/lib/typesafe/config/impl/simple_config.rb +0 -11
  27. data/lib/typesafe/config/impl/simple_config_list.rb +0 -70
  28. data/lib/typesafe/config/impl/simple_config_object.rb +0 -178
  29. data/lib/typesafe/config/impl/simple_config_origin.rb +0 -174
  30. data/lib/typesafe/config/impl/simple_include_context.rb +0 -7
  31. data/lib/typesafe/config/impl/simple_includer.rb +0 -19
  32. data/lib/typesafe/config/impl/token.rb +0 -32
  33. data/lib/typesafe/config/impl/token_type.rb +0 -42
  34. data/lib/typesafe/config/impl/tokenizer.rb +0 -370
  35. data/lib/typesafe/config/impl/tokens.rb +0 -157
  36. data/lib/typesafe/config/impl/unmergeable.rb +0 -4
  37. data/lib/typesafe/config/impl.rb +0 -5
  38. data/lib/typesafe/config.rb +0 -4
  39. data/lib/typesafe.rb +0 -2
@@ -1,31 +0,0 @@
1
- require 'typesafe/config/impl'
2
- require 'typesafe/config/impl/config_number'
3
- require 'typesafe/config/config_value_type'
4
-
5
- class Typesafe::Config::Impl::ConfigInt < Typesafe::Config::Impl::ConfigNumber
6
- def initialize(origin, value, original_text)
7
- super(origin, original_text)
8
- @value = value
9
- end
10
-
11
- def value_type
12
- Typesafe::Config::ConfigValueType::NUMBER
13
- end
14
-
15
- def unwrapped
16
- @value
17
- end
18
-
19
- def transform_to_string
20
- s = super
21
- if s.nil?
22
- self.to_s
23
- else
24
- s
25
- end
26
- end
27
-
28
- def new_copy(origin)
29
- Typesafe::Config::Impl::ConfigInt.new(origin, @value, @original_text)
30
- end
31
- end
@@ -1,27 +0,0 @@
1
- require 'typesafe/config/impl'
2
- require 'typesafe/config/impl/abstract_config_value'
3
-
4
- class Typesafe::Config::Impl::ConfigNumber < Typesafe::Config::Impl::AbstractConfigValue
5
- ## sigh... requiring these subclasses before this class
6
- ## is declared would cause an error. Thanks, ruby.
7
- require 'typesafe/config/impl/config_int'
8
- require 'typesafe/config/impl/config_float'
9
-
10
- def self.new_number(origin, number, original_text)
11
- as_int = number.to_i
12
- if as_int == number
13
- Typesafe::Config::Impl::ConfigInt.new(origin, as_int, original_text)
14
- else
15
- Typesafe::Config::Impl::ConfigFloat.new(origin, number, original_text)
16
- end
17
- end
18
-
19
- def initialize(origin, original_text)
20
- super(origin)
21
- @original_text = original_text
22
- end
23
-
24
- def transform_to_string
25
- @original_text
26
- end
27
- end
@@ -1,37 +0,0 @@
1
- require 'typesafe/config/impl'
2
- require 'typesafe/config/impl/abstract_config_value'
3
- require 'typesafe/config/config_value_type'
4
- require 'typesafe/config/impl/config_impl_util'
5
-
6
- class Typesafe::Config::Impl::ConfigString < Typesafe::Config::Impl::AbstractConfigValue
7
- ConfigImplUtil = Typesafe::Config::Impl::ConfigImplUtil
8
-
9
- def initialize(origin, value)
10
- super(origin)
11
- @value = value
12
- end
13
-
14
- def value_type
15
- Typesafe::Config::ConfigValueType::STRING
16
- end
17
-
18
- def unwrapped
19
- @value
20
- end
21
-
22
- def transform_to_string
23
- @value
24
- end
25
-
26
- def render_value_to_sb(sb, indent_size, at_root, options)
27
- if options.json?
28
- sb << ConfigImplUtil.render_json_string(@value)
29
- else
30
- sb << ConfigImplUtil.render_string_unquoted_if_possible(@value)
31
- end
32
- end
33
-
34
- def new_copy(origin)
35
- Typesafe::Config::Impl::ConfigString.new(origin, @value)
36
- end
37
- end
@@ -1,4 +0,0 @@
1
- require 'typesafe/config/impl'
2
-
3
- class Typesafe::Config::Impl::FullIncluder
4
- end
@@ -1,9 +0,0 @@
1
- require 'typesafe/config/impl'
2
-
3
- module Typesafe::Config::Impl::OriginType
4
- ## for now, we only support a subset of these
5
- GENERIC = 0
6
- FILE = 1
7
- #URL = 2
8
- #RESOURCE = 3
9
- end
@@ -1,151 +0,0 @@
1
- require 'typesafe/config/impl'
2
- require 'typesafe/config/config_syntax'
3
- require 'typesafe/config/impl/config_impl'
4
- require 'typesafe/config/impl/simple_include_context'
5
- require 'typesafe/config/impl/simple_config_object'
6
- require 'typesafe/config/impl/simple_config_origin'
7
- require 'typesafe/config/impl/tokenizer'
8
- require 'typesafe/config/impl/parser'
9
-
10
- class Typesafe::Config::Impl::Parseable
11
- class ParseableFile < Typesafe::Config::Impl::Parseable
12
- def initialize(file_path, options)
13
- @input = file_path
14
- post_construct(options)
15
- end
16
-
17
- def guess_syntax
18
- Typesafe::Config::Impl::Parseable.syntax_from_extension(File.basename(@input))
19
- end
20
-
21
- def create_origin
22
- Typesafe::Config::Impl::SimpleConfigOrigin.new_file(@input)
23
- end
24
-
25
- def reader
26
- self
27
- end
28
-
29
- def open
30
- if block_given?
31
- File.open(@input) do |f|
32
- yield f
33
- end
34
- else
35
- File.open(@input)
36
- end
37
- end
38
- end
39
-
40
- def self.new_file(file_path, options)
41
- ParseableFile.new(file_path, options)
42
- end
43
-
44
- def options
45
- @initial_options
46
- end
47
-
48
- def include_context
49
- @include_context
50
- end
51
-
52
- def self.force_parsed_to_object(value)
53
- if value.is_a? Typesafe::Config::Impl::AbstractConfigObject
54
- value
55
- else
56
- raise ConfigWrongTypeError.new(value.origin, "", "object at file root",
57
- value.value_type.name)
58
- end
59
- end
60
-
61
- def parse
62
- self.class.force_parsed_to_object(parse_value(options))
63
- end
64
-
65
- def parse_value(base_options)
66
- # note that we are NOT using our "initialOptions",
67
- # but using the ones from the passed-in options. The idea is that
68
- # callers can get our original options and then parse with different
69
- # ones if they want.
70
- options = fixup_options(base_options)
71
-
72
- # passed-in options can override origin
73
- origin =
74
- if options.origin_description
75
- Typesafe::Config::Impl::SimpleConfigOrigin.new_simple(options.origin_description)
76
- else
77
- @initial_origin
78
- end
79
- parse_value_from_origin(origin, options)
80
- end
81
-
82
-
83
- private
84
-
85
- def self.syntax_from_extension(filename)
86
- case File.extname(filename)
87
- when ".json"
88
- Typesafe::Config::ConfigSyntax::JSON
89
- when ".conf"
90
- Typesafe::Config::ConfigSyntax::CONF
91
- when ".properties"
92
- Typesafe::Config::ConfigSyntax::PROPERTIES
93
- else
94
- nil
95
- end
96
- end
97
-
98
- def post_construct(base_options)
99
- @initial_options = fixup_options(base_options)
100
- @include_context = Typesafe::Config::Impl::SimpleIncludeContext.new(self)
101
- if @initial_options.origin_description
102
- @initial_origin = SimpleConfigOrigin.new_simple(@initial_options.origin_description)
103
- else
104
- @initial_origin = create_origin
105
- end
106
- end
107
-
108
- def fixup_options(base_options)
109
- syntax = base_options.syntax
110
- if !syntax
111
- syntax = guess_syntax
112
- end
113
- if !syntax
114
- syntax = Typesafe::Config::ConfigSyntax.CONF
115
- end
116
-
117
- modified = base_options.with_syntax(syntax)
118
- modified = modified.append_includer(Typesafe::Config::Impl::ConfigImpl.default_includer)
119
- modified = modified.with_includer(Typesafe::Config::Impl::SimpleIncluder.make_full(modified.includer))
120
-
121
- modified
122
- end
123
-
124
- def parse_value_from_origin(origin, final_options)
125
- begin
126
- raw_parse_value(origin, final_options)
127
- rescue IOError => e
128
- if final_options.allow_missing?
129
- Typesafe::Config::Impl::SimpleConfigObject.empty_missing(origin)
130
- else
131
- raise ConfigIOError.new(origin, "#{e.class.name}: #{e.message}", e)
132
- end
133
- end
134
- end
135
-
136
- # this is parseValue without post-processing the IOException or handling
137
- # options.getAllowMissing()
138
- def raw_parse_value(origin, final_options)
139
- ## TODO: if we were going to support loading from URLs, this
140
- ## method would need to deal with the content-type.
141
-
142
- reader.open { |io|
143
- raw_parse_value_from_io(io, origin, final_options)
144
- }
145
- end
146
-
147
- def raw_parse_value_from_io(io, origin, final_options)
148
- tokens = Typesafe::Config::Impl::Tokenizer.tokenize(origin, io, final_options.syntax)
149
- Typesafe::Config::Impl::Parser.parse(tokens, origin, final_options, include_context)
150
- end
151
- end