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 CHANGED
@@ -1,4 +1,6 @@
1
- Copyright 2013 YOURNAME
1
+ Copyright 2013 Dmytro Kovalov
2
+ dmytro.kovalov@gmail.com
3
+ http://dmytro.github.com
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining
4
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -13,7 +13,19 @@ Rails and ActiveResource models.
13
13
  Usage
14
14
  ===========
15
15
 
16
- Define your models like
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/lib/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
- self.all(args).map &:attributes
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
- raise "No such attribute '#{attribute}'" unless last(args).attributes.has_key? attribute
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_(.*)$/
@@ -1,3 +1,3 @@
1
1
  module NagiraActiveResource
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1
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-15 00:00:00.000000000 Z
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: ! ' 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
- '
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: []