module Tatooine::Resource
Constants
- MAPPING
Public Class Methods
included(base)
click to toggle source
# File lib/tatooine/resource.rb, line 16 def self.included(base) base.extend(ClassMethods) end
new(opts={})
click to toggle source
# File lib/tatooine/resource.rb, line 20 def initialize(opts={}) @properties = opts set_properties end
Private Instance Methods
set_properties()
click to toggle source
# File lib/tatooine/resource.rb, line 27 def set_properties self.class.schema["properties"].each do |property, values| properties = @properties.dup if properties[property] if values["type"] == "integer" properties[property] = properties[property].to_i elsif values["type"] == "array" && MAPPING.keys.include?(property) klass = Tatooine.const_get(MAPPING[property]) properties[property] = properties[property].map do |url| klass.new("url" => url) end elsif MAPPING.keys.include?(property) klass = Tatooine.const_get(MAPPING[property]) properties[property] = klass.new("url" => properties[property]) end instance_variable_set("@#{property}", properties[property]) end end @url = @properties["url"] if @properties["url"] end