lib/ecoportal/api/common/content/double_model.rb in ecoportal-api-v2-0.8.8 vs lib/ecoportal/api/common/content/double_model.rb in ecoportal-api-v2-0.8.9
- old
+ new
@@ -8,10 +8,11 @@
# which differs of `attr_*` ruby native class methods because `pass*`
# completelly **links** the methods **to a subjacent `Hash` model**
class DoubleModel < Common::BaseModel
NOT_USED = Common::Content::ClassHelpers::NOT_USED
extend Common::Content::ClassHelpers
+ include Common::Content::ModelHelpers
class UnlinkedModel < Exception
def initialize (msg = "Something went wrong when linking the document.", from: nil, key: nil)
msg += " From: #{from}." if from
msg += " key: #{key}." if key
@@ -103,9 +104,19 @@
# @param read_only [Boolean] should it only define the reader?
def passdate(*methods, read_only: false)
pass_reader(*methods) {|value| to_time(value)}
unless read_only
pass_writer(*methods) {|value| to_time(value)&.iso8601}
+ end
+ self
+ end
+
+ # To link as a `Boolean` to a subjacent `Hash` model property
+ # @param read_only [Boolean] should it only define the reader?
+ def passboolean(*methods, read_only: false)
+ pass_reader(*methods) {|value| value}
+ unless read_only
+ pass_writer(*methods) {|value| !!value}
end
self
end
# To link as plain `Array` to a subjacent `Hash` model property