langrove 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. data/.rspec +1 -0
  2. data/.rvmrc +62 -0
  3. data/.watchr +27 -0
  4. data/Gemfile +16 -0
  5. data/Gemfile.lock +61 -0
  6. data/Rakefile +24 -0
  7. data/functional/.gitignore +1 -0
  8. data/functional/bin/datagram +6 -0
  9. data/functional/config/.gitignore +0 -0
  10. data/functional/config/boot.rb +64 -0
  11. data/functional/config/daemons.yml +12 -0
  12. data/functional/config/environment.rb +28 -0
  13. data/functional/config/environments/development.rb +0 -0
  14. data/functional/config/environments/production.rb +0 -0
  15. data/functional/config/environments/test.rb +0 -0
  16. data/functional/lib/daemon/datagram.rb +21 -0
  17. data/functional/lib/handler/socket_to_file.rb +36 -0
  18. data/functional/lib/protocol/socket_to_file.rb +55 -0
  19. data/functional/libexec/daemon.rb +68 -0
  20. data/functional/log/.gitignore +3 -0
  21. data/functional/tmp/README +1 -0
  22. data/lib/langrove/_base.rb +26 -0
  23. data/lib/langrove/adaptor/base.rb +3 -0
  24. data/lib/langrove/adaptor/datagram.rb +27 -0
  25. data/lib/langrove/adaptor_base.rb +89 -0
  26. data/lib/langrove/client/base.rb +2 -0
  27. data/lib/langrove/client/datagram.rb +25 -0
  28. data/lib/langrove/client_base.rb +114 -0
  29. data/lib/langrove/daemon/base.rb +2 -0
  30. data/lib/langrove/daemon_base.rb +175 -0
  31. data/lib/langrove/ext/class_loader.rb +148 -0
  32. data/lib/langrove/ext/config_item.rb +34 -0
  33. data/lib/langrove/ext/config_loader.rb +16 -0
  34. data/lib/langrove/ext/fake_logger.rb +8 -0
  35. data/lib/langrove/ext/persistable.rb +103 -0
  36. data/lib/langrove/ext/string.rb +35 -0
  37. data/lib/langrove/ext.rb +7 -0
  38. data/lib/langrove/handler/base.rb +2 -0
  39. data/lib/langrove/handler_base.rb +141 -0
  40. data/lib/langrove/protocol/base.rb +2 -0
  41. data/lib/langrove/protocol/syslog.rb +32 -0
  42. data/lib/langrove/protocol_base.rb +32 -0
  43. data/lib/langrove/version.rb +3 -0
  44. data/lib/langrove.rb +1 -0
  45. data/spec/functional/daemon/datagram_spec.rb +115 -0
  46. data/spec/langrove/adaptor/datagram_spec.rb +6 -0
  47. data/spec/langrove/adaptor_base_spec.rb +48 -0
  48. data/spec/langrove/client/datagram_spec.rb +1 -0
  49. data/spec/langrove/client_base_spec.rb +5 -0
  50. data/spec/langrove/daemon_base_spec.rb +101 -0
  51. data/spec/langrove/ext/class_loader_spec.rb +83 -0
  52. data/spec/langrove/ext/config_item_spec.rb +81 -0
  53. data/spec/langrove/ext/config_loader_spec.rb +5 -0
  54. data/spec/langrove/ext/fake_logger_spec.rb +0 -0
  55. data/spec/langrove/ext/persistable_spec.rb +117 -0
  56. data/spec/langrove/ext/string_spec.rb +16 -0
  57. data/spec/langrove/handler_base_spec.rb +57 -0
  58. data/spec/langrove/protocol/syslog_spec.rb +45 -0
  59. data/spec/langrove/protocol_base_spec.rb +6 -0
  60. data/spec/todo_spec.rb +12 -0
  61. data/tmp/README +2 -0
  62. metadata +200 -0
