groovy 0.7.0 → 0.7.1

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
  SHA256:
3
- metadata.gz: dc2860dffbf2ed0ba7df5db1d728766f8da5cd2ddd0e5bf4a07268307c54b6bb
4
- data.tar.gz: 5175d60fd1e3ad3f78e9d87e08fd10ba90845e7d29e4e73e6214e2326bb92c2c
3
+ metadata.gz: da506ad46a6a3aad6cd965b7fcc43079fd61903c1e1a9f0bee659342430dc9ad
4
+ data.tar.gz: 6eba099bd0552fcc3ce8aaa15a0d9fb46486a96e1c1eee8dcd427f86a7d44256
5
5
  SHA512:
6
- metadata.gz: 57a8880213de3b723057090d0928068716ecbe8ff89b3e19867d485febcfb9af2efd998fcee011cce9e3a30cac164f6ad8612312f5824a6b962ccbd7d12e6fec
7
- data.tar.gz: 70fce1c4f7152dbe6630d39ffe9286bf767ce1dad244636d5e8d9284b12f6c4cb31af15714c94b7da38439e3ce3404cab94543e2f8740162b199516da6115492
6
+ metadata.gz: 4c26e85b1dc605632deff25150f39e3794079c75581c0098c4893d01fced0729a6f4cd99fea8cae1d840aa003b219dfc62a62acbc0fa0743514d2d4464bbf98a
7
+ data.tar.gz: 1efedf625a489694dc51442664438d8d3a1984dfa50398734f97ecccf8f8146ff4543c06f9a1a6b9a0b17c4007d4fd1baa636b5d2ade8a98b300142133e89240
data/lib/groovy/model.rb CHANGED
@@ -265,6 +265,10 @@ module Groovy
265
265
  query.where(*args, &block)
266
266
  end
267
267
 
268
+ def each(&block)
269
+ query.each(&block)
270
+ end
271
+
268
272
  def find_or_create_by(attributes)
269
273
  find_by(**attributes) || create(**attributes)
270
274
  end
@@ -524,6 +528,9 @@ module Groovy
524
528
  update_attributes(obj) or raise "Invalid!"
525
529
  end
526
530
 
531
+ alias_method :update, :update_attributes
532
+ alias_method :update!, :update_attributes!
533
+
527
534
  def save(options = {})
528
535
  return false if respond_to?(:invalid?) and invalid?
529
536
  if new_record?
@@ -625,7 +632,14 @@ module Groovy
625
632
  if record.nil? # not persisted yet
626
633
  set_attribute(name, obj.id) # obj should be a groovy model or groonga record
627
634
  else
628
- val = obj.respond_to?(:record) ? obj.record : obj
635
+ val = if obj.is_a?(Groovy::Model)
636
+ obj.id
637
+ elsif obj.respond_to?(:record)
638
+ # obj.record.record_id
639
+ obj.record
640
+ else
641
+ obj
642
+ end
629
643
  record[name] = val
630
644
  end
631
645
  end
@@ -1,3 +1,3 @@
1
1
  module Groovy
2
- VERSION = '0.7.0'.freeze
2
+ VERSION = '0.7.1'.freeze
3
3
  end
data/spec/model_spec.rb CHANGED
@@ -119,6 +119,21 @@ describe Groovy::Model do
119
119
  end
120
120
 
121
121
  describe '#update_attributes' do
122
+
123
+ it 'allows setting references out of searches' do
124
+ cat = TestCategory.create!(name: 'A category')
125
+ cat2 = TestCategory.create!(name: 'Another category')
126
+
127
+ prod = TestProduct.create!(name: 'A product', price: 100)
128
+ prod.update_attributes(test_category: cat)
129
+
130
+ last = TestCategory.last
131
+ expect(last).to eq(cat2)
132
+ puts "last: #{last.inspect}"
133
+ prod.update_attributes(test_category: last)
134
+ expect(prod.reload.test_category).to eq(cat2)
135
+ end
136
+
122
137
  end
123
138
 
124
139
  describe '#save' do
data/spec/query_spec.rb CHANGED
@@ -16,6 +16,13 @@ describe Groovy::Query do
16
16
  Groovy.close('query_spec')
17
17
  end
18
18
 
19
+ # describe '#first' do
20
+ # it 'returns a valid object' do
21
+ # res = TestProduct.first
22
+ # expect(res.record.table.name).to eq(TestProduct.table.name)
23
+ # end
24
+ # end
25
+
19
26
  describe '#where' do
20
27
  describe 'boolean value' do
21
28
  it 'finds expected records' do
data/spec/spec_helper.rb CHANGED
@@ -16,12 +16,21 @@ RSpec.configure do |config|
16
16
  end
17
17
  end
18
18
 
19
+ class TestCategory
20
+ include Groovy::Model
21
+ end
22
+
19
23
  class TestProduct
20
24
  include Groovy::Model
21
25
  end
22
26
 
23
27
  def load_schema!(context_name)
28
+ TestCategory.load_schema context: context_name do |t|
29
+ t.string :name
30
+ end
31
+
24
32
  TestProduct.load_schema context: context_name do |t|
33
+ t.one :test_category
25
34
  t.boolean :visible
26
35
  t.string :name
27
36
  t.integer :price
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groovy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomás Pollak
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-13 00:00:00.000000000 Z
11
+ date: 2024-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rroonga
@@ -108,7 +108,7 @@ files:
108
108
  homepage: https://github.com/tomas/groovy
109
109
  licenses: []
110
110
  metadata: {}
111
- post_install_message:
111
+ post_install_message:
112
112
  rdoc_options: []
113
113
  require_paths:
114
114
  - lib
@@ -123,8 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  requirements: []
126
- rubygems_version: 3.4.10
127
- signing_key:
126
+ rubygems_version: 3.4.6
127
+ signing_key:
128
128
  specification_version: 4
129
129
  summary: A wrapper around Groonga/Rroonga
130
130
  test_files: []