nagira_active_resource 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +3 -1
- data/README.md +26 -4
- data/lib/nagira_active_resource/base.rb +24 -3
- data/lib/nagira_active_resource/version.rb +1 -1
- metadata +7 -14
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -13,7 +13,19 @@ Rails and ActiveResource models.
|
|
13
13
|
Usage
|
14
14
|
===========
|
15
15
|
|
16
|
-
|
16
|
+
* Install gem
|
17
|
+
|
18
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~bash
|
19
|
+
gem install nagira_active_resource
|
20
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
21
|
+
|
22
|
+
or add it to `Gemfile`
|
23
|
+
|
24
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ruby
|
25
|
+
gem 'nagira_active_resource'
|
26
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
27
|
+
|
28
|
+
* Define your models
|
17
29
|
|
18
30
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ruby
|
19
31
|
class Host < NagiraActiveResource::Host
|
@@ -27,10 +39,10 @@ class Service < ActiveResource::Base
|
|
27
39
|
end
|
28
40
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
29
41
|
|
30
|
-
Add initializer in `config/initialiazers`
|
42
|
+
* Add initializer in `config/initialiazers`
|
31
43
|
|
32
44
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ruby
|
33
|
-
require 'nagira_active_resource
|
45
|
+
require 'nagira_active_resource'
|
34
46
|
|
35
47
|
Rails::NAGIRA={
|
36
48
|
host: 'localhost',
|
@@ -38,14 +50,24 @@ Rails::NAGIRA={
|
|
38
50
|
}
|
39
51
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
40
52
|
|
53
|
+
See also
|
54
|
+
===========
|
55
|
+
|
56
|
+
Nagira API
|
57
|
+
|
58
|
+
* [http://dmytro.github.com/nagira](http://dmytro.github.com/nagira)
|
59
|
+
* [https://github.com/dmytro/nagira](https://github.com/dmytro/nagira)
|
60
|
+
|
41
61
|
License
|
42
62
|
===========
|
43
63
|
|
44
|
-
This project uses MIT-LICENSE.
|
64
|
+
This project uses {file:MIT-LICENSE}.
|
45
65
|
|
46
66
|
Author
|
47
67
|
===========
|
48
68
|
|
49
69
|
Dmytro Kovalov
|
70
|
+
|
50
71
|
http://dmytro.github.com
|
72
|
+
|
51
73
|
dmytro.kovalov@gmail.com
|
@@ -5,13 +5,19 @@ module NagiraActiveResource
|
|
5
5
|
#
|
6
6
|
class Base < ActiveResource::Base
|
7
7
|
|
8
|
+
@@logger = ActiveRecord::Base.logger
|
8
9
|
##
|
9
10
|
# Return all objects as Hash
|
10
11
|
#
|
11
12
|
# @param [Hash] args Extra arguents like :host_name for nested
|
12
13
|
# objects (services) :params => !{'host_name' => 'viy'}
|
13
14
|
def self.to_h args={ }
|
14
|
-
|
15
|
+
begin
|
16
|
+
self.all(args).map &:attributes
|
17
|
+
rescue NoMethodError => e
|
18
|
+
logger.warn "Search did not return any results: #{args}, #{caller[0]}"
|
19
|
+
{ }
|
20
|
+
end
|
15
21
|
end
|
16
22
|
|
17
23
|
##
|
@@ -26,7 +32,11 @@ module NagiraActiveResource
|
|
26
32
|
#
|
27
33
|
def self.find_by attribute, value, args={ }
|
28
34
|
# TODO: .first does not work for services, since 1st is 'Check time'
|
29
|
-
|
35
|
+
begin
|
36
|
+
@@logger.error "No such attribute '#{attribute}'" unless self.last(args).attributes.has_key? attribute
|
37
|
+
rescue
|
38
|
+
@@logger.info self
|
39
|
+
end
|
30
40
|
self.to_h(args).find { |x| x[attribute.to_s] == value.to_s }
|
31
41
|
end
|
32
42
|
|
@@ -45,9 +55,20 @@ module NagiraActiveResource
|
|
45
55
|
raise "No such attribute '#{attribute}'" unless last(args).attributes.has_key? attribute
|
46
56
|
to_h(args).reject { |x| x[attribute.to_s] != value.to_s }
|
47
57
|
end
|
58
|
+
|
59
|
+
## TODO
|
60
|
+
# Instance level methods - attribute accessors
|
61
|
+
#
|
62
|
+
# def method_missing sym, *args, &block
|
63
|
+
# if self.has_key? sym
|
64
|
+
# self[sym]
|
65
|
+
# else
|
66
|
+
# super sym, *args, &block
|
67
|
+
# end
|
68
|
+
# end
|
48
69
|
|
49
70
|
##
|
50
|
-
# Dynamic methods for search
|
71
|
+
# Dynamic methods for search - class level methods
|
51
72
|
#
|
52
73
|
def self.method_missing sym, *args, &block
|
53
74
|
if sym.to_s =~ /^(find(_all)?)_by_(.*)$/
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nagira_active_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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-04-
|
12
|
+
date: 2013-04-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -59,18 +59,11 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
-
description: !
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
This module provides additional methods use Nagira together with
|
70
|
-
|
71
|
-
Rails and ActiveResource models.
|
72
|
-
|
73
|
-
'
|
62
|
+
description: ! " Rails side to Nagira API. \nSince Nagira API in ActiveResource mode
|
63
|
+
is not actually ActiveResource\ncompliant, there is a need to have component on
|
64
|
+
the Rails side to\nprovide additional functionality to make it look like ActiveResource.\n\nThis
|
65
|
+
module provides additional methods use Nagira together with\nRails and ActiveResource
|
66
|
+
models.\n"
|
74
67
|
email:
|
75
68
|
- dmytro.kovalov@gmail.com
|
76
69
|
executables: []
|