grably 0.0.2 → 0.0.3

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
  SHA256:
3
- metadata.gz: d0a6b73759c81fdcf51a74419ad2623872f6d1a11e369668ff3cfcd79d349d20
4
- data.tar.gz: 966bda27069001e502742cadb4ecea0a5ece85cc7ff149b4647468c4024d450e
3
+ metadata.gz: bf9742abda95d9380b462abfc4bb89378731258c0be527b2a3423088496232e0
4
+ data.tar.gz: 7861cf271dac8f6ca0bbec669fa25c4ca5b76bf9b3b88d2428abddd40a796b36
5
5
  SHA512:
6
- metadata.gz: 851a9f4b2da3543a59a4ad9ba04f2314dc97b25587534886372d5febd384fd745dc9d8feaa0504c8f64e65b153705b14a43ace8c9360aafb5e10fea4c8198f83
7
- data.tar.gz: 8f9c76709d59efd2a016784bff9c6ddf38c9dabbe4b474b78be316cf76e04983af191ebc009abd8482256a7dfe7d05a95470d5fd08725ab20f6e8d602619894a
6
+ metadata.gz: fd7ba5ea17f663a65e15ed6b7bde8c1711d019e02fc33d6631254e8d081a86f98a66d127abefdedcea7d98b8a2d8a335628cc30af3dd902edff16fdcd376a6ae
7
+ data.tar.gz: 45de64bc16029816e57839a7aa7a49db3a2b09da54f8dd5176f97cc3729741264ad178b24d17dbeee8ee6d548e85599f3d5c7ea8e048e47f2bd6a0425cfd30fa
@@ -14,11 +14,6 @@ module Grably
14
14
  '/_/ \____/_/ \__,_/_.___/_/\__, (_) |' \
15
15
  ' /____/ |'.tr('|', "\n")
16
16
 
17
- # Key where required profile is placed.
18
- # To load grably with profile `foo,bar` one need to
19
- # run `rake mp=foo,bar task1, task2, ... taskN`
20
- ENV_PROFILE_KEY = 'mp'.freeze
21
-
22
17
  def config
23
18
  Grably.config
24
19
  end
@@ -31,9 +26,7 @@ module Grably
31
26
  class << self
32
27
  attr_reader :config
33
28
  def init
34
- profile = (ENV[ENV_PROFILE_KEY] || 'default').split(',')
35
- puts 'Loding profile ' + profile.join('/')
36
- @config = Grably::Core::Configuration.load(profile)
29
+ @config = Grably::Core::Configuration.load
37
30
  end
38
31
 
39
32
  def server
@@ -3,7 +3,7 @@ require 'rake'
3
3
  require 'yaml'
4
4
 
5
5
  require_relative 'version'
6
-
6
+ require_relative 'core/configuration'
7
7
  module Grably
8
8
  # Grably CLI tool. Gives access to basic grably commands. Allowing to fetch
9
9
  # basic infromation about build configuration, grably version and much more
@@ -12,8 +12,8 @@ module Grably
12
12
  map %w(--version -v) => :version
13
13
  map %w(x) => :exec
14
14
 
15
- desc 'exec ...TASKS', 'Execute build tasks'
16
15
  option :profile, type: :string, default: 'default', aliases: :'-p', banner: '<profile>'
16
+ desc 'exec ...TASKS', 'Execute build tasks'
17
17
  def exec(*tasks)
18
18
  Rake.application.run(tasks + ["mp=#{options[:profile]}"])
19
19
  end
@@ -26,11 +26,11 @@ module Grably
26
26
  Rake.application.run(args)
27
27
  end
28
28
 
29
+ option :profile, type: :string, aliases: :'-p', banner: '<profile>'
29
30
  desc 'config', 'Pretty print current configuration'
30
- option :profile, type: :string, default: 'default', aliases: :'-p', banner: '<profile>'
31
31
  def config
32
32
  app = Rake.application
