Class: OdataDuty::SchemaBuilder::Schema

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace:, host: 'localhost', scheme: 'https', base_path: '') ⇒ Schema

Returns a new instance of Schema.



17
18
19
20
21
22
23
24
25
# File 'lib/odata_duty/schema_builder.rb', line 17

def initialize(namespace:, host: 'localhost', scheme: 'https', base_path: '')
  @namespace = namespace.to_str.clone.freeze
  @host = host.to_str.clone.freeze
  @scheme = scheme.to_str.clone.freeze
  @base_path = base_path.to_str.clone.freeze
  @base_url = [scheme, '://', host, base_path].join.freeze
  @types = {}
  @containers = {}
end

Instance Attribute Details

#base_pathObject (readonly)

Returns the value of attribute base_path.



14
15
16
# File 'lib/odata_duty/schema_builder.rb', line 14

def base_path
  @base_path
end

#base_urlObject (readonly)

Returns the value of attribute base_url.



14
15
16
# File 'lib/odata_duty/schema_builder.rb', line 14

def base_url
  @base_url
end

#hostObject (readonly)

Returns the value of attribute host.



14
15
16
# File 'lib/odata_duty/schema_builder.rb', line 14

def host
  @host
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



14
15
16
# File 'lib/odata_duty/schema_builder.rb', line 14

def namespace
  @namespace
end

#schemeObject (readonly)

Returns the value of attribute scheme.



14
15
16
# File 'lib/odata_duty/schema_builder.rb', line 14

def scheme
  @scheme
end

#titleObject

Returns the value of attribute title.



15
16
17
# File 'lib/odata_duty/schema_builder.rb', line 15

def title
  @title
end

#typesObject (readonly)

Returns the value of attribute types.



14
15
16
# File 'lib/odata_duty/schema_builder.rb', line 14

def types
  @types
end

#versionObject

Returns the value of attribute version.



15
16
17
# File 'lib/odata_duty/schema_builder.rb', line 15

def version
  @version
end

Instance Method Details

#add_complex_type(**kwargs, &block) ⇒ Object



32
33
34
35
36
37
# File 'lib/odata_duty/schema_builder.rb', line 32

def add_complex_type(**kwargs, &block)
  ComplexType.new(**kwargs).tap do |complex_type|
    add_type complex_type
    block.call(complex_type)
  end
end

#add_entity_set(**kwargs) ⇒ Object



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

def add_entity_set(**kwargs)
  EntitySet.new(**kwargs).tap { |entity_set| add_container(entity_set) }
end

#add_entity_type(**kwargs, &block) ⇒ Object



46
47
48
49
50
51
# File 'lib/odata_duty/schema_builder.rb', line 46

def add_entity_type(**kwargs, &block)
  EntityType.new(**kwargs).tap do |entity_type|
    add_type entity_type
    block.call(entity_type)
  end
end

#add_enum_type(**kwargs, &block) ⇒ Object



39
40
41
42
43
44
# File 'lib/odata_duty/schema_builder.rb', line 39

def add_enum_type(**kwargs, &block)
  EnumType.new(**kwargs).tap do |enum_type|
    add_type enum_type
    block.call(enum_type)
  end
end

#collection_entity_setsObject



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

def collection_entity_sets
  entity_sets.select { |t| t.resolver_class.method_defined?(:collection) }
end

#complex_typesObject



65
66
67
# File 'lib/odata_duty/schema_builder.rb', line 65

def complex_types
  all_types.select { |t| t.instance_of?(ComplexType) }
end

#create(url, context:, query_options: nil) ⇒ Object



87
88
89
# File 'lib/odata_duty/schema_builder.rb', line 87

def create(url, context:, query_options: nil)
  Executor.create(url: url, context: context, query_options: query_options, schema: self)
end

#delete(url, context:, query_options: nil) ⇒ Object



95
96
97
# File 'lib/odata_duty/schema_builder.rb', line 95

def delete(url, context:, query_options: nil)
  Executor.delete(url: url, context: context, query_options: query_options, schema: self)
end

#endpointsObject



57
58
59
# File 'lib/odata_duty/schema_builder.rb', line 57

def endpoints
  entity_sets.map { |entity_set| Endpoint.new(entity_set) }
end

#entity_setsObject



73
# File 'lib/odata_duty/schema_builder.rb', line 73

def entity_sets = all_containers

#entity_typesObject



69
70
71
# File 'lib/odata_duty/schema_builder.rb', line 69

def entity_types
  all_types.grep(EntityType)
end

#enum_typesObject



61
62
63
# File 'lib/odata_duty/schema_builder.rb', line 61

def enum_types
  all_types.grep(EnumType)
end

#execute(url, context:, query_options: {}) ⇒ Object



83
84
85
# File 'lib/odata_duty/schema_builder.rb', line 83

def execute(url, context:, query_options: {})
  Executor.execute(url: url, context: context, query_options: query_options, schema: self)
end

#index_hashObject



107
108
109
# File 'lib/odata_duty/schema_builder.rb', line 107

def index_hash
  EdmxSchema.index_hash(self)
end

#individual_entity_setsObject



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

def individual_entity_sets
  entity_sets.select { |t| t.resolver_class.method_defined?(:individual) }
end

#inspectObject



27
28
29
30
# File 'lib/odata_duty/schema_builder.rb', line 27

def inspect
  "#<#{self.class} @namespace=#{@namespace} @base_path=#{@base_path} \
 containers=#{@containers.keys} types=#{@types.keys}>"
end

#metadata_xmlObject



103
104
105
# File 'lib/odata_duty/schema_builder.rb', line 103

def 
  EdmxSchema.(self)
end

#to_mcp_serverObject



99
100
101
# File 'lib/odata_duty/schema_builder.rb', line 99

def to_mcp_server
  McpServerBuilder.build(self)
end

#update(url, context:, query_options: nil) ⇒ Object



91
92
93
# File 'lib/odata_duty/schema_builder.rb', line 91

def update(url, context:, query_options: nil)
  Executor.update(url: url, context: context, query_options: query_options, schema: self)
end