Class: Hotwire::Response::Json::Date

Inherits:
Object
  • Object
show all
Defined in:
lib/hotwire/response/json.rb

Overview

Utility class to produce a JSON rendering of dates compatible with what the Wire APIs expect ( a Javascript date object )

Instance Method Summary collapse

Constructor Details

#initialize(date) ⇒ Date

Returns a new instance of Date.



72
73
74
# File 'lib/hotwire/response/json.rb', line 72

def initialize(date)
  @date = date
end

Instance Method Details

#to_json(options = nil) ⇒ Object



76
77
78
# File 'lib/hotwire/response/json.rb', line 76

def to_json(options=nil)
  @date.nil? ? "" : "new Date(#{@date.year}, #{@date.month-1}, #{@date.day})"
end