fedux_org-stdlib 0.0.22 → 0.0.23

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -7,7 +7,7 @@ Gemfile.lock
7
7
  InstalledFiles
8
8
  _yardoc
9
9
  coverage
10
- doc/
10
+ doc/yard/
11
11
  lib/bundler/man
12
12
  pkg
13
13
  rdoc
data/.yardopts CHANGED
@@ -1,6 +1,9 @@
1
+ --output ./doc/yard
1
2
  --verbose
2
3
  -
3
4
  API-GUIDE.md
4
5
  CONTRIBUTIONS.md
5
6
  LICENSE.md
6
7
  RELEASE_NOTES.md
8
+ doc/logic_converters.md
9
+ doc/models.md
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # FeduxOrg::Stdlib
2
2
 
3
- TODO: Write a gem description
3
+ Gem with a lot of stuff which can be used in other libraries.
4
4
 
5
5
  ## Installation
6
6
 
@@ -16,9 +16,14 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install fedux_org-stdlib
18
18
 
19
- ## Usage
19
+ ## Further Reading
20
20
 
21
- You need to require the files... More is comming.
21
+ * {file:models.md Models}
22
+ * {file:logic_converters.md Logic Converters}
23
+ * {file:logging.md Logging} #TBD
24
+ * {file:filesystem.md Filesystem} #TBD
25
+ * {file:rake.md Rake Tasks} #TBD
26
+ * {file:environment.md Environment} #TBD
22
27
 
23
28
  ## Contributing
24
29
 
data/RELEASE_NOTES.md ADDED
@@ -0,0 +1,3 @@
1
+ Version 0.0.23
2
+ * + Add logic converters which can be used in puppet functions
3
+ * + Documentation
@@ -0,0 +1,27 @@
1
+ # FeduxOrg::Stdlib::LogicConverters
2
+
3
+ ## Usage
4
+
5
+ ### LogicConverter
6
+
7
+ ```ruby
8
+ require 'fedux_org/stdlib/logic_converters/logic_converter'
9
+ ```
10
+
11
+ ### YesNoConverter
12
+
13
+ ```ruby
14
+ require 'fedux_org/stdlib/logic_converters/yes_no_converter'
15
+ ```
16
+
17
+ ### TrueFalseConverter
18
+
19
+ ```ruby
20
+ require 'fedux_org/stdlib/logic_converters/true_false_converter'
21
+ ```
22
+
23
+ ### OnOffConverter
24
+
25
+ ```ruby
26
+ require 'fedux_org/stdlib/logic_converters/on_off_converter'
27
+ ```
data/doc/models.md ADDED
@@ -0,0 +1,29 @@
1
+ # FeduxOrg::Stdlib::Models
2
+
3
+ ## Usage
4
+
5
+ ### Models
6
+
7
+ This file requires all other files found below.
8
+
9
+ ```ruby
10
+ require 'fedux_org/stdlib/models'
11
+ ```
12
+
13
+ ### BaseModel
14
+
15
+ ```ruby
16
+ require 'fedux_org/stdlib/models/base_model'
17
+ ```
18
+
19
+ ### ClassBaseModel
20
+
21
+ ```ruby
22
+ require 'fedux_org/stdlib/models/class_based_model'
23
+ ```
24
+
25
+ ### FileSystemBasedModel
26
+
27
+ ```ruby
28
+ require 'fedux_org/stdlib/models/filesystem_based_model'
29
+ ```
@@ -1,4 +1,5 @@
1
1
  require 'open3'
2
+ require 'active_support/core_ext/string/inflections'
2
3
 
3
4
  require 'fedux_org/stdlib/environment'
4
5
  require 'fedux_org/stdlib/command/command_result'
@@ -46,6 +47,25 @@ module FeduxOrg
46
47
 
47
48
  result
48
49
  end
50
+
51
+ # Search for command
52
+ # @param [String] cmd
53
+ # name of command
54
+ #
55
+ # @return [String]
56
+ # path to command
57
+ def which(cmd)
58
+ return nil if cmd.blank?
59
+
60
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
61
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
62
+ exts.each do |ext|
63
+ exe = File.join(path, "#{cmd}#{ext}")
64
+ return exe if File.executable? exe
65
+ end
66
+ end
67
+ nil
49
68
  end
69
+
50
70
  end
51
71
  end
@@ -0,0 +1,12 @@
1
+ module FeduxOrg
2
+ module Stdlib
3
+ module LogicConverters
4
+ module Exceptions
5
+ #raised if invalid value was provided for conversion
6
+ class InvalidValue < Exception; end
7
+ #raised if invalid value was provided for conversion
8
+ class InvalidType < Exception; end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,37 @@
1
+ require 'fedux_org/stdlib/logic_converters/exceptions'
2
+
3
+ require 'fedux_org/stdlib/logic_converters/on_off_converter'
4
+ require 'fedux_org/stdlib/logic_converters/true_false_converter'
5
+ require 'fedux_org/stdlib/logic_converters/yes_no_converter'
6
+
7
+ module FeduxOrg
8
+ module Stdlib
9
+ module LogicConverters
10
+ class LogicConverter
11
+
12
+ # @param [String, Symbol] type (true_false, yes_no, on_off)
13
+ # choose the type of converter which should be used
14
+ def initialize(type)
15
+ @converter = case type.to_s
16
+ when 'true_false'
17
+ YesNoConverter.new
18
+ when 'yes_no'
19
+ TrueFalseConverter.new
20
+ when 'on_off'
21
+ OnOffConverter.new
22
+ else
23
+ raise FeduxOrg::Stdlib::LogicConverters::Exceptions::InvalidType, "Unknown type \"#{type}\" for logic converter. Valid types are \"true_false\", \"yes_no\" or \"on_off\"."
24
+ end
25
+ end
26
+
27
+ # @param [true,false] value
28
+ # the logic value which should be converted
29
+ # @return [String]
30
+ # the converted value
31
+ def parse( value )
32
+ @converter.parse( value )
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,27 @@
1
+ require 'fedux_org/stdlib/logic_converters/exceptions'
2
+
3
+ module FeduxOrg
4
+ module Stdlib
5
+ module LogicConverters
6
+ class OnOffConverter
7
+
8
+ # @param [true,false] value
9
+ # the logic value which should be converted
10
+ # @return [String]
11
+ # the converted value: true => on, false => off, '' => nil
12
+ def parse( value )
13
+ case value
14
+ when true
15
+ 'on'
16
+ when false
17
+ 'off'
18
+ when ''
19
+ nil
20
+ else
21
+ raise FeduxOrg::Stdlib::LogicConverters::Exceptions::InvalidValue, "Unknown logic value \"#{value}\"."
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require 'fedux_org/stdlib/logic_converters/exceptions'
2
+
3
+ module FeduxOrg
4
+ module Stdlib
5
+ module LogicConverters
6
+ class TrueFalseConverter
7
+
8
+ # @param [true,false] value
9
+ # the logic value which should be converted
10
+ # @return [String]
11
+ # the converted value: true => 'true', false => 'false', '' => nil
12
+ def parse( value )
13
+ case value
14
+ when true
15
+ 'true'
16
+ when false
17
+ 'false'
18
+ when ''
19
+ nil
20
+ else
21
+ raise FeduxOrg::Stdlib::LogicConverters::Exceptions::InvalidValue, "Unknown logic value \"#{value}\"."
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ require 'fedux_org/stdlib/logic_converters/exceptions'
2
+
3
+ module FeduxOrg
4
+ module Stdlib
5
+ module LogicConverters
6
+ class YesNoConverter
7
+ # @param [true,false] value
8
+ # the logic value which should be converted
9
+ # @return [String]
10
+ # the converted value: true => yes, false => no, '' => nil
11
+ def parse( value )
12
+ case value
13
+ when true
14
+ 'yes'
15
+ when false
16
+ 'no'
17
+ when ''
18
+ nil
19
+ else
20
+ raise FeduxOrg::Stdlib::LogicConverters::Exceptions::InvalidValue, "Unknown logic value \"#{value}\"."
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,6 +1,6 @@
1
1
  #main FeduxOrg
2
2
  module FeduxOrg
3
3
  module Stdlib
4
- VERSION = '0.0.22'
4
+ VERSION = '0.0.23'
5
5
  end
6
6
  end
@@ -0,0 +1,17 @@
1
+ require 'fedux_org/stdlib/logic_converters/on_off_converter'
2
+
3
+ describe FeduxOrg::Stdlib::LogicConverters::OnOffConverter do
4
+ let( :converter ) { FeduxOrg::Stdlib::LogicConverters::OnOffConverter.new }
5
+
6
+ context '#parse' do
7
+ it 'converts true to on' do
8
+ result = converter.parse( true )
9
+ expect( result ).to eq( 'on' )
10
+ end
11
+
12
+ it 'converts false to off' do
13
+ result = converter.parse( false )
14
+ expect( result ).to eq( 'off' )
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'fedux_org/stdlib/logic_converters/true_false_converter'
2
+
3
+ describe FeduxOrg::Stdlib::LogicConverters::TrueFalseConverter do
4
+ let( :converter ) { FeduxOrg::Stdlib::LogicConverters::TrueFalseConverter.new }
5
+
6
+ context '#parse' do
7
+ it 'converts true to "true"' do
8
+ result = converter.parse( true )
9
+ expect( result ).to eq( 'true' )
10
+ end
11
+
12
+ it 'converts false to "false"' do
13
+ result = converter.parse( false )
14
+ expect( result ).to eq( 'false' )
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'fedux_org/stdlib/logic_converters/yes_no_converter'
2
+
3
+ describe FeduxOrg::Stdlib::LogicConverters::YesNoConverter do
4
+ let( :converter ) { FeduxOrg::Stdlib::LogicConverters::YesNoConverter.new }
5
+
6
+ context '#parse' do
7
+ it 'converts true to "true"' do
8
+ result = converter.parse( true )
9
+ expect( result ).to eq( 'yes' )
10
+ end
11
+
12
+ it 'converts false to "false"' do
13
+ result = converter.parse( false )
14
+ expect( result ).to eq( 'no' )
15
+ end
16
+ end
17
+ end
@@ -244,7 +244,7 @@ describe Models::ClassBasedModel do
244
244
 