33
- app.init
33
+ ENV[Grably::ENV_PROFILE_KEY] = options[:profile]
34
34
  app.load_rakefile
35
35
  Grably.config.pretty_print
36
36
  end
@@ -10,6 +10,14 @@ module Grably
10
10
  # We use jac for configuration
11
11
  # @see https://github.com/vizor-games/jac
12
12
  module Configuration
13
+ # Key where required profile is placed.
14
+ # To load grably with profile `foo,bar` one need to
15
+ # run `rake mp=foo,bar task1, task2, ... taskN`
16
+ ENV_PROFILE_KEY = 'mp'.freeze
17
+
18
+ # Key where binary configuration stored if any
19
+ ENV_BINCONFIG_KEY = 'BIN_CONFIG'.freeze
20
+
13
21
  # Default configuration file names
14
22
  CONFIGURATION_FILES = %w(grably.yml grably.user.yml grably.override.yml).freeze
15
23
 
@@ -21,17 +29,55 @@ module Grably
21
29
  # names to read
22
30
  # @return [OpenStruct] instance which contains all resolved profile fields
23
31
  def read(profile, *streams)
24
- Jac::Configuration.read(profile, *streams)
32
+ obj = Jac::Configuration.read(profile, *streams)
33
+ obj.extend(self)
34
+ obj
25
35
  end
26
36
 
27
37
  # Read configuration from configuration files.
28
38
  # @praram [String or Array] profile which should be loaded
29
39
  # @param [String] dir base directory path for provided files may be nil
30
40
  # @return [OpenStruct] resolved profile values
31
- def load(profile, dir: nil)
32
- obj = Jac::Configuration.load(profile, files: CONFIGURATION_FILES, dir: dir)
33
- obj.extend(self)
34
- obj
41
+ def load(dir: nil, profile: [])
42
+ profile += (ENV[ENV_PROFILE_KEY] || 'default').split(',')
43
+ puts 'Loding profile ' + profile.join('/')
44
+ read(profile, *load_configuration_streams(dir))
45
+ end
46
+
47
+ def load_configuration_streams(dir)
48
+ # Read all known files
49
+ streams = CONFIGURATION_FILES
50
+ .map { |f| [dir ? File.join(Dir.pwd, f) : f, f] }
51
+ .select { |path, _name| File.exist?(path) }
52
+ .map { |path, name| [IO.read(path), name] }
53
+
54
+ streams << bin_config if bin_config?
55
+ streams
56
+ end
57
+
58
+ # Reads binary configuration as YAML configuration stream so it could
59
+ # be merged with other streams
60
+ def bin_config
61
+ data = hex_to_string ENV[ENV_BINCONFIG_KEY]
62
+ # Data will be walid YAML string. Trick is ident its contend and
63
+ # attach to ^top profile
64
+ [
65
+ "^top:\n" + data.split("\n").map { |x| ' ' + x }.join("\n"),
66
+ ENV_BINCONFIG_KEY
67
+ ]
68
+ end
69
+
70
+ # Converts hex string representation to plain string
71
+ # @see https://en.wikipedia.org/wiki/Hexadecimal
72
+ def hex_to_string(str)
73
+ str.each_char.each_slice(2).inject('') do |acc, elem|
74
+ acc + elem.map(&:chr).inject(&:+).hex.chr
75
+ end
76
+ end
77
+
78
+ # Tells if binary configuration is provided
79
+ def bin_config?
80
+ ENV[ENV_BINCONFIG_KEY]
35
81
  end
36
82
  end
37
83
  end
@@ -1,7 +1,7 @@
1
1
  module Grably # :nodoc:
2
2
  class << self
3
3
  # Current grably version identifier
4
- VERSION = [0, 0, 2].freeze
4
+ VERSION = [0, 0, 3].freeze
5
5
 
6
6
  # Returns grably version string
7
7
  # @return [String] version string
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grably
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Arkhanhelsky
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.1.1
47
+ version: 0.1.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.1.1
54
+ version: 0.1.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement