orchestrate-rails 0.1.2 → 0.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45a5bf3c95eed7c945ba37051d9993fab5f45266
4
- data.tar.gz: bb3f294d24c43b41425469a7c899fb3a24a0a024
3
+ metadata.gz: 166db9c90bebd699191f15f953f5d75ed798f949
4
+ data.tar.gz: 76817436a532fc83e62b27da2783fec7480f70f8
5
5
  SHA512:
6
- metadata.gz: 132574ad45f7a4cefb3936bc0fcfcebcc8fd6869e170d8ea10f3d06baacee79dd8d048d31be480f6916cf757059f626e0558630518f64e916c2eb59d556f9ab1
7
- data.tar.gz: 613cfd0eaf2fe8ed9be89bd9562be28625a0e7b84f046ec5e603dc2601cbb10c78947e29ce88aeff037eb64dc875584e5498e41eaa5994a08c7f18a8894c224a
6
+ metadata.gz: d21e092deb79e7fd79b30fcb1b43cc31eda1a9d4d0c7f63697c08149e7afca9fc0690649d1d6fbfb5645bbf7f5671713e3df07e3cc5fcd99dd972a84d94da5d2
7
+ data.tar.gz: 7a66f5c71d6298d64f368ef1a6e219f6cb9ba6ae67aa2a36901b49eee8aab32ac1944ba5147146f2b78f2dbc8cf9fd159c25d82612bed84f220ded4336607738
@@ -22,7 +22,7 @@ module Orchestrate::Application
22
22
  # attr_reader :event_types, :graphs
23
23
 
24
24
  # :stopdoc:
25
- # The <tt>ref</tt> value for the current instance.
25
+ # The <b>ref</b> value for the current instance.
26
26
  # Convenience method #orchestrate_ref_value is provided as the
27
27
  # recommended way for an application to read this attribute.
28
28
  attr_reader :__ref_value__
@@ -236,7 +236,7 @@ module Orchestrate::Application
236
236
  )
237
237
  end
238
238
 
239
- def orchio_put_event(event_type, timestamp={}, document)
239
+ def orchio_put_event(event_type, timestamp=nil, document)
240
240
  # add_event_type event_type
241
241
  response = client.send_request(:put, inst_args(
242
242
  event_type: event_type, timestamp: timestamp, json: document
@@ -318,8 +318,8 @@ module Orchestrate::Application
318
318
  ocollection
319
319
  end
320
320
 
321
- # Returns the <tt>ref</tt> value for the current instance.
322
- # The <tt>ref</tt> value is an immutable value assigned to each
321
+ # Returns the <b>ref</b> value for the current instance.
322
+ # The <b>ref</b> value is an immutable value assigned to each
323
323
  # version of primary_key data in an orchestrate.io collection.
324
324
  def orchestrate_ref_value
325
325
  __ref_value__
@@ -341,7 +341,7 @@ module Orchestrate::Application
341
341
  # Returns the collection name for this instance.
342
342
  #
343
343
  # This method is called during initializtion with the value
344
- # of <tt>:define_collection_name</tt> from the params hash.
344
+ # of <b>:define_collection_name</b> from the params hash.
345
345
  # If this value is nil or blank, it is expected that the collection
346
346
  # name can be derived from the class name as shown:
347
347
  #
@@ -349,7 +349,7 @@ module Orchestrate::Application
349
349
  # - class: FilmClassic => 'film_classics'
350
350
  #
351
351
  # Any collection names that do not follow this convention must be
352
- # specified by adding the <tt>:define_collection_name</tt> key to
352
+ # specified by adding the <b>:define_collection_name</b> key to
353
353
  # the params hash in the model class definition.
354
354
  #
355
355
  # class Film < Orchestrate::Application::Record
@@ -364,11 +364,34 @@ module Orchestrate::Application
364
364
  : collection_name
365
365
  end
366
366
 
367
- # Updates the current instance's <tt>ref</tt> value, aka <tt>etag</tt>,
368
- # after a successful PUT request.
367
+ # After a successful PUT request,
368
+ # updates the current instance's <b>ref</b> value (also referred to
369
+ # as the <b>etag</b>)
370
+ # and calls #orchio_update_ref_table.
369
371
  def set_ref_value(response)
370
372
  unless response.header.code != 201 || response.header.etag.blank?
371
373
  @__ref_value__ = response.header.etag
374
+ # orchio_update_ref_table response.header.timestamp
375
+ end
376
+ end
377
+
378
+ # Updates the <b>ref table</b> collection with key/value data consisting
379
+ # of the current instance's <em><b>collection, key, timestamp</b> and
380
+ # <b>ref</b> values </em>, using the ref value as the primary key.
381
+ # When the ref table feature is enabled, the ref table is
382
+ # updated after each sucessful <b>put_key</b> request.
383
+ def orchio_update_ref_table(timestamp)
384
+ return if ocollection == RefTable.get_collection_name
385
+
386
+ if RefTable.enabled?
387
+ primary_key = __ref_value__.gsub(/"/, '')
388
+ doc = {
389
+ xcollection: ocollection,
390
+ xkey: id,
391
+ xref: primary_key,
392
+ timestamp: timestamp
393
+ }.to_json
394
+ RefTable.new(:id => primary_key).orchio_put doc
372
395
  end
373
396
  end
374
397
 
@@ -453,7 +476,7 @@ module Orchestrate::Application
453
476
  def self.orchio_status(response, expected_code)
454
477
  # puts " orchio_status: '#{response.header.code}'"
455
478
  status = true
456
- if response.header.code != expected_code
479
+ if response.header.code.to_i != expected_code
457
480
  puts " Error: #{response.body.code}: \"#{response.body.message}\""
458
481
  status = false
459
482
  end
@@ -0,0 +1,35 @@
1
+ module Orchestrate::Application
2
+
3
+ class RefTable < Orchestrate::Application::Record
4
+
5
+ @@is_enabled = false
6
+ @@collection_name = 'orchio_ref_table'
7
+
8
+ def initialize(params={})
9
+ return unless @@is_enabled == true
10
+ params[:define_collection_name] = @@collection_name
11
+ super params
12
+ end
13
+
14
+ def self.enable(name = nil)
15
+ puts "ENABLE REF TABLE"
16
+ @@is_enabled = true
17
+ @@collection_name = name unless name.blank?
18
+ Orchestrate::Application::Schema.instance.define_collection(
19
+ :name => @@collection_name,
20
+ :properties => [ :xcollection, :xkey, :timestamp, :xref]
21
+ )
22
+ end
23
+
24
+ def self.enabled?
25
+ @@is_enabled == true
26
+ end
27
+
28
+ def self.get_collection_name
29
+ @@collection_name
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+
@@ -2,7 +2,7 @@ module Orchestrate::Application
2
2
 
3
3
  # ---------------------------------------------------------------------------
4
4
  # Class to handle Orchestrate.io API responses
5
- #
5
+ #
6
6
  class SimpleCacheResponse
7
7
  attr_accessor :header, :body
8
8
 
@@ -10,13 +10,18 @@ module Orchestrate::Application
10
10
  @header, @body = Header.new(header), Body.new(body)
11
11
  end
12
12
 
13
+ def success?
14
+ true
15
+ end
16
+
13
17
  class Header
14
- attr_reader :locations, :code, :status, :etag
18
+ attr_reader :locations, :code, :status, :etag, :content
15
19
 
16
20
  def initialize(header)
17
21
  @locations = header[:locations]
18
22
  @code, @status = header[:code], header[:status]
19
23
  @etag = header[:etag]
24
+ @content = {}
20
25
  end
21
26
 
22
27
  def location
@@ -25,10 +30,12 @@ module Orchestrate::Application
25
30
  end
26
31
 
27
32
  class Body
28
- attr_reader :documents
29
-
33
+ attr_reader :documents, :count, :content
34
+
30
35
  def initialize(body)
31
36
  @documents = body
37
+ @count = documents.length
38
+ @content = nil
32
39
  end
33
40
 
34
41
  def document
@@ -148,9 +148,9 @@ module Orchestrate::Application
148
148
  end
149
149
 
150
150
  def self.enable
151
- # puts "SC-ENABLE"
152
- # @@is_enabled = true
153
- puts "SIMPLE-CACHE has been DISABLED for the current version."
151
+ puts "SC-ENABLE"
152
+ @@is_enabled = true
153
+ # puts "SIMPLE-CACHE has been DISABLED for the current version."
154
154
  end
155
155
 
156
156
  def self.disable
@@ -8,6 +8,9 @@ module Orchestrate::Rails
8
8
  #
9
9
  class Model < Orchestrate::Application::Record
10
10
  include ::ActiveModel::Validations
11
+ include ::ActiveModel::Serialization
12
+ include ::ActiveModel::Serializers
13
+ include ::ActiveModel::Serializers::JSON
11
14
  include ::ActiveModel::Conversion
12
15
  extend ::ActiveModel::Naming
13
16
 
@@ -38,6 +41,16 @@ module Orchestrate::Rails
38
41
  end
39
42
  end
40
43
 
44
+ # Called by ActiveModel::Validation
45
+ def read_attribute_for_validation(attribute)
46
+ instance_variable_get("@#{attribute}")
47
+ end
48
+
49
+ # Called by ActiveModel::Serialization
50
+ def read_attribute_for_serialization(attribute)
51
+ instance_variable_get("@#{attribute}")
52
+ end
53
+
41
54
  # -------------------------------------------------------------------------
42
55
  # Instance methods
43
56
 
@@ -49,8 +62,6 @@ module Orchestrate::Rails
49
62
  # Returns hash of key/value pairs.
50
63
  def attributes
51
64
  @attributes = Hash[attrs.map { |a| [a.to_sym, send("#{a}")] }]
52
- # @attributes =
53
- # Hash[attrs.map { |a| [a.to_sym, instance_variable_get("@#{a}")] }]
54
65
  end
55
66
 
56
67
  # :stopdoc:
@@ -159,7 +170,7 @@ module Orchestrate::Rails
159
170
  end
160
171
  # :startdoc:
161
172
 
162
- # Deletes the current primary_key from the collection.
173
+ # Deletes the current primary_key from the collection. Calls #orchio_delete
163
174
  #
164
175
  # Returns boolean status.
165
176
  def destroy
@@ -224,7 +235,7 @@ module Orchestrate::Rails
224
235
  #
225
236
  # Returns boolean status.
226
237
  def save_graph(kind, to_collection, to_key)
227
- retval orchio_put_graph kind, to_collection, to_key
238
+ retval orchio_put_graph(kind, to_collection, to_key)
228
239
  end
229
240
 
230
241
  # Removes the specified relation from the graph.
@@ -293,7 +304,7 @@ module Orchestrate::Rails
293
304
  # ::String#to_orchio_rails_attr.
294
305
  #
295
306
  def self.properties
296
- schema.properties ocollection
307
+ schema.properties(ocollection).select { |prop| prop !~ /id/i }
297
308
  end
298
309
 
299
310
  # -------------------------------------------------------------------------
@@ -395,7 +406,7 @@ module Orchestrate::Rails
395
406
  def self.find_by_method(myattrs, *args, &block)
396
407
  attrs_with_args = [myattrs.split('_and_'), args].transpose
397
408
  attrs_with_args.each { |awa| return unless attrs.include? awa.first }
398
- find_by Hash[attr_with_args]
409
+ find_by Hash[attrs_with_args]
399
410
  end
400
411
 
401
412
  # Calls ::find_by_method for 'find_by_attribute(s)'.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orchestrate-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Carrasquer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-01 00:00:00.000000000 Z
11
+ date: 2014-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: orchestrate-api
@@ -36,6 +36,7 @@ files:
36
36
  - lib/orchestrate_application/connect.rb
37
37
  - lib/orchestrate_application/record.rb
38
38
  - lib/orchestrate_application/document.rb
39
+ - lib/orchestrate_application/ref_table.rb
39
40
  - lib/orchestrate_application/result.rb
40
41
  - lib/orchestrate_application/response.rb
41
42
  - lib/orchestrate_application/simple_cache_store.rb