embedson 1.0.3 → 1.0.4

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzBjMmI2NTk4ZWRhMGJkZTZlZWI3MTBjMzI4MzA1ZmU5ODg1MjA5NA==
4
+ NThiNzZmNzBkMTA2Mzg0OGVmZWJhMGI0Yzc3MmVjYWFjN2JjYTA2ZQ==
5
5
  data.tar.gz: !binary |-
6
- MTAyNjhmYmY3OGM4ZTYxYTcxZjVhYzgzY2ZhNzYwNTM0ZGFhYjAxYQ==
6
+ ZDg1Njk0ODlmNGI3OTY0OTZjMmFiMDY0YzM3NjIxYTkyYTIxOGNlMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NjEyYTE2ZmJiZGE2ODA5Njc3Y2U4ZDJiYmM4ODU5MGJjNDNlYzZjYzA4Mzhk
10
- ZDJkYjllZWJhMWFlNjNiOGY5MzI5OTFiODlhMTNkYWQ2MjgzYTYyOGFhMTE3
11
- YTBjY2FlMDBkNWExYzU0MzcyYjgyZGEwOWQzMzIxYjI2ZDQ5NGQ=
9
+ ZjBkMmQxN2JhMzBiOWZiOTQ3ZjI1OGJiZDFkMDBjN2Y2NzUwZDFmNjNkMWE4
10
+ NWUwZDExOTc1YzZhMWY0ODgzOTlmMDYwYTQyNGQ3Yjk5ODk3Yzg1OGVhMDIx
11
+ ZDdlMjkzYTRhZDcxNDEyNzJiZmQ2MzBlNGRmNDZkN2QzNWM1YzE=
12
12
  data.tar.gz: !binary |-
13
- NjZhZDliMWE4YWMyZmIxNDk4YTE2ZDQ5NTVmYzZhMmFiMDZkOWE3MGQ4MWU1
14
- YjFiOTFkNmVlZDc1Mzc3YTljODA5OWZjZGI5NTVkNDAyNjAxNzQ1M2NiYWVl
15
- OThjODgzZjQ2YjY5YzM0MzM4NzlmMjVjYmJjNzg1ZTk2ZTgxMmI=
13
+ Y2JmODUxMDljZTc4MDhkNWJiNDI2MmU1NTUyNjkyNzU3Nzc4NTE4Yzc2ODFm
14
+ MTU2NjBkZmExOGI4MmI1YjU5MjBhZDVlZWNmOTI3YmVlMTlkNzdiYzEwMzk0
15
+ Yzg4ODUxYzY0MWM4YzA4M2ZmZTkwYWZiNmZiMmY3NzM3MmY2ODE=
data/README.md CHANGED
@@ -32,6 +32,9 @@ Or install it yourself as:
32
32
 
33
33
  ## Usage
34
34
 
35
+ Example with [Searchlight](https://github.com/nathanl/searchlight) is described
36
+ in blogpost ["Persistent queries in Ruby on Rails with PostgreSQL"](https://netguru.co/blog/persistent-queries-in-ruby-on-rails).
37
+
35
38
  Example with [Virtus](https://github.com/solnic/virtus):
36
39
 
37
40
  ```RUBY
@@ -26,7 +26,7 @@ module Embedson
26
26
  send("#{builder.field_name}_send_to_related", arg)
27
27
 
28
28
  instance_variable_set(builder.instance_var_name, arg)
29
- val = arg.nil? ? arg : arg.to_h.stringify_keys
29
+ val = arg.nil? ? arg : arg.send(builder.hash_method).stringify_keys
30
30
  unless val == read_attribute(builder.column_name)
31
31
  write_attribute(builder.column_name, val)
32
32
  end
@@ -21,6 +21,10 @@ module Embedson
21
21
  generate_common
22
22
  end
23
23
 
24
+ def hash_method
25
+ @hash_method || options.fetch(:hash_method, nil) || :to_h
26
+ end
27
+
24
28
  def column_name
25
29
  @column_name ||= options.fetch(:column_name, nil) || field_name
26
30
  end
@@ -1,3 +1,3 @@
1
1
  module Embedson
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Embedson::Model::MethodBuilder do
4
+
5
+ describe '#hash_method' do
6
+ context 'when option :hash_method is defined' do
7
+ let(:builder) { described_class.new(nil, :name, { hash_method: 'method' }) }
8
+
9
+ it 'returns its value' do
10
+ expect(builder.hash_method).to eq 'method'
11
+ end
12
+ end
13
+
14
+ context 'when options :hash_method is not defined' do
15
+ let(:builder) { described_class.new(nil, :name, {}) }
16
+
17
+ it 'returns :to_h' do
18
+ expect(builder.hash_method).to eq :to_h
19
+ end
20
+ end
21
+ end
22
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embedson
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - sufleR
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-16 00:00:00.000000000 Z
11
+ date: 2014-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -146,6 +146,7 @@ files:
146
146
  - lib/embedson/version.rb
147
147
  - spec/embedson/exceptions_spec.rb
148
148
  - spec/embedson/model/embedded_builder_spec.rb
149
+ - spec/embedson/model/method_builder_spec.rb
149
150
  - spec/embedson/model_spec.rb
150
151
  - spec/spec_helper.rb
151
152
  homepage: https://github.com/sufleR/embedson
@@ -175,5 +176,6 @@ summary: Embedded model for AR with postgresql
175
176
  test_files:
176
177
  - spec/embedson/exceptions_spec.rb
177
178
  - spec/embedson/model/embedded_builder_spec.rb
179
+ - spec/embedson/model/method_builder_spec.rb
178
180
  - spec/embedson/model_spec.rb
179
181
  - spec/spec_helper.rb