Class: Explicit::Type::DateTimeUnixEpoch
- Inherits:
-
Explicit::Type
- Object
- Explicit::Type
- Explicit::Type::DateTimeUnixEpoch
- Defined in:
- lib/explicit/type/date_time_unix_epoch.rb
Constant Summary collapse
- Eval =
->(expr) { expr.respond_to?(:call) ? expr.call : expr }
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
Attributes inherited from Explicit::Type
#auth_type, #default, #description, #nilable, #param_location
Instance Method Summary collapse
-
#initialize(min: nil, max: nil) ⇒ DateTimeUnixEpoch
constructor
A new instance of DateTimeUnixEpoch.
- #json_schema(flavour) ⇒ Object
- #validate(value) ⇒ Object
Methods inherited from Explicit::Type
#auth_basic?, #auth_bearer?, build, #error_i18n, #mcp_schema, #merge_base_json_schema, #param_location_body?, #param_location_path?, #param_location_query?, #required?, #swagger_i18n, #swagger_schema
Constructor Details
#initialize(min: nil, max: nil) ⇒ DateTimeUnixEpoch
Returns a new instance of DateTimeUnixEpoch.
10 11 12 13 |
# File 'lib/explicit/type/date_time_unix_epoch.rb', line 10 def initialize(min: nil, max: nil) @min = min @max = max end |
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
6 7 8 |
# File 'lib/explicit/type/date_time_unix_epoch.rb', line 6 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
6 7 8 |
# File 'lib/explicit/type/date_time_unix_epoch.rb', line 6 def min @min end |
Instance Method Details
#json_schema(flavour) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/explicit/type/date_time_unix_epoch.rb', line 57 def json_schema(flavour) { type: "integer", minimum: 1, format: "POSIX time", description_topics: [ swagger_i18n("date_time_unix_epoch") ] } end |
#validate(value) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/explicit/type/date_time_unix_epoch.rb', line 15 def validate(value) if !value.is_a?(::Integer) && !value.is_a?(::String) return error_i18n("date_time_unix_epoch") end datetime = DateTime.strptime(value.to_s, "%s") if min min_value = Eval[min] if datetime.before?(min_value) return error_i18n("date_time_unix_epoch_min", min: min_value) end end if max max_value = Eval[max] if datetime.after?(max_value) return error_i18n("date_time_unix_epoch_max", max: max_value) end end [:ok, datetime] rescue ::Date::Error return error_i18n("date_time_unix_epoch") end |