groovy 0.6.0 → 0.6.1

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
  SHA256:
3
- metadata.gz: e3e87c857a45ab045967ed1af60d619ec7340fc751c950032645657049bd1c68
4
- data.tar.gz: 4886e8db94b7fa3627312f82842d141b9c24ea7954e59955f4840dab7f70f776
3
+ metadata.gz: bf0e3aa6e2c0d1e3d9e0245062e1b778e4da15e9130cc672d07eb1e474e25d0f
4
+ data.tar.gz: add6fe670e018efb4f5706b02d05154bdf525d5f2bb3f8ce378e60bb92471f59
5
5
  SHA512:
6
- metadata.gz: df4c68551089cf9ade2f20ac70436962fff82c0a83db5caeb0208b107a1215443386ab429d644c939200fef844a70db315c502cfb4c901aff7c809f578a07b67
7
- data.tar.gz: 8eb292ae1c4365040a62c4f9feb8e04b27119ae5b4d84b1adf0640cb7f1d46cbea29bafd57ad076ca0d0f593fae504f4bb6eb4afac392b530f725f82948b8ad1
6
+ metadata.gz: '0228c03673a0d86e3072c3f7a952a152c3799125f3c3a2998a219d6015a0c6ccea54bd10972996f17dab52b47298fdc3424fe9bff5de3343a3803748d22bbef1'
7
+ data.tar.gz: 8302d8af1e7940a878643f123760e5ae482b786c6c6857cf69306f8b2bb0e79a7364f05035659611102966a7b199aae7ce1eab869cdc9f2ab8055551cb5cdc42
data/lib/groovy/model.rb CHANGED
@@ -26,7 +26,7 @@ module Groovy
26
26
  # end
27
27
 
28
28
  def self.model_from_table(table_name)
29
- Kernel.const_get(table_name.to_s.sub(/ies$/, 'y').sub(/s$/, '').classify)
29
+ get_class(table_name.to_s.sub(/ies$/, 'y').sub(/s$/, ''))
30
30
  end
31
31
 
32
32
  def self.included(base)
@@ -35,6 +35,11 @@ module Groovy
35
35
  base.table_name = base.name.sub(/y$/, 'ie') + 's'
36
36
  end
37
37
 
38
+ def self.get_class(table_name)
39
+ classified = table_name.gsub(/([A-Z])/, '_\1').split('_').collect! { |w| w.capitalize }.join
40
+ Kernel.const_get(classified)
41
+ end
42
+
38
43
  module ClassMethods
39
44
  extend Forwardable
40
45
  attr_accessor :context_name, :table_name
@@ -86,6 +91,12 @@ module Groovy
86
91
  add_accessors_for(name)
87
92
  end
88
93
 
94
+ def add_reference(name, table_name, options = {})
95
+ schema.reference(name, table_name, options)
96
+ schema.sync
97
+ add_accessors_for(name)
98
+ end
99
+
89
100
  def add_accessors_for(col, s = schema)
90
101
  if s.attribute_columns.include?(col)
91
102
  add_attr_accessors(col)
@@ -378,7 +389,11 @@ module Groovy
378
389
 
379
390
  def save(options = {})
380
391
  return false if respond_to?(:invalid?) and invalid?
381
- new_record? ? create : update
392
+ if new_record?
393
+ create && true
394
+ else
395
+ update
396
+ end
382
397
  end
383
398
 
384
399
  def save!(options = {})
data/lib/groovy/schema.rb CHANGED
@@ -108,9 +108,11 @@ module Groovy
108
108
 
109
109
  ensure_created!
110
110
  remove_columns_not_in(@spec.keys)
111
+
111
112
  @spec.each do |col, spec|
112
113
  check_and_add_column(col, spec[:type], spec[:args])
113
114
  end
115
+
114
116
  @index_columns.each do |col|
115
117
  add_index_on(col)
116
118
  end
@@ -187,12 +189,12 @@ module Groovy
187
189
  end
188
190
 
189
191
  def create_table!
190
- log "Creating table!"
192
+ log "Creating table #{table_name}!"
191
193
  Groonga::Schema.create_table(table_name, context: context)
192
194
  end
193
195
 
194
196
  def remove_table!
195
- log "Removing table!"
197
+ log "Removing table #{table_name}!"
196
198
  Groonga::Schema.remove_table(table_name, context: context)
197
199
  @table = nil
198
200
  end
@@ -202,7 +204,7 @@ module Groovy
202
204
  end
203
205
 
204
206
  def log(str)
205
- puts "[#{table_name}] #{str}" if ENV['DEBUG']
207
+ puts "[#{table_name}] #{str}" # if ENV['DEBUG']
206
208
  end
207
209
  end
208
210
  end
data/lib/groovy/vector.rb CHANGED
@@ -80,6 +80,10 @@ module Groovy
80
80
  end
81
81
  end
82
82
 
83
+ def ==(arr)
84
+ to_a == arr
85
+ end
86
+
83
87
  private
84
88
  attr_reader :obj, :key
85
89
 
@@ -1,3 +1,3 @@
1
1
  module Groovy
2
- VERSION = '0.6.0'.freeze
2
+ VERSION = '0.6.1'.freeze
3
3
  end
@@ -0,0 +1,56 @@
1
+ require_relative './spec_helper'
2
+
3
+ describe Groovy::Model do
4
+
5
+ before :all do
6
+ Groovy.open('tmp/vector', 'vector_spec')
7
+ load_schema! 'vector_spec'
8
+ end
9
+
10
+ after :all do
11
+ Groovy.close('vector_spec')
12
+ end
13
+
14
+ def load_vector_schema!
15
+ klass = Class.new
16
+ Object.const_set("Comment", klass)
17
+ Comment.class_eval do
18
+ include Groovy::Model
19
+ schema(context: 'vector_spec') do |t|
20
+ t.string :content
21
+ t.timestamps
22
+ end
23
+ end
24
+
25
+ klass = Class.new;
26
+ Object.const_set("User", klass)
27
+ User.class_eval do
28
+ include Groovy::Model
29
+ schema(context: 'vector_spec') do |t|
30
+ t.string :name
31
+ t.timestamps
32
+ end
33
+ end
34
+
35
+ Comment.add_reference :author, "Users"
36
+ User.add_reference :comments, "Comments", type: :vector
37
+ end
38
+
39
+ describe 'relations' do
40
+
41
+ before do
42
+ load_vector_schema!
43
+ end
44
+
45
+ it 'loads records and keeps relations' do
46
+ user = User.new(name: 'John')
47
+ expect(user.save).to eq(true)
48
+ comment = Comment.new(author: user, content: 'Hello there!')
49
+ expect(comment.save).to eq(true)
50
+ user.comments << comment
51
+ expect(user.reload.comments).to eq([comment])
52
+ end
53
+
54
+ end
55
+
56
+ end
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.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomás Pollak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-27 00:00:00.000000000 Z
11
+ date: 2023-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rroonga
@@ -102,6 +102,7 @@ files:
102
102
  - spec/query_spec.rb
103
103
  - spec/search_spec.rb
104
104
  - spec/spec_helper.rb
105
+ - spec/vector_spec.rb
105
106
  homepage: https://github.com/tomas/groovy
106
107
  licenses: []
107
108
  metadata: {}