Class: OdataDuty::EntitySet::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/odata_duty.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entity_set) ⇒ Metadata

Returns a new instance of Metadata.



46
47
48
# File 'lib/odata_duty.rb', line 46

def initialize(entity_set)
  @entity_set = entity_set
end

Instance Attribute Details

#entity_setObject (readonly)

Returns the value of attribute entity_set.



44
45
46
# File 'lib/odata_duty.rb', line 44

def entity_set
  @entity_set
end

Instance Method Details

#collection(set_builder, context:, selected:) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/odata_duty.rb', line 83

def collection(set_builder, context:, selected:)
  begin
    values = set_builder.collection
  rescue NoMethodError
    raise NoImplementationError, "collection not implemented for #{entity_set}"
  end

  mapper = entity_type.mapper(context, selected: selected)

  values.map { |v| mapper.obj_to_hash(v, context) }
end

#create(context:) ⇒ Object



107
108
109
110
111
112
113
114
# File 'lib/odata_duty.rb', line 107

def create(context:)
  wrapper = CreateComplexTypeHashWrapper.new(context.query_options, entity_type,
                                             operation: :create, context: context)
  result = entity_set.new(context: context)
                     .create(wrapper)
  mapper = entity_type.mapper(context, selected: nil)
  mapper.obj_to_hash(result, context)
end

#delete(id, context:) ⇒ Object



125
126
127
128
# File 'lib/odata_duty.rb', line 125

def delete(id, context:)
  result = entity_set.new(context: context).delete(converted_id(id))
  raise ResourceNotFoundError, "No such entity #{id}" unless result
end

#descriptionObject



50
51
52
# File 'lib/odata_duty.rb', line 50

def description
  entity_set.description
end

#entity_typeObject



63
64
65
# File 'lib/odata_duty.rb', line 63

def entity_type
  entity_set.entity_type
end

#entity_type_nameObject



67
68
69
# File 'lib/odata_duty.rb', line 67

def entity_type_name
  entity_type..name
end

#individual(set_builder, id, context:, selected:) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/odata_duty.rb', line 95

def individual(set_builder, id, context:, selected:)
  begin
    result = set_builder.individual(converted_id(id))
  rescue NoMethodError
    raise NoImplementationError, "individual not implemented for #{entity_set}"
  end

  raise ResourceNotFoundError, "No such entity #{id}" unless result

  entity_type.mapper(context, selected: selected).obj_to_hash(result, context)
end

#kindObject



71
72
73
# File 'lib/odata_duty.rb', line 71

def kind
  'EntitySet'
end

#metadata_typesObject



54
55
56
# File 'lib/odata_duty.rb', line 54

def 
  [entity_type].map(&:__metadata).flat_map(&:metadata_types)
end

#nameObject



58
59
60
61
# File 'lib/odata_duty.rb', line 58

def name
  entity_set.name ||
    entity_set.to_s.split('::').last.sub(/EntitySet\z/, '').sub(/Set\z/, '')
end

#new_entity_set(context:) ⇒ Object



79
80
81
# File 'lib/odata_duty.rb', line 79

def new_entity_set(context:)
  entity_set.new(context: context)
end

#non_insertable_property_namesObject



139
140
141
142
# File 'lib/odata_duty.rb', line 139

def non_insertable_property_names
  @non_insertable_property_names ||=
    entity_type.properties.select(&:non_insertable?).map(&:name)
end

#supports_collection?Boolean

Returns:

  • (Boolean)


132
# File 'lib/odata_duty.rb', line 132

def supports_collection? = entity_set.method_defined?(:collection)

#supports_count?Boolean

Returns:

  • (Boolean)


134
# File 'lib/odata_duty.rb', line 134

def supports_count? = entity_set.method_defined?(:count)

#supports_create?Boolean

Returns:

  • (Boolean)


135
# File 'lib/odata_duty.rb', line 135

def supports_create? = entity_set.method_defined?(:create)

#supports_delete?Boolean

Returns:

  • (Boolean)


137
# File 'lib/odata_duty.rb', line 137

def supports_delete? = entity_set.method_defined?(:delete)

#supports_filter_or?Boolean

Returns:

  • (Boolean)


131
# File 'lib/odata_duty.rb', line 131

def supports_filter_or? = entity_set.method_defined?(:od_filter_or)

#supports_individual?Boolean

Returns:

  • (Boolean)


133
# File 'lib/odata_duty.rb', line 133

def supports_individual? = entity_set.method_defined?(:individual)

#supports_search?Boolean

Returns:

  • (Boolean)


130
# File 'lib/odata_duty.rb', line 130

def supports_search? = entity_set.method_defined?(:od_search)

#supports_update?Boolean

Returns:

  • (Boolean)


136
# File 'lib/odata_duty.rb', line 136

def supports_update? = entity_set.method_defined?(:update)

#update(id, context:) ⇒ Object



116
117
118
119
120
121
122
123
# File 'lib/odata_duty.rb', line 116

def update(id, context:)
  wrapper = CreateComplexTypeHashWrapper.new(context.query_options, entity_type,
                                             operation: :update, context: context)
  result = entity_set.new(context: context).update(converted_id(id), wrapper)
  raise ResourceNotFoundError, "No such entity #{id}" unless result

  entity_type.mapper(context, selected: nil).obj_to_hash(result, context)
end

#urlObject



75
76
77
# File 'lib/odata_duty.rb', line 75

def url
  entity_set.url || name
end