Sha256: cda677907642b3951516ca1f32ce3ad4695fa125c6424a461a735b8e3d98e6c8
Contents?: true
Size: 1.05 KB
Versions: 12
Compression:
Stored size: 1.05 KB
Contents
module EventbriteSDK class Resource class SchemaDefinition def initialize(resource_name) @resource_name = resource_name @read_only_keys = Set.new @attrs = {} end %i(boolean currency datetime integer string).each do |method| define_method(method) do |value, *opts| options = opts.first @read_only_keys << value if options && options[:read_only] @attrs[value] = method end end def writeable?(key) whitelisted_attribute?(key) && !read_only?(key) end def type(key) attrs[key] end def defined_keys attrs.keys end private attr_reader :read_only_keys, :resource_name, :attrs def read_only?(key) read_only_keys.member?(key) end def whitelisted_attribute?(key) if attrs.has_key?(key) true else raise InvalidAttribute.new( "attribute `#{key}` not present in #{resource_name}" ) end end end end end
Version data entries
12 entries across 12 versions & 1 rubygems