architect4r 0.4 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -68,6 +68,22 @@ Quick Start
68
68
  Fanship.new(@user, @instrument, { :reason => 'Because I like you' })
69
69
 
70
70
 
71
+ Logging
72
+ -------
73
+
74
+ In order to log the debug output from architect4r to a logfile, just override the default
75
+ logger instance. If you are using rails, you might wanna add this to an initializer:
76
+
77
+
78
+ # Create a logger instance
79
+ file = File.open('log/output.log', File::WRONLY | File::APPEND)
80
+ logger = Logger.new(file, 'daily')
81
+ logger.level = Logger::DEBUG
82
+
83
+ # Set architect4r logger
84
+ Architect4r.logger = logger
85
+
86
+
71
87
  Development
72
88
  -----------
73
89
 
@@ -1,5 +1,11 @@
1
1
  # Release Notes
2
2
 
3
+ ## v0.4.1
4
+
5
+ * Allow logging of cypher queries for easier debugging
6
+
7
+ * Add proper node comparison, so we can detect multiple instances of the same node.
8
+
3
9
  ## v0.4
4
10
 
5
11
  * Upgrade to neo4j 1.6 GA
@@ -3,6 +3,11 @@
3
3
  #
4
4
  require 'architect4r/version'
5
5
 
6
+ #
7
+ # External libraries
8
+ #
9
+ require 'logger'
10
+
6
11
  #
7
12
  # Extensions
8
13
  #
@@ -57,6 +62,14 @@ end
57
62
  #
58
63
  module Architect4r
59
64
 
65
+ def self.logger
66
+ @log ||= Logger.new(STDOUT)
67
+ end
68
+
69
+ def self.logger=(logger_instance)
70
+ @log = logger_instance
71
+ end
72
+
60
73
  def self.version
61
74
  "Architect4r version #{Architect4r::VERSION}"
62
75
  end
@@ -8,14 +8,19 @@ module Architect4r
8
8
  def execute_cypher(query)
9
9
  query = self.interpolate_node_model_root_references(query)
10
10
 
11
+ Architect4r.logger.debug("[Architect4r][execute_cypher] QUERY: #{query}")
12
+
11
13
  url = prepend_base_url("/cypher")
12
14
  response = Typhoeus::Request.post(url,
13
15
  :headers => { 'Accept' => 'application/json', 'Content-Type' => 'application/json' },
14
16
  :body => { 'query' => query }.to_json)
15
17
 
18
+ msg = JSON.parse(response.body)
19
+
20
+ Architect4r.logger.debug("[Architect4r][execute_cypher] CODE: #{response.code} => #{msg.inspect}")
21
+
16
22
  # Check if there might be an error with the query
17
23
  if response.code == 400
18
- msg = JSON.parse(response.body)
19
24
  if msg['exception'].to_s.match /org.neo4j.graphdb.NotFoundException/
20
25
  nil
21
26
  else
@@ -26,7 +31,7 @@ module Architect4r
26
31
  elsif response.code == 204
27
32
  nil
28
33
  else
29
- JSON.parse(response.body)
34
+ msg
30
35
  end
31
36
  end
32
37
 
@@ -34,6 +39,8 @@ module Architect4r
34
39
  # Get data from server
35
40
  data = execute_cypher(query)
36
41
 
42
+ Architect4r.logger.debug("[Architect4r][cypher_query] #{data.inspect}")
43
+
37
44
  # Create native ruby objects
38
45
  data['data'].map! do |set|
39
46
  set.map { |item| convert_if_possible(item) }
@@ -51,11 +51,26 @@ module Architect4r
51
51
  end
52
52
  end
53
53
 
54
+ # Override to_s to make debugging easier. It now includes the id and properties
55
+ #
54
56
  def to_s
55
57
  prop_data = @properties_data.collect { |key, value| "#{key}='#{value}'" }.join(' ')
56
58
  "#<#{self.class.name}:#{object_id} id=#{id} #{prop_data} neo4j_uri='#{@raw_data['self']}'>"
57
59
  end
58
60
 
61
+ # Calculate hash manually in order to only include unique properties for comparison
62
+ #
63
+ def hash
64
+ [self.class, self.id].hash
65
+ end
66
+
67
+ # Override comparison of instances
68
+ #
69
+ def ==(other)
70
+ other.is_a?(self.class) && id.present? && other.id == id
71
+ end
72
+ alias :eql? :==
73
+
59
74
  # Create the document. Validation is enabled by default and will return
60
75
  # false if the document is not valid. If all goes well, the document will
61
76
  # be returned.
@@ -1,3 +1,3 @@
1
1
  module Architect4r
2
- VERSION = "0.4"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -30,6 +30,26 @@ describe "Model Node" do
30
30
 
31
31
  end
32
32
 
33
+ describe "equality of two instances of the same node" do
34
+
35
+ subject { Person.create(:name => 'Alfons', :human => true) }
36
+ let(:instance_1) { Person.find_by_id(subject.id) }
37
+ let(:instance_2) { Person.find_by_id(subject.id) }
38
+
39
+ it "should have the same hash" do
40
+ instance_1.hash.should equal(instance_2.hash)
41
+ end
42
+
43
+ it "should be eql" do
44
+ instance_1.should eql(instance_2)
45
+ end
46
+
47
+ it "should be ==" do
48
+ instance_1.should == instance_2
49
+ end
50
+
51
+ end
52
+
33
53
  describe "connection" do
34
54
 
35
55
  it { should respond_to(:connection) }
@@ -10,8 +10,7 @@ unless defined?(TEST_SERVER)
10
10
  :config => {
11
11
  :host => 'localhost',
12
12
  :port => '7474',
13
- :path => '',
14
- :log_level => 'OFF'
13
+ :path => ''
15
14
  }
16
15
  }
17
16
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: architect4r
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- version: "0.4"
9
+ - 1
10
+ version: 0.4.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Maximilian Schulz
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2012-01-30 00:00:00 Z
18
+ date: 2012-01-31 00:00:00 Z
18
19
  dependencies:
19
20
  - !ruby/object:Gem::Dependency
20
21
  name: activemodel