jac 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85117aeca4175be823c52ff25aa33e0ebaf6efdf
4
- data.tar.gz: b8c98ee89f3a3818cfa906f26e8ac3189282fd18
3
+ metadata.gz: 2b46834178b5af04b84cb286e7f449a4fc63920b
4
+ data.tar.gz: 04f6f8bd3f489f28fb78f138d2a665cf8e03e690
5
5
  SHA512:
6
- metadata.gz: 7f9f97b2551ec8c5ec763673b615cfba497e434e4a3004e396cf106bd080c53398fbea623f3051318097fd419265a3c601e054abf805029b30250780c65b9ce3
7
- data.tar.gz: 4f26c83218fffd715448ca87ba96e39d99a17efe702bde663e9aa2c3fb6f3cae20878177dbcac0c3ad97dbace423b57d8ff88a8f36bfb0dae6cbc738f9d3d377
6
+ metadata.gz: 6586f01ea2192d6abf3c49d525bd0c3586261ba74e5e23b03fc700f8dd0ffa40d97be1ce1b5b8b31fc3dbe07ebe17c66f629eab9768d422bc41e762ec6c68c40
7
+ data.tar.gz: 93a37896f9a576ae32147bc801463812e2a8b752ecc6cd3066ac032587e8fb29abc85abeae47e129098e964db04bc6bc44cf6e242b615d90e79e3647de4800a4
@@ -9,7 +9,7 @@ module Jac
9
9
  # key names (i.e. `extends`) each key in profile is a
10
10
  # configuration field. For example following yaml document
11
11
  #
12
- # ```
12
+ # ```yml
13
13
  #
14
14
  # foo:
15
15
  # bar: 42
@@ -39,7 +39,7 @@ module Jac
39
39
  # profiles. To specify this one should use `extends` field
40
40
  # like that
41
41
  #
42
- # ```
42
+ # ```yml
43
43
  #
44
44
  # base:
45
45
  # application_name: my-awesome-app
@@ -56,7 +56,7 @@ module Jac
56
56
  #
57
57
  # In this example `debug` will receive following fields:
58
58
  #
59
- # ```
59
+ # ```yml
60
60
  # application_name: my-awesome-app # from base profile
61
61
  # port: 9292 # from debug profile
62
62
  # version_name: 0.0.0 # from version profile
@@ -70,7 +70,7 @@ module Jac
70
70
  # are merged down together. Having sequence of files like
71
71
  # `.application.yml`, `.application.user.yml` with following content
72
72
  #
73
- # ```
73
+ # ```yml
74
74
  # # .application.yml
75
75
  # base:
76
76
  # user: deployer
@@ -80,7 +80,7 @@ module Jac
80
80
  # # ... other values
81
81
  # ```
82
82
  #
83
- # ```
83
+ # ```yml
84
84
  # # .application.user.yml
85
85
  # base:
86
86
  # user: developer
@@ -96,14 +96,14 @@ module Jac
96
96
  # feature: it allows evaluate strings as ruby expressions
97
97
  # like this:
98
98
  #
99
- # ```
99
+ # ```yml
100
100
  # foo:
101
101
  # build_time: "#{Time.now}" # Will be evaluated at configuration resolving step
102
102
  # ```
103
103
  #
104
104
  # Configuration values are available to and can be referenced with `c`:
105
105
  #
106
- # ```
106
+ # ```yml
107
107
  # base:
108
108
  # application_name: my-awesome-app
109
109
  # debug:
@@ -120,13 +120,47 @@ module Jac
120
120
  #
121
121
  # ## Merging values
122
122
  #
123
- # By default if one value definition overwrites another
123
+ # By default if one value have multiple defenitions it will be overwritten by
124
+ # topmost value. Except several cases where Jac handles value resolution
125
+ # specialy
126
+ #
124
127
  # ### Merging hashes
125
128
  #
