Class: Shark::Base

Inherits:
JsonApiClient::Resource
  • Object
show all
Defined in:
lib/shark/base.rb

Class Method Summary collapse

Class Method Details

.add_datetime_accessors(*method_names) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/shark/base.rb', line 16

def add_datetime_accessors(*method_names)
  method_names.each do |name|
    # get
    define_method name do
      value = super()
      DateTime.parse(value) if value
    end

    # set
    define_method "#{name}=" do |value|
      if value.respond_to?(:iso8601)
        super(value.iso8601(0))
      else
        super(value)
      end
    end
  end
end