245
245
  expect {
246
246
  test_class.init
247
- }.to_not raise_error TestIt::Exceptions::InvalidTestClass
247
+ }.not_to raise_error
248
248
  end
249
249
 
250
250
  it "supports multiple methods to check for invalid instance and fails if one is missing." do
@@ -128,8 +128,8 @@ describe Models::FilesystemBasedModel do
128
128
  it "search for available instances in filesystem" do
129
129
  expect( klass.send(:find_files) ).to eq(
130
130
  [
131
- "/home/d/work/projects/fedux_org-stdlib/spec/examples/models/filesystem_based/find_files/abc.rb",
132
- "/home/d/work/projects/fedux_org-stdlib/spec/examples/models/filesystem_based/find_files/cde.rb",
131
+ File.join( examples_dir, 'models', 'filesystem_based', 'find_files', 'abc.rb' ),
132
+ File.join( examples_dir, 'models', 'filesystem_based', 'find_files', 'cde.rb' )
133
133
  ]
134
134
  )
135
135
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fedux_org-stdlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.22
4
+ version: 0.0.23
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-31 00:00:00.000000000 Z
12
+ date: 2013-10-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -74,7 +74,10 @@ files:
74
74
  - Gemfile
75
75
  - LICENSE.md
76
76
  - README.md
77
+ - RELEASE_NOTES.md
77
78
  - Rakefile
79
+ - doc/logic_converters.md
80
+ - doc/models.md
78
81
  - fedux_org-stdlib.gemspec
79
82
  - lib/fedux_org/stdlib.rb
80
83
  - lib/fedux_org/stdlib/command.rb
@@ -84,6 +87,11 @@ files:
84
87
  - lib/fedux_org/stdlib/filesystem/exceptions.rb
85
88
  - lib/fedux_org/stdlib/logging.rb
86
89
  - lib/fedux_org/stdlib/logging/logger.rb
90
+ - lib/fedux_org/stdlib/logic_converters/exceptions.rb
91
+ - lib/fedux_org/stdlib/logic_converters/logic_converter.rb
92
+ - lib/fedux_org/stdlib/logic_converters/on_off_converter.rb
93
+ - lib/fedux_org/stdlib/logic_converters/true_false_converter.rb
94
+ - lib/fedux_org/stdlib/logic_converters/yes_no_converter.rb
87
95
  - lib/fedux_org/stdlib/models.rb
88
96
  - lib/fedux_org/stdlib/models/base_model.rb
89
97
  - lib/fedux_org/stdlib/models/class_based_model.rb
@@ -125,6 +133,9 @@ files:
125
133
  - spec/examples/models/filesystem_based/find_files/abc.rb
126
134
  - spec/examples/models/filesystem_based/find_files/abc.rb.swp
127
135
  - spec/examples/models/filesystem_based/find_files/cde.rb
136
+ - spec/logic_converters/on_off_converter_spec.rb
137
+ - spec/logic_converters/true_false_converter_spec.rb
138
+ - spec/logic_converters/yes_no_converter_spec.rb
128
139
  - spec/models/base_model_spec.rb
129
140
  - spec/models/class_based_model_spec.rb
130
141
  - spec/models/filesystem_based_model_spec.rb
@@ -166,6 +177,9 @@ test_files:
166
177
  - spec/examples/models/filesystem_based/find_files/abc.rb
167
178
  - spec/examples/models/filesystem_based/find_files/abc.rb.swp
168
179
  - spec/examples/models/filesystem_based/find_files/cde.rb
180
+ - spec/logic_converters/on_off_converter_spec.rb
181
+ - spec/logic_converters/true_false_converter_spec.rb
182
+ - spec/logic_converters/yes_no_converter_spec.rb
169
183
  - spec/models/base_model_spec.rb
170
184
  - spec/models/class_based_model_spec.rb
171
185
  - spec/models/filesystem_based_model_spec.rb