flight_config 0.2.0 → 0.3.0

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: f8c36bdbe520695cb9d379d6038699c3529fb1fb8938af728fa50452ec0414ae
4
- data.tar.gz: 58bf550037f38ede9db72516a5a70afd1b2fa1a47f1be8e7a3d7b95144d9d768
3
+ metadata.gz: 8526bfd920f7e1e74a43402bd85998d5bfd997ad8e65fcff50db35b2d1e82616
4
+ data.tar.gz: fcd21613b191a9cd3df1e84780f62677b47b18ee84f86d0d75a883d42c5e385b
5
5
  SHA512:
6
- metadata.gz: bf01421b86b937cfd4df7180398a81578723391cd26ac0f54e8c98d7ad741cc1315ff23f257460cb6e7474c652285e67cc5ffabf739fb1d3fda6e826847d6d21
7
- data.tar.gz: 17768019155bd3e1621f0d597c89010b1403fe11f280ccec08f9e27c5685bb0435b0dbfdbc888b59bfcc84772146ebb153c2f624330505979d7c3b61b1bdbdc0
6
+ metadata.gz: 11b70976a739890020e3d266da4e3acf39d04fab07d0447efa56a6db1d3cd712e162276a6fd29a35bf3572e534fb249dc4dae1ec12f905fd4bb1905a1eb5e288
7
+ data.tar.gz: b8e468998c06fea296e29bb1bb70d3f94d1e9cc94906748bc0612b928946e8ce3e96ecb852cf00e1982e550588dcc1517b5abd8a5c742a46a9f3c97c45842adb
@@ -30,4 +30,5 @@ module FlightConfig
30
30
  class ResourceBusy < FlightConfigError; end
31
31
  class MissingFile < FlightConfigError; end
32
32
  class CreateError < FlightConfigError; end
33
+ class InvalidIndex < FlightConfigError; end
33
34
  end
@@ -0,0 +1,53 @@
1
+ #==============================================================================
2
+ # Copyright (C) 2019-present Alces Flight Ltd.
3
+ #
4
+ # This file is part of FlightConfig.
5
+ #
6
+ # This program and the accompanying materials are made available under
7
+ # the terms of the Eclipse Public License 2.0 which is available at
8
+ # <https://www.eclipse.org/legal/epl-2.0>, or alternative license
9
+ # terms made available by Alces Flight Ltd - please direct inquiries
10
+ # about licensing to licensing@alces-flight.com.
11
+ #
12
+ # FlightConfig is distributed in the hope that it will be useful, but
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
14
+ # IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS
15
+ # OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A
16
+ # PARTICULAR PURPOSE. See the Eclipse Public License 2.0 for more
17
+ # details.
18
+ #
19
+ # You should have received a copy of the Eclipse Public License 2.0
20
+ # along with FlightConfig. If not, see:
21
+ #
22
+ # https://opensource.org/licenses/EPL-2.0
23
+ #
24
+ # For more information on FlightConfig, please visit:
25
+ # https://github.com/openflighthpc/flight_config
26
+ #==============================================================================
27
+
28
+ module FightConfig
29
+ module HasIndices
30
+ def included(base)
31
+ base.extend(ClassMethods)
32
+ end
33
+
34
+ module ClassMethods
35
+ def has_indices(klass, &b)
36
+ @indices ||= []
37
+ @indices << [klass, b]
38
+ end
39
+
40
+ def indices
41
+ @indices ||= []
42
+ base = (defined?(super) ? super : [])
43
+ [*base, *@indices]
44
+ end
45
+ end
46
+
47
+ def generate_indices
48
+ self.class.indices.each do |klass, block|
49
+ instance_exec(klass.method(:create_or_update), &block)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,75 @@
1
+ #==============================================================================
2
+ # Copyright (C) 2019-present Alces Flight Ltd.
3
+ #
4
+ # This file is part of FlightConfig.
5
+ #
6
+ # This program and the accompanying materials are made available under
7
+ # the terms of the Eclipse Public License 2.0 which is available at
8
+ # <https://www.eclipse.org/legal/epl-2.0>, or alternative license
9
+ # terms made available by Alces Flight Ltd - please direct inquiries
10
+ # about licensing to licensing@alces-flight.com.
11
+ #
12
+ # FlightConfig is distributed in the hope that it will be useful, but
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
14
+ # IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS
15
+ # OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A
16
+ # PARTICULAR PURPOSE. See the Eclipse Public License 2.0 for more
17
+ # details.
18
+ #
19
+ # You should have received a copy of the Eclipse Public License 2.0
20
+ # along with FlightConfig. If not, see:
21
+ #
22
+ # https://opensource.org/licenses/EPL-2.0
23
+ #
24
+ # For more information on FlightConfig, please visit:
25
+ # https://github.com/openflighthpc/flight_config
26
+ #==============================================================================
27
+
28
+ require 'flight_config/reader'
29
+ require 'flight_config/globber'
30
+
31
+ module FlightConfig
32
+ module Indexable
33
+ include FlightConfig::Reader
34
+ include FlightConfig::Globber
35
+
36
+ def self.included(base)
37
+ base.extend(ClassMethods)
38
+ end
39
+
40
+ module ClassMethods
41
+ include FlightConfig::Reader::ClassMethods
42
+
43
+ def glob_read(*a)
44
+ super.reject do |index|
45
+ next if index.valid?
46
+ FileUtils.rm_f path
47
+ true
48
+ end
49
+ end
50
+
51
+ def create_or_update(*a)
52
+ new!(*a, read_mode: true) do |index|
53
+ Core.log(index, "Generating index")
54
+ FileUtils.mkdir_p File.dirname(index.path)
55
+ FileUtils.touch index.path
56
+ end
57
+ end
58
+ end
59
+
60
+ def valid?
61
+ raise NotImplementedError
62
+ end
63
+
64
+ def __data__
65
+ @__data__ ||= begin
66
+ if __read_mode__ && !valid?
67
+ FlightConfig::Core.log(self, 'Removing index')
68
+ FileUtils.rm_f path
69
+ raise InvalidIndex, 'Failed to load index as it is invalid'
70
+ end
71
+ {}
72
+ end
73
+ end
74
+ end
75
+ end
@@ -74,7 +74,7 @@ module FlightConfig
74
74
  mode = File.exists?(_path(*a))
75
75
  new!(*a, read_mode: mode) do |config|
76
76
  Updater.create_or_update(config, action: 'create_or_update', &b)
77
- end
77
+ end.tap { |c| c.generate_indices if c.respond_to?(:generate_indices) }
78
78
  end
79
79
 
80
80
  def create(*a, &b)
@@ -25,5 +25,5 @@
25
25
  # https://github.com/openflighthpc/flight_config
26
26
  #==============================================================================
27
27
  module FlightConfig
28
- VERSION = "0.2.0"
28
+ VERSION = "0.3.0"
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flight_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alces Flight Ltd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-22 00:00:00.000000000 Z
11
+ date: 2019-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-config
@@ -117,6 +117,8 @@ files:
117
117
  - lib/flight_config/deleter.rb
118
118
  - lib/flight_config/exceptions.rb
119
119
  - lib/flight_config/globber.rb
120
+ - lib/flight_config/has_indices.rb
121
+ - lib/flight_config/indexable.rb
120
122
  - lib/flight_config/links.rb
121
123
  - lib/flight_config/log.rb
122
124
  - lib/flight_config/patches/tty_config.rb