126
- #
127
- # ### Merging sets
129
+ # Hashes inside profile are recurseively merged automaticly. This rule works
130
+ # for profile extensions and value redefenitions too.
131
+ #
132
+ # Example:
133
+ #
134
+ # ```yml
135
+ # base:
136
+ # servers:
137
+ # release: http://release.com
138
+ #
139
+ # debug:
140
+ # extends: base
141
+ # debug: http://debug.com
142
+ #
143
+ # ```
128
144
  #
145
+ # ### Merging sets
129
146
  #
147
+ # Sets allowed to be merged with `nil`s and any instance of `Enumerable`.
148
+ # Merge result is always new `Set` instance.
149
+ # ```yml
150
+ # release:
151
+ # extends:
152
+ # - no_rtti
153
+ # - no_debug
154
+ # flags: !set {} # empty set
155
+ # no_rtti:
156
+ # flags:
157
+ # - -fno-rtti
158
+ # no_debug:
159
+ # flags:
160
+ # - -DNDEBUG
161
+ # ```
162
+ #
163
+ # Resulting profile will have `-fno-rtti, -DNDEBUG` in `release profile`
130
164
  # ## Generic profiles
131
165
  #
132
166
  # Same result as shown above can be achieved with generic profiles. Generic profile
@@ -151,18 +185,17 @@ module Jac
151
185
  DEFAULT_PROFILE_NAME = 'default'.freeze
152
186
  # Creates "empty" config
153
187
  DEFAULT_CONFIGURATION = -> () { { DEFAULT_PROFILE_NAME => {} } }
154
- # Creates configuration reader
155
- # @param streams [Array] of pairs containing YAML document and provided
156
- # name for this stream
157
188
  attr_reader :merger
189
+ # Creates configuration reader
190
+ # @param [Array] streams of pairs containing YAML document and provided
191
+ # name for this stream
158
192
  def initialize(streams)
159
193
  @streams = streams
160
194
  @merger = Merger.new
161
195
  end
162
196
 
163
197
  # Parses all streams and resolves requested profile
164
- # @param profile [Array] list of profile names to be
165
- # merged
198
+ # @param [Array] profile list of profile names to be merged
166
199
  # @return [OpenStruct] instance which contains all resolved profile fields
167
200
  def read(*profile)
168
201
  result = @streams
@@ -177,7 +210,7 @@ module Jac
177
210
  # Each stream consists of one or more documents
178
211
  YAML.parse_stream(stream).children.flat_map do |document|
179
212
  # Will use separate visitor per YAML document.
180
- visitor = Only::Parser::VisitorToRuby.create
213
+ visitor = Jac::Parser::VisitorToRuby.create
181
214
  # Expecting document to be single mapping
182
215
  profile_mapping = document.children.first
183
216
  raise(ArgumentError, 'Mapping expected') unless profile_mapping.is_a? Psych::Nodes::Mapping
@@ -208,8 +241,8 @@ module Jac
208
241
  # @param [Hash] base value mappings
209
242
  # @param [Hash] values ovverides.
210
243
  # @return [Hash] merged profile
211
- def merge!(base, overrides)
212
- merger.merge!(base, overrides)
244
+ def merge!(base, values)
245
+ merger.merge!(base, values)
213
246
  end
214
247
 
215
248
  def resolve(profile, config)
@@ -261,7 +294,9 @@ module Jac
261
294
  def generate_profile(match, matched_profile, profile_name)
262
295
  gen_profile = {}
263
296
  gen_profile['captures'] = match.captures if match.captures
264
- gen_profile['named_captures'] = match.named_captures if match.named_captures
297
+ if match.respond_to?(:named_captures) && match.named_captures
298
+ gen_profile['named_captures'] = match.named_captures
299
+ end
265
300
  gen_profile.merge!(config[matched_profile])
266
301
 
267
302
  config[profile_name] = gen_profile
@@ -373,13 +408,13 @@ module Jac
373
408
  end
374
409
 
375
410
  # List of files where configuration can be placed
376
- # * `application.yml` - expected to be main configuration file.
411
+ # * `jac.yml` - expected to be main configuration file.
377
412
  # Usually it placed under version control.
378
- # * `application.user.yml` - user defined overrides for main
413
+ # * `jac.user.yml` - user defined overrides for main
379
414
  # configuration, sensitive data which can't be placed
380
415
  # under version control.
381
- # * `application.override.yml` - final overrides.
382
- CONFIGURATION_FILES = %w[application.yml application.user.yml application.override.yml].freeze
416
+ # * `jac.override.yml` - final overrides.
417
+ CONFIGURATION_FILES = %w[jac.yml jac.user.yml jac.override.yml].freeze
383
418
 
384
419
  class << self
385
420
  # Generates configuration object for given profile
@@ -394,10 +429,14 @@ module Jac
394
429
  end
395
430
 
396
431
  # Read configuration from configuration files.
432
+ # @praram [String or Array] profile which should be loaded
433
+ # @param [Array] files filenames to load
434
+ # @param [String] dir base directory path for provided files may be nil
435
+ # @return [OpenStruct] resolved profile values
397
436
  def load(profile, files: CONFIGURATION_FILES, dir: Dir.pwd)
398
437
  # Read all known files
399
438
  streams = files
400
- .map { |f| [File.join(dir, f), f] }
439
+ .map { |f| [dir ? File.join(dir, f) : f, f] }
401
440
  .select { |path, _name| File.exist?(path) }
402
441
  .map { |path, name| [IO.read(path), name] }
403
442
  read(profile, *streams)
data/lib/jac/parser.rb CHANGED
@@ -2,16 +2,17 @@ require 'psych'
2
2
  require 'set'
3
3
 
4
4
  module Jac
5
+ # Custom YAML parsing routines
5
6
  module Parser
6
7
  # Cutstom Yaml AST visitor
7
- # @see {Psych::Visitors::ToRuby}
8
- # While standart Psych visitor converts sets to `{ value => nil }` mappings
9
- # we need explicitly convert those mappings to ruby {Set}
8
+ # @see Psych::Visitors::ToRuby
9
+ # While standard Psych visitor converts sets to `{ value => nil }` mappings
10
+ # we need explicitly convert those mappings to ruby [Set]
10
11
  class VisitorToRuby < Psych::Visitors::ToRuby
11
12
  # rubocop: disable Naming/MethodName
12
13
 
13
14
  # Uses standard Psych visitor to convert mapping to ruby object
14
- # except `!set` case. Here we convert mapping to {Set}.
15
+ # except `!set` case. Here we convert mapping to [Set].
15
16
  # @param [Psych::Nodes::Mapping] o YAML AST node
16
17
  # @return [Object] parsed ruby object
17
18
  def visit_Psych_Nodes_Mapping(o)
data/lib/jac.rb CHANGED
@@ -1,3 +1,8 @@
1
1
  require_relative 'jac/configuration'
2
2
  require_relative 'jac/merger'
3
3
  require_relative 'jac/parser'
4
+
5
+ # Just another config top level module
6
+ # @see Jac::Configuration
7
+ module Jac
8
+ end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jac
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ilya.arkhanhelsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-14 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: powerpack
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '='
18
- - !ruby/object:Gem::Version
19
- version: 0.1.1
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '='
25
- - !ruby/object:Gem::Version
26
- version: 0.1.1
11
+ date: 2017-11-15 00:00:00.000000000 Z
12
+ dependencies: []
27
13
  description: Profile based configuration lib
28
14
  email: ilya.arkhanhelsky@vizor-games.com
29
15
  executables: []
@@ -34,7 +20,6 @@ files:
34
20
  - lib/jac/configuration.rb
35
21
  - lib/jac/merger.rb
36
22
  - lib/jac/parser.rb
37
- - lib/version.rb
38
23
  homepage: https://github.com/vizor-games/jac
39
24
  licenses:
40
25
  - MIT
data/lib/version.rb DELETED
@@ -1,14 +0,0 @@
1
- module Jac
2
- # Jac version module
3
- module Version
4
- class << self
5
- def value
6
- [ 0, 0, 1]
7
- end
8
-
9
- def to_s
10
- value.join('.')
11
- end
12
- end
13
- end
14
- end