Class: OData::AbstractSchema::End

Inherits:
SchemaObject show all
Defined in:
lib/o_data/abstract_schema/end.rb

Constant Summary collapse

@@end_option_names =
%w{nullable multiple polymorphic}

Instance Attribute Summary collapse

Attributes inherited from SchemaObject

#name, #schema

Instance Method Summary collapse

Methods inherited from SchemaObject

#<=>, #plural_name, #qualified_name, #singular_name

Methods included from Comparable

#compare, #sort

Constructor Details

#initialize(schema, association, entity_type, return_type, name, options = {}) ⇒ End

Returns a new instance of End.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/o_data/abstract_schema/end.rb', line 17

def initialize(schema, association, entity_type, return_type, name, options = {})
  super(schema, name)
  
  @association = association
  @entity_type = entity_type
  @return_type = return_type
  
  unless @entity_type.nil?
    @return_type ||= @entity_type.qualified_name
  end

  @options = {}
  options.keys.select { |key| @@end_option_names.include?(key.to_s) }.each do |key|
    @options[key.to_sym] = options[key]
  end
end

Instance Attribute Details

#associationObject (readonly)

Returns the value of attribute association.



13
14
15
# File 'lib/o_data/abstract_schema/end.rb', line 13

def association
  @association
end

#entity_typeObject (readonly)

Returns the value of attribute entity_type.



14
15
16
# File 'lib/o_data/abstract_schema/end.rb', line 14

def entity_type
  @entity_type
end

#optionsObject

Returns the value of attribute options.



15
16
17
# File 'lib/o_data/abstract_schema/end.rb', line 15

def options
  @options
end

#return_typeObject (readonly)

Returns the value of attribute return_type.



14
15
16
# File 'lib/o_data/abstract_schema/end.rb', line 14

def return_type
  @return_type
end

Instance Method Details

#inspectObject



45
46
47
# File 'lib/o_data/abstract_schema/end.rb', line 45

def inspect
  "#<< #{qualified_name.to_s}(return_type: #{@return_type.to_s}, to_multiplicity: #{to_multiplicity.to_s}) >>"
end

#to_multiplicityObject

def return_type

@options[:multiple] ? 'Collection(' + @return_type.to_s + ')' : @return_type.to_s

end



38
39
40
41
42
43
# File 'lib/o_data/abstract_schema/end.rb', line 38

def to_multiplicity
  m = (@options[:nullable] ? '0' : '1') + '..' + (@options[:multiple] ? '*' : '1')
  m = '1' if m == '1..1'
  m = '*' if m == '0..*'
  m
end