Class: Frodo::EntitySet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/frodo/entity_set.rb

Overview

This class represents a set of entities within an Frodo service. It is instantiated whenever an Frodo::Service is asked for an EntitySet via the Frodo::Service#[] method call. It also provides Enumerable behavior so that you can interact with the entities within a set in a very comfortable way.

This class also implements a query interface for finding certain entities based on query criteria or limiting the result set returned by the set. This functionality is implemented through transparent proxy objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Frodo::EntitySet

Sets up the EntitySet to permit querying for the resources in the set.

Parameters:

  • options (Hash) (defaults to: {})

    the options to setup the EntitySet



28
29
30
31
32
33
34
# File 'lib/frodo/entity_set.rb', line 28

def initialize(options = {})
  @name         = options[:name]
  @type         = options[:type]
  @namespace    = options[:namespace]
  @service_name = options[:service_name]
  @container    = options[:container]
end

Instance Attribute Details

#containerObject (readonly)

The EntitySet’s container name



22
23
24
# File 'lib/frodo/entity_set.rb', line 22

def container
  @container
end

#nameObject (readonly)

The name of the EntitySet



14
15
16
# File 'lib/frodo/entity_set.rb', line 14

def name
  @name
end

#namespaceObject (readonly)

The Frodo::Service’s namespace



18
19
20
# File 'lib/frodo/entity_set.rb', line 18

def namespace
  @namespace
end

#service_nameObject (readonly)

The Frodo::Service’s identifiable name



20
21
22
# File 'lib/frodo/entity_set.rb', line 20

def service_name
  @service_name
end

#typeObject (readonly)

The Entity type for the EntitySet



16
17
18
# File 'lib/frodo/entity_set.rb', line 16

def type
  @type
end

Instance Method Details

#entity_optionsHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Options used for instantiating a new Frodo::Entity for this set.

Returns:

  • (Hash)


122
123
124
125
126
127
128
# File 'lib/frodo/entity_set.rb', line 122

def entity_options
  {
    service_name: service_name,
    type:         type,
    entity_set:   self
  }
end

#entity_primary_keyObject



74
75
76
# File 'lib/frodo/entity_set.rb', line 74

def entity_primary_key()
  new_entity.primary_key
end

#new_entity(properties = {}) ⇒ Frodo::Entity

Create a new Entity for this set with the given properties.

Parameters:

  • properties (Hash) (defaults to: {})

    property name as key and it’s initial value

Returns:



62
63
64
# File 'lib/frodo/entity_set.rb', line 62

def new_entity(properties = {})
  Frodo::Entity.with_properties(properties, entity_options)
end

#query(options = {}) ⇒ Frodo::Query

Returns a query targetted at the current EntitySet.

Parameters:

  • options (Hash) (defaults to: {})

    query options

Returns:



69
70
71
# File 'lib/frodo/entity_set.rb', line 69

def query(options = {})
  Frodo::Query.new(self, options)
end

#serviceFrodo::Service

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The Frodo::Service this EntitySet is associated with.

Returns:



115
116
117
# File 'lib/frodo/entity_set.rb', line 115

def service
  @service ||= Frodo::ServiceRegistry[service_name]
end