module Crea::JSONable

Public Class Methods

included(base) click to toggle source
# File lib/crea/mixins/jsonable.rb, line 13
def self.included(base)
  base.extend(ClassMethods)
end

Public Instance Methods

as_json(options = {}) click to toggle source
# File lib/crea/mixins/jsonable.rb, line 17
def as_json options = {}
  serialized = Hash.new
  
  self.class.attributes.each do |attribute|
    unless (value = self.public_send attribute).nil?
      serialized[attribute] = if value.respond_to? :strftime
        value.strftime('%Y-%m-%dT%H:%M:%S')
      else
        value
      end
    end
  end
  
  serialized
end
to_json(*a) click to toggle source
# File lib/crea/mixins/jsonable.rb, line 33
def to_json *a
  as_json.to_json *a
end