Class: ConfigKit::ConfigData
Defined Under Namespace
Classes: DataError, DataMissingRequireFieldError, MetadataError, MetadataMissingRequireFieldError
Instance Method Summary
collapse
Methods inherited from SlashedHash
#inspect, symbolize, #to_hash
Methods inherited from Hash
#deep_merge
Constructor Details
#initialize(config_data, name, api_version = 'v1.0', kind = 'config_kit') ⇒ ConfigData
Returns a new instance of ConfigData.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/config_kit/config_data.rb', line 11
def initialize(config_data, name, api_version='v1.0', kind='config_kit')
@defined_api_version=api_version
@defined_kind = kind
@metadata_required_fields = ['api_version', 'kind']
@data_required_fields = ['version', 'namespace']
@config_data = config_data
@name = name
check_metadata
check_data
@binded_data = binding_data
super(@binded_data)
end
|
Instance Method Details
#api_version ⇒ Object
84
85
86
|
# File 'lib/config_kit/config_data.rb', line 84
def api_version
@config_data['api_version']
end
|
#binding_data ⇒ Object
/v1/config_kit/axle/v1.0/database => mysql
58
59
60
|
# File 'lib/config_kit/config_data.rb', line 58
def binding_data
binding_kind
end
|
#binding_kind ⇒ Object
50
51
52
|
# File 'lib/config_kit/config_data.rb', line 50
def binding_kind
{ kind => binding_name }
end
|
#binding_name ⇒ Object
46
47
48
|
# File 'lib/config_kit/config_data.rb', line 46
def binding_name
{ @name => binding_version }
end
|
#binding_version ⇒ Object
42
43
44
|
# File 'lib/config_kit/config_data.rb', line 42
def binding_version
{ data_version => data }
end
|
#check_data ⇒ Object
26
27
28
29
30
31
|
# File 'lib/config_kit/config_data.rb', line 26
def check_data
raise DataError, 'Config Kit Support Hash Data Formate ONLY.' unless data.is_a?(Hash)
@data_required_fields.each do |f|
raise DataMissingRequireFieldError,"Config Kit Raw data missing require field #{f} " unless data.has_key?(f)
end
end
|
33
34
35
36
37
38
39
40
|
# File 'lib/config_kit/config_data.rb', line 33
def check_metadata
raise MetadataError, 'Config Kit Support Hash Data Formate ONLY.' unless @config_data.is_a?(Hash)
@metadata_required_fields.each do |f|
raise MetadataMissingRequireFieldError,"Config Kit Meta data missing require field #{f} " unless @config_data.has_key?(f)
end
raise MetadataError, "Config Kit API Version metadata mis-match #{@config_data['api_version']}." unless support_api?
raise MetadataError, "Config Kit Kind metadate mis-match #{@config_data['kind']}." unless same_kind?
end
|
#data ⇒ Object
80
81
82
|
# File 'lib/config_kit/config_data.rb', line 80
def data
@config_data && @config_data[@name]
end
|
#data_cs ⇒ Object
76
77
78
|
# File 'lib/config_kit/config_data.rb', line 76
def data_cs
nil
end
|
#data_version ⇒ Object
70
71
72
73
74
|
# File 'lib/config_kit/config_data.rb', line 70
def data_version
_version = @config_data && @config_data[@name] && @config_data[@name]['version']
version = _version[0] == 'v' ? _version : "v#{_version}"
version
end
|
#kind ⇒ Object
88
89
90
|
# File 'lib/config_kit/config_data.rb', line 88
def kind
@config_data['kind']
end
|
#same_kind? ⇒ Boolean
62
63
64
|
# File 'lib/config_kit/config_data.rb', line 62
def same_kind?
@defined_kind == kind
end
|
#support_api? ⇒ Boolean
66
67
68
|
# File 'lib/config_kit/config_data.rb', line 66
def support_api?
@defined_api_version == api_version
end
|