class Cyby::Kintone::Record
Public Class Methods
new(app, raw = {})
click to toggle source
# File lib/cyby/kintone/record.rb, line 4 def initialize(app, raw = {}) @app = app @raw = raw @changed = {} end
Public Instance Methods
[](key)
click to toggle source
# File lib/cyby/kintone/record.rb, line 10 def [](key) if @raw.key?(key) convert(@raw[key]) else fail "'#{key}' doesn't exist" end end
[]=(key, value)
click to toggle source
# File lib/cyby/kintone/record.rb, line 18 def []=(key, value) @raw[key] ||= {} if @raw[key]["value"] != value changed(key) end @raw[key]["value"] = value end
changed(field)
click to toggle source
# File lib/cyby/kintone/record.rb, line 26 def changed(field) case field when "$id", "$revision" # Do nothing else @changed[field] = true end end
changed?()
click to toggle source
# File lib/cyby/kintone/record.rb, line 35 def changed? @changed.any? end
delete()
click to toggle source
# File lib/cyby/kintone/record.rb, line 68 def delete @app.delete(self) end
inspect()
click to toggle source
# File lib/cyby/kintone/record.rb, line 56 def inspect hash = {} @raw.each do |key, value| hash[key] = value["value"] end hash.inspect end
method_missing(method_name, *args)
click to toggle source
# File lib/cyby/kintone/record.rb, line 43 def method_missing(method_name, *args) key = if @app.convert_to_camelized_field method_name.to_s.camelize(:lower) else method_name.to_s end if key[-1] == "=" self.[]=(key[0..-2], args[0]) else self.[](key) end end
save()
click to toggle source
# File lib/cyby/kintone/record.rb, line 64 def save @app.save(self) end
to_json_for_save()
click to toggle source
# File lib/cyby/kintone/record.rb, line 72 def to_json_for_save record = @raw.select do |key, value| @changed[key] end if @raw["$id"] { id: @raw["$id"]["value"], record: record } else { record: record } end end
unchanged()
click to toggle source
# File lib/cyby/kintone/record.rb, line 39 def unchanged @changed = {} end
Private Instance Methods
convert(args)
click to toggle source
# File lib/cyby/kintone/record.rb, line 84 def convert(args) type = args['type'] value = args['value'] case type when 'CALC' value.to_f when 'NUMBER' value.to_f when 'RECORD_NUMBER' value.to_i else value end end