canvas_oss-configuration 0.1.0.pre.alpha.pre.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ # Copyright 2018-02-24
2
+ # Remy BOISSEZON boissezon.remy@gmail.com
3
+ # Valentin PRODHOMME valentin@prodhomme.me
4
+ # Dylan TROLES chill3d@protonmail.com
5
+ # Alexandre ZANNI alexandre.zanni@engineer.com
6
+ #
7
+ # This software is governed by the CeCILL license under French law and
8
+ # abiding by the rules of distribution of free software. You can use,
9
+ # modify and/ or redistribute the software under the terms of the CeCILL
10
+ # license as circulated by CEA, CNRS and INRIA at the following URL
11
+ # "http://www.cecill.info".
12
+ #
13
+ # The fact that you are presently reading this means that you have had
14
+ # knowledge of the CeCILL license and that you accept its terms.
15
+
16
+ module CanvasOss
17
+ class Configuration
18
+ VERSION = '0.1.0'.freeze
19
+ end
20
+ end
@@ -0,0 +1,83 @@
1
+ # Copyright 2018-02-24
2
+ # Remy BOISSEZON boissezon.remy@gmail.com
3
+ # Valentin PRODHOMME valentin@prodhomme.me
4
+ # Dylan TROLES chill3d@protonmail.com
5
+ # Alexandre ZANNI alexandre.zanni@engineer.com
6
+ #
7
+ # This software is governed by the CeCILL license under French law and
8
+ # abiding by the rules of distribution of free software. You can use,
9
+ # modify and/ or redistribute the software under the terms of the CeCILL
10
+ # license as circulated by CEA, CNRS and INRIA at the following URL
11
+ # "http://www.cecill.info".
12
+ #
13
+ # The fact that you are presently reading this means that you have had
14
+ # knowledge of the CeCILL license and that you accept its terms.
15
+
16
+ require 'canvas_oss/configuration/version'
17
+ require 'canvas_oss/configuration/default_path'
18
+ require 'yaml'
19
+
20
+ module CanvasOss
21
+ # A class that open a CANVAS configuration file and parse it
22
+ # @example Load configuration from a CANVAS subsystem_name subsystem configuration file. A default file URI is assumed.
23
+ # => configuration = new Configuration(uri)
24
+ class Configuration
25
+ # :global contains CANVAS global configuration as a hash
26
+ attr_reader :global
27
+ # :subsys contains CANVAS subsystem configuration as a hash
28
+ attr_reader :subsys
29
+
30
+ SUBSYSTEM_NAME = 'subsystem_name'.freeze
31
+
32
+ # Load CANVAS configuration file from `uri` file or from default file
33
+ def initialize(uri = nil)
34
+ filename = File.realpath(File.join(DEFAULT_PATH, configuration_filename)) unless uri
35
+ filename = File.realpath(uri) if uri.is_a?(String) && uri.length.positive?
36
+ # Load YAML configuration file
37
+ documents = []
38
+ YAML.load_stream(File.read(filename)) do |document|
39
+ documents << document
40
+ end
41
+ # CANVAS Configuration file contain CANVAS global configuration
42
+ @global = validate_global(documents[0])
43
+ # CANVAS Configuration file contains CANVAS product-inventory subprocess configuration
44
+ @subsys = validate_subsys(documents[1])
45
+ end
46
+
47
+ # Ensure that CANVAS configuration contains at least some parameters
48
+ def validate_global(hash)
49
+ # CANVAS global configuration contains `canvas`
50
+ hash.key?(:canvas)
51
+ # CANVAS global configuration contains database parameters
52
+ hash[:canvas].key?(:database)
53
+ # CANVAS global configuration contains `canvas_configuration` database parameters
54
+ hash[:canvas][:database].key?(:canvas_configuration)
55
+ hash[:canvas][:database][:canvas_configuration].key?(:host)
56
+ hash[:canvas][:database][:canvas_configuration].key?(:port)
57
+ hash[:canvas][:database][:canvas_configuration].key?(:database)
58
+ hash[:canvas][:database][:canvas_configuration].key?(:username)
59
+ hash[:canvas][:database][:canvas_configuration].key?(:password)
60
+ # CANVAS global configuration contains `canvas_data` database parameters
61
+ hash[:canvas][:database].key?(:canvas_data)
62
+ hash[:canvas][:database][:canvas_data].key?(:host)
63
+ hash[:canvas][:database][:canvas_data].key?(:port)
64
+ hash[:canvas][:database][:canvas_data].key?(:database)
65
+ hash[:canvas][:database][:canvas_data].key?(:username)
66
+ hash[:canvas][:database][:canvas_data].key?(:password)
67
+ return hash[:canvas]
68
+ end
69
+
70
+ # Ensure that CANVAS subsystem configuration contains at least some parameters
71
+ # This method should be overloaded
72
+ def validate_subsys(hash)
73
+ # CANVAS global configuration contains `subsystem_name`
74
+ hash.key?(:subsystem_name)
75
+ return hash[:subsystem_name]
76
+ end
77
+
78
+ # Return configuration filename
79
+ def configuration_filename
80
+ return SUBSYSTEM_NAME + '.yml'
81
+ end
82
+ end
83
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: canvas_oss-configuration
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre.alpha.pre.7
5
+ platform: ruby
6
+ authors:
7
+ - "'Remy"
8
+ - BOISSEZON'
9
+ - "'Valentin"
10
+ - PRODHOMME'
11
+ - "'Dylan"
12
+ - TROLES'
13
+ - "'Alexandre"
14
+ - ZANNI'
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+ date: 2018-02-24 00:00:00.000000000 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: bundler
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ type: :development
28
+ prerelease: false
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ - !ruby/object:Gem::Dependency
35
+ name: minitest
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ type: :development
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ description: A little API to load and use CANVAS yaml configuration files
63
+ email:
64
+ - boissezon.remy@gmail.com
65
+ - valentin@prodhomme.me
66
+ - chill3d@protonmail.com
67
+ - alexandre.zanni@engineer.com
68
+ executables: []
69
+ extensions: []
70
+ extra_rdoc_files: []
71
+ files:
72
+ - ".rubocop.yml"
73
+ - ".travis.yml"
74
+ - Gemfile
75
+ - LICENSE.CECILL-EN
76
+ - LICENSE.CECILL-FR
77
+ - README.md
78
+ - Rakefile
79
+ - canvas_oss-configuration.gemspec
80
+ - files/canvas-configuration-sample.yml
81
+ - lib/canvas_oss/configuration.rb
82
+ - lib/canvas_oss/configuration/default_path.rb
83
+ - lib/canvas_oss/configuration/version.rb
84
+ homepage: https://github.com/canvas-oss/canvas-configuration
85
+ licenses:
86
+ - CECILL-2.1
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">"
100
+ - !ruby/object:Gem::Version
101
+ version: 1.3.1
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.7.6
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: API for used by CANVAS subsystems
108
+ test_files: []