Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/strokedb/util/xml.rb,
lib/strokedb/util.rb,
lib/strokedb/core_ext/blank.rb,
lib/strokedb/core_ext/object.rb,
lib/strokedb/core_ext/infinity.rb,
lib/strokedb/sync/diff/default.rb
Overview
These are for use in Range arguments for View#find. We don’t provide correct spaceship operator <=> to preserve performance.
Instance Method Summary collapse
- #_stroke_automerged(r) ⇒ Object
- #_stroke_conflicted(r1, r2) ⇒ Object
-
#blank? ⇒ Boolean
An object is blank if it’s nil, empty, or a whitespace string.
- #infinite? ⇒ Boolean
- #stroke_diff(to) ⇒ Object
-
#stroke_merge(patch1, patch2) ⇒ Object
> is_conflict, result1, result2.
- #stroke_patch(patch) ⇒ Object
-
#to_optimized_raw ⇒ Object
Uses references to documents (compared to to_raw using hashes instead).
- #to_xml(options = {}) ⇒ Object
-
#truthy? ⇒ Boolean
Tricky, tricky! (-:.
Instance Method Details
#_stroke_automerged(r) ⇒ Object
14 15 16 |
# File 'lib/strokedb/sync/diff/default.rb', line 14 def _stroke_automerged(r) [false, r, r] end |
#_stroke_conflicted(r1, r2) ⇒ Object
17 18 19 |
# File 'lib/strokedb/sync/diff/default.rb', line 17 def _stroke_conflicted(r1, r2) [true, r1, r2] end |
#blank? ⇒ Boolean
An object is blank if it’s nil, empty, or a whitespace string. For example, “”, “ ”, nil, [], and {} are blank.
This simplifies
if !address.nil? && !address.empty?
to
if !address.blank?
9 10 11 |
# File 'lib/strokedb/core_ext/blank.rb', line 9 def blank? respond_to?(:empty?) ? empty? : !truthy? end |
#infinite? ⇒ Boolean
6 7 8 |
# File 'lib/strokedb/core_ext/infinity.rb', line 6 def infinite? false end |
#stroke_diff(to) ⇒ Object
3 4 5 |
# File 'lib/strokedb/sync/diff/default.rb', line 3 def stroke_diff(to) self == to ? nil : [PATCH_REPLACE, to] end |
#stroke_merge(patch1, patch2) ⇒ Object
> is_conflict, result1, result2
9 10 11 12 13 |
# File 'lib/strokedb/sync/diff/default.rb', line 9 def stroke_merge(patch1, patch2) # => is_conflict, result1, result2 r1 = self.stroke_patch(patch1) r2 = self.stroke_patch(patch2) [r1 != r2, r1, r2] end |
#stroke_patch(patch) ⇒ Object
6 7 8 |
# File 'lib/strokedb/sync/diff/default.rb', line 6 def stroke_patch(patch) patch ? patch[1] : self end |
#to_optimized_raw ⇒ Object
Uses references to documents (compared to to_raw using hashes instead)
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/strokedb/util.rb', line 6 def to_optimized_raw case self when Array map{|v| v.to_optimized_raw } when Hash new_hash = {} each_pair{|k,v| new_hash[k.to_optimized_raw] = v.to_optimized_raw} new_hash else self end end |
#to_xml(options = {}) ⇒ Object
2 3 4 5 |
# File 'lib/strokedb/util/xml.rb', line 2 def to_xml( = {}) xml = [:builder] xml.tag!([:root], [:skip_types] ? {} : {:type => self.class.to_s.underscore},to_s) end |
#truthy? ⇒ Boolean
Tricky, tricky! (-:
12 13 14 |
# File 'lib/strokedb/core_ext/object.rb', line 12 def truthy? !!self end |