dolly 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 607619b07d08f6c860815258fe030b39cd0a09f8
4
- data.tar.gz: 5dac80a4623dbb5e02bcb5a658e27c68c79f7b07
3
+ metadata.gz: 754dab90c1532d18893458b0b7301b38b319e5a1
4
+ data.tar.gz: ff8a35e0bdbfe7af08a62e3c42042024d8c1af2c
5
5
  SHA512:
6
- metadata.gz: 8f702a1d9f7772ee6f846840ad01929552efdd149c91d62a47ab0987fb133949dbdd1960e7f09d27045aba1c3499419aaa85f5f55c2128aeb64bd520a707a242
7
- data.tar.gz: 911733d3bbe11688ac8783009b2500e76d21fc9b0ed1cea9a8e222635c1ee578cd8890fbbace7dba3daee31aabaf01ed9bdfbbd54058f0b49ba72c10975e7ffb
6
+ metadata.gz: b517028df8a2946914bd15d56c04a279d6c67392de905bb31160753b31366be2ca6dce9e23bbda648882404e01ccdb908f32553c32265c373e866401e0cdbf26
7
+ data.tar.gz: 0964bd2b62f61ac822fe10da422cc055eb25ce8eb2b8d97302632577ff3eba438072f09318cceddce89dc6789773d07af0a5820b2753750609a8a7cf16ec8ce5
@@ -5,12 +5,12 @@ module Dolly
5
5
  class Document
6
6
  extend Dolly::Connection
7
7
  include Dolly::Query
8
- include Dolly::NameSpace
9
8
 
10
9
  attr_accessor :rows, :doc, :key
11
10
  class_attribute :properties
12
11
 
13
12
  def initialize options = {}
13
+ options = options.with_indifferent_access
14
14
  init_properties options
15
15
  end
16
16
 
@@ -1,12 +1,8 @@
1
- require "active_model/naming"
2
-
3
- #TODO: remove this module to be part of Dolly::Document
4
1
  module Dolly
5
2
  module NameSpace
6
- include ActiveModel::Naming
7
3
 
8
4
  def name_paramitized
9
- model_name.element
5
+ underscore name.split("::").last
10
6
  end
11
7
 
12
8
  def base_id id
@@ -18,5 +14,15 @@ module Dolly
18
14
  return id if id =~ %r~^#{name_paramitized}/~
19
15
  "#{name_paramitized}/#{id}"
20
16
  end
17
+
18
+ #FROM ActiveModel::Name
19
+ def underscore(camel_cased_word)
20
+ camel_cased_word.to_s.gsub(/::/, '/').
21
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
22
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
23
+ tr("-", "_").
24
+ downcase
25
+ end
26
+
21
27
  end
22
28
  end
data/lib/dolly/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dolly
2
- VERSION = "0.6.2"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -218,9 +218,24 @@ class DocumentTest < ActiveSupport::TestCase
218
218
  assert_equal "foo_bar/b", bar.id
219
219
  end
220
220
 
221
+ test 'new document will have id from _id or id strings' do
222
+ foo = FooBar.new 'id' => 'a'
223
+ bar = FooBar.new '_id' => 'b'
224
+ assert_equal "foo_bar/a", foo.id
225
+ assert_equal "foo_bar/b", bar.id
226
+ end
227
+
221
228
  test 'new document with no id' do
222
229
  foo = FooBar.new
223
- assert foo.id.match(%r{foo_bar/[a-f0-1]+}).present?
230
+ uuid = %r{
231
+ \A
232
+ foo_bar /
233
+ \h{8} # 8 hex chars
234
+ (?: - \h{4} ){3} # 3 groups of 4 hex chars (hyphen sep)
235
+ - \h{12} # 12 hex chars (hyphen sep again)
236
+ \Z
237
+ }x
238
+ assert foo.id.match(uuid)
224
239
  end
225
240
 
226
241
  private