Class: Attributor::Ids

Inherits:
CSV show all
Defined in:
lib/attributor/types/ids.rb

Class Method Summary collapse

Methods inherited from CSV

decode_string, describe, dump, example, family, json_schema_type

Methods inherited from Collection

as_json_schema, check_option!, construct, constructable?, decode_string, describe, dump, #dump, example, family, inherited, json_schema_type, load, member_attribute, member_type, native_type, valid_type?, validate, #validate, validate_options

Methods included from Dumpable

#dump

Methods included from Container

included

Class Method Details

.for(type) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/attributor/types/ids.rb', line 3

def self.for(type)
  identity_name = type.options.fetch(:identity) do
    raise AttributorException, "no identity found for #{type.name}"
  end

  identity_attribute = type.attributes.fetch(identity_name) do
    raise AttributorException, "#{type.name} does not have attribute with name '#{identity_name}'"
  end

  ::Class.new(self) do
    @member_attribute = identity_attribute
    @member_type = identity_attribute.type
  end
end

.of(_type) ⇒ Object



18
19
20
# File 'lib/attributor/types/ids.rb', line 18

def self.of(_type)
  raise 'Invalid definition of Ids type. Defining Ids.of(type) is not allowed, you probably meant to do Ids.for(type) instead'
end