Sha256: c0cf72f7188a52831325c8b2232ebb1dac480ac54939a879e4c53066acbe39cd
Contents?: true
Size: 1.48 KB
Versions: 1
Compression:
Stored size: 1.48 KB
Contents
require 'parse-model-scaffold/types' module Parse module Model module Scaffold PROTECTED_FIELDS = ['objectId', 'createdAt', 'updatedAt', 'ACL'] class ParseInspector def self.parse(obj) PROTECTED_FIELDS.each {|x| obj.delete x} attrs = [] obj.each do |k, v| value_type = determine_type(v) attr = ParseAttribute.new(k, value_type) attrs << attr end attrs end # Map Parse types to Ruby types if possible, otherwise, leave them as a def self.determine_type(val) # Parse represents complex types as a JSON object, so we need to inspect it if val.is_a? Hash # If we don't see the Parse '__type' key that they use for encoding # complex types, then this is just a simple object return :Hash if !val.has_key? '__type' # Otherwise, this is probably a Parse type (Relation, Pointer, GeoPoint, etc.) return val['__type'].to_sym end return :Boolean if [TrueClass, FalseClass].include? val.class # Base case val.class.to_s.to_sym end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
parse-model-scaffold-0.11.0 | lib/parse-model-scaffold/parse_inspector.rb |