nagira_active_resource 0.0.1

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.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ NagiraActiveResource
2
+ ======================
3
+
4
+ Rails side to Nagira API.
5
+
6
+ Since Nagira API in ActiveResource mode is not actually ActiveResource
7
+ compliant, there is a need to have component on the Rails side to
8
+ provide additional functionality to make it look like ActiveResource.
9
+
10
+ This module provides additional methods use Nagira together with
11
+ Rails and ActiveResource models.
12
+
13
+ Usage
14
+ ===========
15
+
16
+ Define your models like
17
+
18
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ruby
19
+ class Host < NagiraActiveResource::Host
20
+ self.site = "http://#{Rails::NAGIRA[:host] || localhost}:#{Rails::NAGIRA[:port] || 80}/_status/"
21
+ self.element_name = "_host"
22
+ end
23
+
24
+ class Service < ActiveResource::Base
25
+ self.site = "http://#{Rails::NAGIRA[:host] || localhost}:#{Rails::NAGIRA[:port] || 80}/_status/"
26
+ self.element_name = "service"
27
+ end
28
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29
+
30
+ Add initializer in `config/initialiazers`
31
+
32
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ruby
33
+ require 'nagira_active_resource/lib/nagira_active_resource'
34
+
35
+ Rails::NAGIRA={
36
+ host: 'localhost',
37
+ port: 4567
38
+ }
39
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
40
+
41
+ License
42
+ ===========
43
+
44
+ This project uses MIT-LICENSE.
45
+
46
+ Author
47
+ ===========
48
+
49
+ Dmytro Kovalov
50
+ http://dmytro.github.com
51
+ dmytro.kovalov@gmail.com
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'NagiraActiveResource'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+
38
+ task :default => :test
@@ -0,0 +1,76 @@
1
+ module NagiraActiveResource
2
+
3
+ ##
4
+ # Rails-like methods for Nagira host class
5
+ #
6
+ class Base < ActiveResource::Base
7
+
8
+ ##
9
+ # Return all objects as Hash
10
+ #
11
+ # @param [Hash] args Extra arguents like :host_name for nested
12
+ # objects (services) :params => !{'host_name' => 'viy'}
13
+ def self.to_h args={ }
14
+ self.all(args).map &:attributes
15
+ end
16
+
17
+ ##
18
+ # Find host by attribute and its value
19
+ #
20
+ # @param [String] attribute
21
+ #
22
+ # @param [String] value
23
+ #
24
+ # @param [Hash] args Extra arguents like :host_name for nested
25
+ # objects (services) :params => !{'host_name' => 'viy'}
26
+ #
27
+ def self.find_by attribute, value, args={ }
28
+ # TODO: .first does not work for services, since 1st is 'Check time'
29
+ raise "No such attribute '#{attribute}'" unless last(args).attributes.has_key? attribute
30
+ self.to_h(args).find { |x| x[attribute.to_s] == value.to_s }
31
+ end
32
+
33
+
34
+ ##
35
+ # Find hosts by attribute and its value
36
+ #
37
+ # @param [String] attribute
38
+ #
39
+ # @param [String] value
40
+ #
41
+ # @param [Hash] args Extra arguents like :host_name for nested
42
+ # objects (services) :params => !{'host_name' => 'viy'}
43
+ #
44
+ def self.find_all_by attribute, value, args={ }
45
+ raise "No such attribute '#{attribute}'" unless last(args).attributes.has_key? attribute
46
+ to_h(args).reject { |x| x[attribute.to_s] != value.to_s }
47
+ end
48
+
49
+ ##
50
+ # Dynamic methods for search
51
+ #
52
+ def self.method_missing sym, *args, &block
53
+ if sym.to_s =~ /^(find(_all)?)_by_(.*)$/
54
+ # message - either 'find' of 'find_all'
55
+ # resource - type of objects to search: host, hostgroup etc.
56
+ # attribute - name of the attribute to do search by: :host_name, :check_command
57
+ # @param *args String or Regexp to search objects
58
+ message,all,attribute = $1, $2, $3
59
+
60
+ value = args.shift
61
+
62
+ case all
63
+ when '_all'
64
+ find_all_by attribute, value, *args
65
+ when nil
66
+ find_by attribute, value, *args
67
+ end
68
+
69
+ else
70
+ super sym, *args, &block
71
+ end
72
+ end
73
+
74
+ end
75
+ end
76
+
@@ -0,0 +1,10 @@
1
+ module NagiraActiveResource
2
+
3
+ ##
4
+ # Rails-like methods for Nagira host class
5
+ #
6
+ class Host < ::NagiraActiveResource::Base
7
+
8
+ end
9
+ end
10
+
@@ -0,0 +1,10 @@
1
+ module NagiraActiveResource
2
+
3
+ ##
4
+ # Rails-like methods for Nagira service class
5
+ #
6
+ class Service < Base
7
+
8
+ end
9
+ end
10
+
@@ -0,0 +1,3 @@
1
+ module NagiraActiveResource
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,55 @@
1
+ =begin rdoc
2
+
3
+ NagiraActiveResource
4
+ ======================
5
+
6
+ Rails side to Nagira API.
7
+
8
+ Since Nagira API in ActiveResource mode is not actually ActiveResource
9
+ compliant, there is a need to have component on the Rails side to
10
+ provide additional functionality to make it look like ActiveResource.
11
+
12
+ This module provides additional methods use Nagira together with
13
+ Rails and ActiveResource models.
14
+
15
+ Usage
16
+ ===========
17
+
18
+ Define your models like
19
+
20
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ruby
21
+ class Host < NagiraActiveResource::Host
22
+ self.site = "http://#{Rails::NAGIRA[:host] || localhost}:#{Rails::NAGIRA[:port] || 80}/_status/"
23
+ self.element_name = "_host"
24
+ end
25
+
26
+ class Service < ActiveResource::Base
27
+ self.site = "http://#{Rails::NAGIRA[:host] || localhost}:#{Rails::NAGIRA[:port] || 80}/_status/"
28
+ self.element_name = "service"
29
+ end
30
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31
+
32
+ Add initializer in `config/initialiazers`
33
+
34
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ruby
35
+ require 'nagira_active_resource/lib/nagira_active_resource'
36
+
37
+ Rails::NAGIRA={
38
+ host: 'localhost',
39
+ port: 4567
40
+ }
41
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42
+
43
+ Classes
44
+ ===========
45
+
46
+ * {Host}
47
+ * {Service}
48
+
49
+ =end
50
+ module NagiraActiveResource
51
+ end
52
+
53
+ require_relative "nagira_active_resource/base"
54
+ require_relative "nagira_active_resource/host"
55
+ require_relative "nagira_active_resource/service"
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :nagira_active_resource do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nagira_active_resource
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dmytro Kovalov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.13
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.13
30
+ - !ruby/object:Gem::Dependency
31
+ name: nagira
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.2.7
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.2.7
46
+ - !ruby/object:Gem::Dependency
47
+ name: sqlite3
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: ! ' Since Nagira API in ActiveResource mode is not actually ActiveResource
63
+
64
+ compliant, there is a need to have component on the Rails side to
65
+
66
+ provide additional functionality to make it look like ActiveResource.
67
+
68
+
69
+ This module provides additional methods use Nagira together with
70
+
71
+ Rails and ActiveResource models.
72
+
73
+ '
74
+ email:
75
+ - dmytro.kovalov@gmail.com
76
+ executables: []
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - lib/nagira_active_resource/base.rb
81
+ - lib/nagira_active_resource/host.rb
82
+ - lib/nagira_active_resource/service.rb
83
+ - lib/nagira_active_resource/version.rb
84
+ - lib/nagira_active_resource.rb
85
+ - lib/tasks/nagira_active_resource_tasks.rake
86
+ - MIT-LICENSE
87
+ - Rakefile
88
+ - README.md
89
+ homepage: http://dmytro.github.com
90
+ licenses: []
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 1.8.25
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: Rails side to Nagira API.
113
+ test_files: []
114
+ has_rdoc: