right_support 1.3.3 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -105,4 +105,29 @@ Profile your compute-heavy and network activities using a Stats::Activity counte
105
105
  stats.finish
106
106
  end
107
107
 
108
- puts "Only %.1f lines/sec? You are a slow typist!" % [stats.avg_rate]
108
+ puts "Only %.1f lines/sec? You are a slow typist!" % [stats.avg_rate]
109
+
110
+ === Configuration
111
+
112
+ RightSupport::Config contains functionality, which provides possibility
113
+ to use human-readable yaml configuration files. For example, you have following yaml
114
+ file '/tmp/features_config.yml', with content:
115
+
116
+ eat:
117
+ khlav kalash: YES!
118
+ speak:
119
+ klingonese: false
120
+ belarusian: true
121
+
122
+ Then, if you would add configuration in you class, like:
123
+
124
+ class SweetestClass
125
+ CONFIG = RightSupport::Config.features('/tmp/features_config.yml')
126
+ end
127
+
128
+ * RightSupport::Config.features receives file` path, io or string.
129
+
130
+ Now you can call CONFIG['feature_group']['feature'], like:
131
+
132
+ * SweetestClass::CONFIG['eat']['khlav kalash'] would return 'YES!'
133
+ * SweetestClass::CONFIG['speak']['belarusian'] would return true
data/lib/right_support.rb CHANGED
@@ -3,6 +3,7 @@ require 'thread'
3
3
 
4
4
  require 'right_support/ruby'
5
5
  require 'right_support/crypto'
6
+ require 'right_support/config'
6
7
  require 'right_support/db'
7
8
  require 'right_support/log'
8
9
  require 'right_support/net'
@@ -0,0 +1,34 @@
1
+ #
2
+ # Copyright (c) 2012 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ module RightSupport
24
+ #
25
+ # A namespace for configuration tools.
26
+ #
27
+ module Config
28
+
29
+ end
30
+ end
31
+
32
+ require 'right_support/config/feature_set'
33
+ require 'right_support/config/yaml_config'
34
+ require 'right_support/config/recursive_true_class'
@@ -0,0 +1,95 @@
1
+ #
2
+ # Copyright (c) 2012 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ module RightSupport::Config
24
+
25
+ # Returns new instance of FeatureSet class,
26
+ # with loaded from config_source configuration
27
+ #
28
+ # === Parameters
29
+ # config_source(IO|String):: File` path, IO or raw yaml.
30
+ #
31
+ # === Return
32
+ # (FeatureSet):: new instance of FeatureSet class
33
+ def self.features(config_source)
34
+ return FeatureSet.new(config_source)
35
+ end
36
+
37
+ class FeatureSet
38
+
39
+ attr_accessor :configuration_source
40
+ attr_accessor :configuration
41
+
42
+ # Create features configuration object
43
+ #
44
+ # === Parameters
45
+ # cfg_source(IO|String):: File path, IO or raw yaml.
46
+ def initialize(cfg_source)
47
+ @configuration = load(cfg_source)
48
+ end
49
+
50
+ # Returns configuration value
51
+ #
52
+ # === Parameters
53
+ # feature_group(String):: Feature group name
54
+ # feature(String|nil):: Feature name
55
+ #
56
+ # === Return
57
+ # (String|Boolean):: Configuration value
58
+ def [](feature_group, feature=nil)
59
+ return_value = true
60
+ if @configuration[feature_group]
61
+ if feature == nil
62
+ return_value = @configuration[feature_group]
63
+ else
64
+ return_value = @configuration[feature_group][feature]
65
+ end
66
+ else
67
+ return_value = RecursiveTrueClass.new
68
+ end
69
+ return_value = true if return_value == nil
70
+ return_value
71
+ end
72
+
73
+ # Load configuration source
74
+ #
75
+ # === Parameters
76
+ # something(IO|String|Hash):: File path, IO, raw YAML string, or a pre-loaded Hash
77
+ #
78
+ # === Return
79
+ # (Hash|nil):: Loaded yaml file
80
+ #
81
+ # === Raise
82
+ # (ArgumentError):: If configuration source can`t be loaded
83
+ def load(something)
84
+ return_value = nil
85
+ @configuration_source = something
86
+ raise ArgumentError, "Can't coerce #{something} into YAML/Hash" unless (return_value = YAMLConfig.read(something))
87
+ return_value
88
+ end
89
+
90
+ end
91
+
92
+ # Temporary alias for FeatureSet class, to avoid disrupting downstream development
93
+ Feature = FeatureSet
94
+
95
+ end
@@ -0,0 +1,63 @@
1
+ #
2
+ # Copyright (c) 2012 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ module RightSupport::Config
24
+
25
+ # Recursive(according to []) implementation of TrueClass.
26
+ # To use, just do: true1 = RecTrueClass.new
27
+ # now you can do true1['a'], true1['a']['b'], ...
28
+ # and it will return
29
+ class RecursiveTrueClass
30
+
31
+ def initialize
32
+ @value = true
33
+ end
34
+
35
+ def [](something)
36
+ self
37
+ end
38
+
39
+ # supporting standart boolean
40
+ # opeimplementation
41
+ def ==(other)
42
+ @value==other
43
+ end
44
+
45
+ def &(other)
46
+ @value & other
47
+ end
48
+
49
+ def ^(other)
50
+ @value ^ other
51
+ end
52
+
53
+ def to_s
54
+ @value.to_s
55
+ end
56
+
57
+ def |(other)
58
+ @value | other
59
+ end
60
+
61
+ end
62
+
63
+ end
@@ -0,0 +1,62 @@
1
+ #
2
+ # Copyright (c) 2012 RightScale Inc
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ require 'yaml'
23
+
24
+ module RightSupport::Config
25
+
26
+ # Helper that encapsulates logic for loading YAML configuration hashes from various sources
27
+ # which can include strings, IO objects, or already-loaded YAML in the form of a Hash.
28
+ module YAMLConfig
29
+
30
+ class << self
31
+
32
+ # Load yaml source
33
+ #
34
+ # === Parameters
35
+ # something(IO|String|Hash):: File path, IO, raw YAML string, or a pre-loaded Hash
36
+ #
37
+ # === Returns
38
+ # (Boolean|Hash):: Loaded yaml file or false if a RuntimeError occurred while loading
39
+ def read(something)
40
+ return_value = false
41
+
42
+ begin
43
+ if something.kind_of?(Hash)
44
+ return_value = something
45
+ elsif File.exists?(something)
46
+ return_value = YAML.load_file(something)
47
+ else
48
+ return_value = YAML.load(something)
49
+ end
50
+ raise unless return_value.kind_of?(Hash)
51
+ rescue
52
+ return_value = false
53
+ end
54
+
55
+ return_value
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+
62
+ end
@@ -7,8 +7,8 @@ spec = Gem::Specification.new do |s|
7
7
  s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
