cyby 0.1.1 → 0.1.2

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: 53aa37324f5116067ffb2c6f162f39582d9747c4
4
- data.tar.gz: e690a048a7c5214b2859d7e984d2223a95c0000b
3
+ metadata.gz: 3c8d7908636d29a6236ca003328acb4f1ec0a3c4
4
+ data.tar.gz: d78b0aa956b2714c6ed245a2338e159b6d498dea
5
5
  SHA512:
6
- metadata.gz: a52c55e6cdcd89396a46428f2a7886005b5a1e592fc0f201bbcab8a1cc4090773a58832ca09d2dbc971f2cbdda5784cb484174595a3d0c13fe3f24bb2f5a7ec0
7
- data.tar.gz: 2e9463720c254d369bd1d597818c9ebf75fc9b792f33241d58272b6330fda7dbe146bdfeba9958eeeaabb7d874b82918aaf9fc39c554d5283c052a3bbe4287f5
6
+ metadata.gz: 0ed719e660c7ab0af392b57b981a7f52f805f3ad1edd8e7c188279ac60bc919f675897dd102d39b8e6996584dc1623d4a653aa849e362bddf75874dfe1a56569
7
+ data.tar.gz: 44b66ab37fbe39a822814cc4ec23693c17bb028bbe77ff7dc456fbb6edd107448ae299e141202f764ae949757efb2fc3418b032d91cf46a7cabbd72fe8db72ac
data/README.md CHANGED
@@ -69,6 +69,11 @@ Get records.
69
69
  end
70
70
  records = relation.all
71
71
 
72
+ # Combining defined conditions
73
+ adult = app.where("age >= ?", 18)
74
+ man = app.where("sex in ?", ["man"])
75
+ records = app.where(adult).and(man)
76
+
72
77
  Create a record.
73
78
 
74
79
  record = app.new_record
@@ -32,15 +32,20 @@ module Cyby
32
32
  end
33
33
 
34
34
  def save(record)
35
- json = record.to_json_for_save
36
- if json[:id]
37
- resp = @api.put("/record.json", json)
35
+ if record.changed?
36
+ json = record.to_json_for_save
37
+ if json[:id]
38
+ resp = @api.put("/record.json", json)
39
+ else
40
+ resp = @api.post("/record.json", json)
41
+ record["$id"] = resp["id"]
42
+ end
43
+ record["$revision"] = resp["revision"]
44
+ record.unchanged
45
+ true
38
46
  else
39
- resp = @api.post("/record.json", json)
40
- record["$id"] = resp["id"]
47
+ false
41
48
  end
42
- record["$revision"] = resp["revision"]
43
- true
44
49
  end
45
50
 
46
51
  def delete(record)
@@ -4,6 +4,7 @@ module Cyby
4
4
  def initialize(app, raw = {})
5
5
  @app = app
6
6
  @raw = raw
7
+ @changed = {}
7
8
  end
8
9
 
9
10
  def [](key)
@@ -16,15 +17,29 @@ module Cyby
16
17
 
17
18
  def []=(key, value)
18
19
  @raw[key] ||= {}
19
- case key
20
- when "$id"
21
- @raw[key]["type"] = "__ID__"
22
- when "$revision"
23
- @raw[key]["type"] = "__REVISION__"
20
+ if @raw[key]["value"] != value
21
+ changed(key)
24
22
  end
25
23
  @raw[key]["value"] = value
26
24
  end
27
25
 
26
+ def changed(field)
27
+ case field
28
+ when "$id", "$revision"
29
+ # Do nothing
30
+ else
31
+ @changed[field] = true
32
+ end
33
+ end
34
+
35
+ def changed?
36
+ @changed.any?
37
+ end
38
+
39
+ def unchanged
40
+ @changed = {}
41
+ end
42
+
28
43
  def method_missing(method_name, *args)
29
44
  key = method_name.to_s
30
45
  if key[-1] == "="
@@ -52,12 +67,7 @@ module Cyby
52
67
 
53
68
  def to_json_for_save
54
69
  record = @raw.select do |key, value|
55
- case value["type"]
56
- when "CREATOR", "CREATED_TIME", "MODIFIER", "UPDATED_TIME", "STATUS", "STATUS_ASSIGNEE", "RECORD_NUMBER", "__REVISION__", "__ID__"
57
- false
58
- else
59
- true
60
- end
70
+ @changed[key]
61
71
  end
62
72
  if @raw["$id"]
63
73
  { id: @raw["$id"]["value"], record: record }
@@ -1,14 +1,16 @@
1
1
  module Cyby
2
2
  module Kintone
3
3
  class Relation
4
+ attr_reader :condition, :order_by, :fields
4
5
  include Enumerable
5
6
 
6
7
  alias_method :all, :to_a
7
8
 
8
9
  def initialize(app)
9
10
  @app = app
10
- @where = Query::Where.new
11
+ @condition = Query::Where.new
11
12
  @order_by = []
13
+ @fields = nil
12
14
  end
13
15
 
14
16
  def each
@@ -22,16 +24,21 @@ module Cyby
22
24
  end
23
25
 
24
26
  def where(cond, *params)
25
- @where = Query::Where.new(cond, *params)
27
+ case cond
28
+ when String
29
+ @condition = Query::Where.new(cond, *params)
30
+ else
31
+ @condition = cond.condition
32
+ end
26
33
  self
27
34
  end
28
35
 
29
36
  def and(cond, *params)
30
37
  case cond
31
38
  when String
32
- @where = Query::WhereAnd.new(@where, Query::Where.new(cond, *params))
39
+ @condition = Query::WhereAnd.new(@condition, Query::Where.new(cond, *params))
33
40
  else
34
- @where = Query::WhereAnd.new(@where, cond)
41
+ @condition = Query::WhereAnd.new(@condition, cond.condition)
35
42
  end
36
43
  self
37
44
  end
@@ -39,9 +46,9 @@ module Cyby
39
46
  def or(cond, *params)
40
47
  case cond
41
48
  when String
42
- @where = Query::WhereOr.new(@where, Query::Where.new(cond, *params))
49
+ @condition = Query::WhereOr.new(@condition, Query::Where.new(cond, *params))
43
50
  else
44
- @where = Query::WhereOr.new(@where, cond)
51
+ @condition = Query::WhereOr.new(@condition, cond.condition)
45
52
  end
46
53
  self
47
54
  end
@@ -62,7 +69,7 @@ module Cyby
62
69
  end
63
70
 
64
71
  def to_query
65
- query = @where.to_query
72
+ query = @condition.to_query
66
73
  if @order_by.any?
67
74
  query += " order by #{@order_by.join(',')}"
68
75
  end
@@ -1,3 +1,3 @@
1
1
  module Cyby
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cyby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroyuki Sato
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-17 00:00:00.000000000 Z
11
+ date: 2015-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler