Class: OdataDuty::EntitySet::Metadata
- Inherits:
-
Object
- Object
- OdataDuty::EntitySet::Metadata
- Defined in:
- lib/odata_duty.rb
Instance Attribute Summary collapse
-
#entity_set ⇒ Object
readonly
Returns the value of attribute entity_set.
Instance Method Summary collapse
- #collection(set_builder, context:, selected:) ⇒ Object
- #create(context:) ⇒ Object
- #delete(id, context:) ⇒ Object
- #entity_type ⇒ Object
- #entity_type_name ⇒ Object
- #individual(set_builder, id, context:, selected:) ⇒ Object
-
#initialize(entity_set) ⇒ Metadata
constructor
A new instance of Metadata.
- #kind ⇒ Object
- #metadata_types ⇒ Object
- #name ⇒ Object
- #new_entity_set(context:) ⇒ Object
- #non_insertable_property_names ⇒ Object
- #supports_collection? ⇒ Boolean
- #supports_count? ⇒ Boolean
- #supports_create? ⇒ Boolean
- #supports_delete? ⇒ Boolean
- #supports_filter_or? ⇒ Boolean
- #supports_individual? ⇒ Boolean
- #supports_search? ⇒ Boolean
- #supports_update? ⇒ Boolean
- #update(id, context:) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(entity_set) ⇒ Metadata
Returns a new instance of Metadata.
41 42 43 |
# File 'lib/odata_duty.rb', line 41 def initialize(entity_set) @entity_set = entity_set end |
Instance Attribute Details
#entity_set ⇒ Object (readonly)
Returns the value of attribute entity_set.
39 40 41 |
# File 'lib/odata_duty.rb', line 39 def entity_set @entity_set end |
Instance Method Details
#collection(set_builder, context:, selected:) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/odata_duty.rb', line 74 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
98 99 100 101 102 103 104 105 |
# File 'lib/odata_duty.rb', line 98 def create(context:) wrapper = CreateComplexTypeHashWrapper.new(context., 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
116 117 118 119 |
# File 'lib/odata_duty.rb', line 116 def delete(id, context:) result = entity_set.new(context: context).delete(converted_id(id)) raise ResourceNotFoundError, "No such entity #{id}" unless result end |
#entity_type ⇒ Object
54 55 56 |
# File 'lib/odata_duty.rb', line 54 def entity_type entity_set.entity_type end |
#entity_type_name ⇒ Object
58 59 60 |
# File 'lib/odata_duty.rb', line 58 def entity_type_name entity_type..name end |
#individual(set_builder, id, context:, selected:) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/odata_duty.rb', line 86 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 |
#kind ⇒ Object
62 63 64 |
# File 'lib/odata_duty.rb', line 62 def kind 'EntitySet' end |
#metadata_types ⇒ Object
45 46 47 |
# File 'lib/odata_duty.rb', line 45 def [entity_type].map(&:__metadata).flat_map(&:metadata_types) end |
#name ⇒ Object
49 50 51 52 |
# File 'lib/odata_duty.rb', line 49 def name entity_set.name || entity_set.to_s.split('::').last.sub(/EntitySet\z/, '').sub(/Set\z/, '') end |
#new_entity_set(context:) ⇒ Object
70 71 72 |
# File 'lib/odata_duty.rb', line 70 def new_entity_set(context:) entity_set.new(context: context) end |
#non_insertable_property_names ⇒ Object
160 161 162 163 |
# File 'lib/odata_duty.rb', line 160 def non_insertable_property_names @non_insertable_property_names ||= entity_type.properties.select(&:non_insertable?).map(&:name) end |
#supports_collection? ⇒ Boolean
130 131 132 133 |
# File 'lib/odata_duty.rb', line 130 def supports_collection? # Check if the entity set class supports read by looking for the collection method entity_set.method_defined?(:collection) end |
#supports_count? ⇒ Boolean
140 141 142 143 |
# File 'lib/odata_duty.rb', line 140 def supports_count? # Check if the entity set class supports counting via the count method entity_set.method_defined?(:count) end |
#supports_create? ⇒ Boolean
145 146 147 148 |
# File 'lib/odata_duty.rb', line 145 def supports_create? # Check if the entity set class supports create by looking for the create method entity_set.method_defined?(:create) end |
#supports_delete? ⇒ Boolean
155 156 157 158 |
# File 'lib/odata_duty.rb', line 155 def supports_delete? # Check if the entity set class supports delete by looking for the delete method entity_set.method_defined?(:delete) end |
#supports_filter_or? ⇒ Boolean
126 127 128 |
# File 'lib/odata_duty.rb', line 126 def supports_filter_or? entity_set.method_defined?(:od_filter_or) end |
#supports_individual? ⇒ Boolean
135 136 137 138 |
# File 'lib/odata_duty.rb', line 135 def supports_individual? # Check if the entity set class supports read-by-id via the individual method entity_set.method_defined?(:individual) end |
#supports_search? ⇒ Boolean
121 122 123 124 |
# File 'lib/odata_duty.rb', line 121 def supports_search? # Check if the entity set class supports search by looking for the od_search method entity_set.method_defined?(:od_search) end |
#supports_update? ⇒ Boolean
150 151 152 153 |
# File 'lib/odata_duty.rb', line 150 def supports_update? # Check if the entity set class supports update by looking for the update method entity_set.method_defined?(:update) end |
#update(id, context:) ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'lib/odata_duty.rb', line 107 def update(id, context:) wrapper = CreateComplexTypeHashWrapper.new(context., 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 |
#url ⇒ Object
66 67 68 |
# File 'lib/odata_duty.rb', line 66 def url entity_set.url || name end |