@@ -0,0 +1,117 @@
1
+ require 'langrove/ext'
2
+
3
+ #
4
+ # This will likely change.
5
+ #
6
+
7
+ describe LanGrove::Persistable do
8
+
9
+ before :each do
10
+
11
+ class TestSerialization
12
+ attr_accessor :data
13
+ end
14
+
15
+ @class_instance = TestSerialization.new
16
+ @class_instance.data = 'VALUE'
17
+
18
+ @now = Time.now
19
+ @state_file = File.dirname( __FILE__ ) + "/../../../tmp/persistable.yml"
20
+
21
+ #
22
+ # delete the file
23
+ #
24
+ File.delete( @state_file ) if File.file?( @state_file )
25
+
26
+ @hash = {
27
+ 'tree' => {
28
+ 'type' => {
29
+ :thing1 => 1
30
+ }
31
+ },
32
+ :now => @now,
33
+ :class_instance => @class_instance
34
+ }
35
+
36
+ end
37
+
38
+ subject do
39
+
40
+ test = LanGrove::Persistable.new
41
+ test.instance_variable_set :@logger, (LanGrove::FakeLogger.new :silent)
42
+ test
43
+
44
+ end
45
+
46
+ it 'can serialize a hash to file' do
47
+
48
+ #
49
+ # install the hash to be 'stored'
50
+ #
51
+ subject.instance_variable_set( :@hash, @hash )
52
+ subject.store_hash( '@hash', @state_file )
53
+
54
+ #
55
+ # is the file there?
56
+ #
57
+ File.file?( @state_file ).should == true
58
+
59
+ end
60
+
61
+ context 'can de-serialize a hash' do
62
+
63
+ before :each do
64
+
65
+ #
66
+ # set up the file to read
67
+ #
68
+ subject.instance_variable_set( :@hash, @hash )
69
+ subject.store_hash( '@hash', @state_file )
70
+
71
+ #
72
+ # replace the hash with another containg other things
73
+ #
74
+ subject.instance_variable_set( :@hash, { 'thing2' => 2 } )
75
+
76
+ end
77
+
78
+ it 'from file' do
79
+
80
+ subject.load_hash( '@hash', @state_file )
81
+
82
+ hash = subject.instance_variable_get( :@hash )
83
+ hash['tree']['type'][:thing1].should == 1
84
+
85
+ end
86
+
87
+ it 'from file and re-instanciate as correct native ruby classes' do
88
+
89
+ subject.load_hash( '@hash', @state_file )
90
+ hash = subject.instance_variable_get( :@hash )
91
+
92
+ hash[:now].should be_a( Time )
93
+ hash[:now].should == @now
94
+
95
+ end
96
+
97
+ it 'from file and re-instanciate as correct userland ruby classes' do
98
+
99
+ subject.load_hash( '@hash', @state_file )
100
+ hash = subject.instance_variable_get( :@hash )
101
+
102
+ hash[:class_instance].should be_a( TestSerialization )
103
+ hash[:class_instance].data.should == 'VALUE'
104
+
105
+ end
106
+
107
+ it 'from file and not overrwrite other variables in the hash' do
108
+
109
+ subject.load_hash( '@hash', @state_file )
110
+ hash = subject.instance_variable_get( :@hash )
111
+
112
+ hash['tree']['type'][:thing1].should == 1
113
+ hash['thing2'].should == 2
114
+
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,16 @@
1
+ require 'langrove/ext'
2
+ describe String do
3
+
4
+ it 'has been extended to camelize' do
5
+
6
+ "this_is_a_class_file_name".camelize.should == "ThisIsAClassFileName"
7
+
8
+ end
9
+
10
+ it 'has been extended to underscore' do
11
+
12
+ "ThisIsAClassName".underscore.should == "this_is_a_class_name"
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,57 @@
1
+ require 'langrove'
2
+
3
+ describe LanGrove::Handler::Base do
4
+
5
+ before :each do
6
+
7
+ @logger = LanGrove::FakeLogger.new :silent
8
+
9
+ @daemon_name = 'test_daemon'
10
+
11
+ @config = {
12
+
13
+ :daemons => {
14
+
15
+ @daemon_name => {
16
+
17
+ :handler => {
18
+
19
+ :collection => 'Base'
20
+ }
21
+ }
22
+ }
23
+ }
24
+
25
+ end
26
+
27
+ context 'uses a protocol' do
28
+
29
+ it 'that defaults to an instance of Protocol::Base' do
30
+
31
+ test = LanGrove::Handler::Base.new( @config, @daemon_name, @logger )
32
+
33
+ protocol = test.instance_variable_get( :@protocol )
34
+
35
+ protocol.should == LanGrove::Protocol::Base
36
+
37
+ end
38
+
39
+ it 'as defined by the config_hash' do
40
+
41
+ @config[:daemons][@daemon_name][:handler][:protocol] = 'MedievalLanternMorse'
42
+
43
+ expect {
44
+
45
+ test = LanGrove::Handler::Base.new( @config, @daemon_name, @logger )
46
+
47
+ }.to raise_error( LanGrove::ClassLoaderException,
48
+
49
+ "no such file to load -- protocol/medieval_lantern_morse.rb"
50
+
51
+ )
52
+
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,45 @@
1
+ require 'langrove/protocol/syslog'
2
+ require 'date'
3
+
4
+ describe LanGrove::Protocol::Syslog.new do
5
+
6
+ before :each do
7
+
8
+ @message1 = "<00>Apr 4 11:00:06 host program[321]: Message with: 1"
9
+ @message2 = "<00>Jun 25 16:15:15 host.name.co.za tag[3241]: Message with: 2"
10
+
11
+ end
12
+
13
+ pending 'it decodes the loglevel'
14
+
15
+ pending 'it supports tagless and pidless'
16
+
17
+ it 'decodes a timestamp' do
18
+
19
+ subject.decode( @message1 )[:timestamp].should == DateTime.parse( 'Apr 4 11:00:06' )
20
+ subject.decode( @message2 )[:timestamp].should == DateTime.parse( 'Jun 25 16:15:15' )
21
+
22
+ end
23
+
24
+ it 'decodes a hostname corrected for prepended vlanN' do
25
+
26
+ subject.decode( @message1 )[:hostname].should == 'host'
27
+ subject.decode( @message2 )[:hostname].should == 'host.name.co.za'
28
+
29
+ end
30
+
31
+ it 'decodes the log tag' do
32
+
33
+ subject.decode( @message1 )[:tag].should == 'program[321]'
34
+ subject.decode( @message2 )[:tag].should == 'tag[3241]'
35
+
36
+ end
37
+
38
+ it 'decodes the log event' do
39
+
40
+ subject.decode( @message1 )[:event].should == 'Message with: 1'
41
+ subject.decode( @message2 )[:event].should == 'Message with: 2'
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,6 @@
1
+ require 'langrove'
2
+
3
+ describe LanGrove::Protocol::Base do
4
+
5
+
6
+ end
data/spec/todo_spec.rb ADDED
@@ -0,0 +1,12 @@
1
+ describe 'Outstanding:' do
2
+
3
+ pending 'Symbolize the config keys'
4
+ pending 'make a langrove --create for developers to recursively copy ./functional from the gem install dir as a base for getting the framework up and running'
5
+ pending 'cut and publish'
6
+
7
+
8
+
9
+
10
+ pending 'rdoc'
11
+
12
+ end
data/tmp/README ADDED
@@ -0,0 +1,2 @@
1
+ Certain test write files into here
2
+
metadata ADDED
@@ -0,0 +1,200 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: langrove
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Richard
9
+ - ''
10
+ - ''
11
+ - ''
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+ date: 2012-04-23 00:00:00.000000000Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: watchr
19
+ requirement: &70352257905620 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ! '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ type: :development
26
+ prerelease: false
27
+ version_requirements: *70352257905620
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ requirement: &70352257905120 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: '2.9'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: *70352257905120
39
+ - !ruby/object:Gem::Dependency
40
+ name: rake
41
+ requirement: &70352257904600 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '1.8'
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: 0.8.7
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: *70352257904600
53
+ - !ruby/object:Gem::Dependency
54
+ name: eventmachine
55
+ requirement: &70352257903860 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: '0.12'
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: 0.12.10
64
+ type: :runtime
65
+ prerelease: false
66
+ version_requirements: *70352257903860
67
+ - !ruby/object:Gem::Dependency
68
+ name: em-http-request
69
+ requirement: &70352257903120 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ version: '0.3'
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.3.0
78
+ type: :runtime
79
+ prerelease: false
80
+ version_requirements: *70352257903120
81
+ - !ruby/object:Gem::Dependency
82
+ name: daemon-kit
83
+ requirement: &70352257902380 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ version: '0.1'
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: 0.1.8.2
92
+ type: :runtime
93
+ prerelease: false
94
+ version_requirements: *70352257902380
95
+ - !ruby/object:Gem::Dependency
96
+ name: resque
97
+ requirement: &70352257901640 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ version: '1.20'
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: 1.20.0
106
+ type: :runtime
107
+ prerelease: false
108
+ version_requirements: *70352257901640
109
+ description: ''
110
+ email: richard@clue.co.za
111
+ executables: []
112
+ extensions: []
113
+ extra_rdoc_files: []
114
+ files:
115
+ - Gemfile
116
+ - Gemfile.lock
117
+ - .rspec
118
+ - .rvmrc
119
+ - .watchr
120
+ - Rakefile
121
+ - functional/.gitignore
122
+ - functional/bin/datagram
123
+ - functional/config/.gitignore
124
+ - functional/config/boot.rb
125
+ - functional/config/daemons.yml
126
+ - functional/config/environment.rb
127
+ - functional/config/environments/development.rb
128
+ - functional/config/environments/production.rb
129
+ - functional/config/environments/test.rb
130
+ - functional/lib/daemon/datagram.rb
131
+ - functional/lib/handler/socket_to_file.rb
132
+ - functional/lib/protocol/socket_to_file.rb
133
+ - functional/libexec/daemon.rb
134
+ - functional/log/.gitignore
135
+ - functional/tmp/README
136
+ - lib/langrove/_base.rb
137
+ - lib/langrove/adaptor/base.rb
138
+ - lib/langrove/adaptor/datagram.rb
139
+ - lib/langrove/adaptor_base.rb
140
+ - lib/langrove/client/base.rb
141
+ - lib/langrove/client/datagram.rb
142
+ - lib/langrove/client_base.rb
143
+ - lib/langrove/daemon/base.rb
144
+ - lib/langrove/daemon_base.rb
145
+ - lib/langrove/ext/class_loader.rb
146
+ - lib/langrove/ext/config_item.rb
147
+ - lib/langrove/ext/config_loader.rb
148
+ - lib/langrove/ext/fake_logger.rb
149
+ - lib/langrove/ext/persistable.rb
150
+ - lib/langrove/ext/string.rb
151
+ - lib/langrove/ext.rb
152
+ - lib/langrove/handler/base.rb
153
+ - lib/langrove/handler_base.rb
154
+ - lib/langrove/protocol/base.rb
155
+ - lib/langrove/protocol/syslog.rb
156
+ - lib/langrove/protocol_base.rb
157
+ - lib/langrove/version.rb
158
+ - lib/langrove.rb
159
+ - spec/functional/daemon/datagram_spec.rb
160
+ - spec/langrove/adaptor/datagram_spec.rb
161
+ - spec/langrove/adaptor_base_spec.rb
162
+ - spec/langrove/client/datagram_spec.rb
163
+ - spec/langrove/client_base_spec.rb
164
+ - spec/langrove/daemon_base_spec.rb
165
+ - spec/langrove/ext/class_loader_spec.rb
166
+ - spec/langrove/ext/config_item_spec.rb
167
+ - spec/langrove/ext/config_loader_spec.rb
168
+ - spec/langrove/ext/fake_logger_spec.rb
169
+ - spec/langrove/ext/persistable_spec.rb
170
+ - spec/langrove/ext/string_spec.rb
171
+ - spec/langrove/handler_base_spec.rb
172
+ - spec/langrove/protocol/syslog_spec.rb
173
+ - spec/langrove/protocol_base_spec.rb
174
+ - spec/todo_spec.rb
175
+ - tmp/README
176
+ homepage: ''
177
+ licenses: []
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ none: false
184
+ requirements:
185
+ - - ! '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
189
+ none: false
190
+ requirements:
191
+ - - ! '>='
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ requirements: []
195
+ rubyforge_project:
196
+ rubygems_version: 1.8.10
197
+ signing_key:
198
+ specification_version: 3
199
+ summary: eventmachine based networked daemon framework
200
+ test_files: []