8
8
 
9
9
  s.name = 'right_support'
10
- s.version = '1.3.3'
11
- s.date = '2012-03-23'
10
+ s.version = '1.4.0'
11
+ s.date = '2012-04-12'
12
12
 
13
13
  s.authors = ['Tony Spataro', 'Sergey Sergyenko', 'Ryan Williamson', 'Lee Kirchhoff']
14
14
  s.email = 'support@rightscale.com'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: right_support
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 3
9
- - 3
10
- version: 1.3.3
8
+ - 4
9
+ - 0
10
+ version: 1.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tony Spataro
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2012-03-23 00:00:00 -07:00
21
+ date: 2012-04-12 00:00:00 -07:00
22
22
  default_executable:
23
23
  dependencies: []
24
24
 
@@ -34,6 +34,10 @@ files:
34
34
  - LICENSE
35
35
  - README.rdoc
36
36
  - lib/right_support.rb
37
+ - lib/right_support/config.rb
38
+ - lib/right_support/config/feature_set.rb
39
+ - lib/right_support/config/recursive_true_class.rb
40
+ - lib/right_support/config/yaml_config.rb
37
41
  - lib/right_support/crypto.rb
38
42
  - lib/right_support/crypto/signed_hash.rb
39
43
  - lib/right_support/db.rb