Class: FrOData::EntityContainer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service) ⇒ EntityContainer

Creates a new EntityContainer

Parameters:



11
12
13
14
# File 'lib/frodata/entity_container.rb', line 11

def initialize(service)
  @metadata = service..xpath('//EntityContainer').first
  @service  = service
end

Instance Attribute Details

#metadataObject (readonly)

The EntityContainer’s metadata



7
8
9
# File 'lib/frodata/entity_container.rb', line 7

def 
  @metadata
end

#serviceObject (readonly)

The EntityContainer’s parent service



5
6
7
# File 'lib/frodata/entity_container.rb', line 5

def service
  @service
end

Instance Method Details

#[](entity_set_name) ⇒ FrOData::EntitySet

Retrieves the EntitySet associated with a specific EntityType by name

Parameters:

  • entity_set_name (to_s)

    the name of the EntitySet desired

Returns:

Raises:

  • (ArgumentError)


49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/frodata/entity_container.rb', line 49

def [](entity_set_name)
  xpath_query = "//EntitySet[@Name='#{entity_set_name}']"
  entity_set_node = .xpath(xpath_query).first
  raise ArgumentError, "Unknown Entity Set: #{entity_set_name}" if entity_set_node.nil?
  entity_type = entity_set_node.attributes['EntityType'].value
  FrOData::EntitySet.new(
    name: entity_set_name,
    namespace: namespace,
    type: entity_type,
    service_name: service.name,
    container: name
  )
end

#actionsObject



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

def actions
  # TODO return action imports exposed by this EntityContainer
end

#entity_setsHash<String, String>

Returns a hash of EntitySet names and their respective EntityTypes.

Returns:

  • (Hash<String, String>)


36
37
38
39
40
41
42
43
# File 'lib/frodata/entity_container.rb', line 36

def entity_sets
  @entity_sets ||= .xpath('//EntitySet').map do |entity|
    [
      entity.attributes['Name'].value,
      entity.attributes['EntityType'].value
    ]
  end.to_h
end

#functionsObject



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

def functions
  # TODO return function imports exposed by this EntityContainer
end

#nameString

Returns the EntityContainer’s name.

Returns:

  • (String)


30
31
32
# File 'lib/frodata/entity_container.rb', line 30

def name
  @name ||= .attributes['Name'].value
end

#namespaceString

Returns the EntityContainer’s namespace.

Returns:

  • (String)


24
25
26
# File 'lib/frodata/entity_container.rb', line 24

def namespace
  @namespace ||= schema.attributes['Namespace'].value
end

#schemaNokogiri::XML

The EntityContainer’s surrounding Schema

Returns:

  • (Nokogiri::XML)


18
19
20
# File 'lib/frodata/entity_container.rb', line 18

def schema
  @schema ||= .ancestors('Schema').first
end

#singletonsObject



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

def singletons
  # TODO return singletons exposed by this EntityContainer
end