subject

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2017 License: GPL-2.0, GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// IngredientVar defines an ingredient type which has a input variable
	IngredientVar = iota

	// IngredientStatic defines an ingredient type which has a static value
	// such as string, int, bool ect.
	IngredientStatic = iota
)

Variables

This section is empty.

Functions

This section is empty.

Types

type IO

type IO struct {
	reflect.Value `json:"-"`
	Name          string `json:"name"`
	TypeStr       string `json:"type"`
}

IO is a type which can describe input/output fields

func NewIO

func NewIO(field reflect.StructField, value reflect.Value) IO

NewIO return a new IO type

func (*IO) Compatible

func (io *IO) Compatible(other Output) bool

Compatible returns whether or not this output is compatible with another. Two outputs are compatible if they have the same name and the same type

func (*IO) Key

func (io *IO) Key(name string) string

Key returns the key uniqely describing the input/output

type Ingredient

type Ingredient struct {
	Type   int         `json:"type"`
	Source string      `json:"source"`
	Value  interface{} `json:"value"`
}

Ingredient describes a variable or static value. If the source is a variable it will be a string representation of which unit the ingredient links to. The frontend will use ingredients to define input for units is json format

func (*Ingredient) IsStatic

func (i *Ingredient) IsStatic() bool

IsStatic returns whether or not the ingredient has static content

func (*Ingredient) IsVariable

func (i *Ingredient) IsVariable() bool

IsVariable returns whether or not the ingredient is a variable representation

func (*Ingredient) Key

func (i *Ingredient) Key() string

Key returns the the storage key for use in a tuple space

func (*Ingredient) Validate

func (i *Ingredient) Validate() error

Validate makes sure the ingredient is valid

type Input

type Input struct {
	IO
	Recipe []*Ingredient `json:"recipe"`
}

Input describes the type of input and the ingredients used

func NewInput

func NewInput(field reflect.StructField, value reflect.Value) *Input

NewInput returns a new input object from a struct field and value

func (*Input) AddIngredient

func (i *Input) AddIngredient(ingr *Ingredient)

AddIngredient adds an ingredient to the input

func (*Input) CopyRecipe

func (i *Input) CopyRecipe(input *Input) error

CopyRecipe assigns the recipe from raw json data

func (*Input) Validate

func (i *Input) Validate() error

Validate makes sure that ingredients are given

type Output

type Output struct {
	IO
}

Output describes the name and type of an output

func NewOutput

func NewOutput(field reflect.StructField, value reflect.Value) *Output

NewOutput returns a new output object from a struct field and value

type Resolver

type Resolver interface {
	ResolveSubject(string) (interface{}, error)
}

Resolver is an interface for a type which can resolve the subject given its type as a string. The resolver has to know the type of object and resolve that object. This will be used with JSON serialization because only a string representation of the subject type is known at that point

type Subject

type Subject struct {
	Resolver `json:"-"`
	Identity string    `json:"id"`
	Name     string    `json:"name"`
	In       []*Input  `json:"input"`
	Out      []*Output `json:"output"`
	// contains filtered or unexported fields
}

Subject is a type which can manipulate and analyze structs

func New

func New(io interface{}, resolver Resolver) *Subject

New creates a new subject from a input/output type. The input and output of the type is analysed and can be manipulated through the subject

func (*Subject) AddStatic

func (s *Subject) AddStatic(argument string, value interface{}) error

AddStatic is a shortcut method for adding an ingredient to the unit which is a static argument

func (*Subject) AddVar

func (s *Subject) AddVar(argument string, source string, variable string) error

AddVar is a shortcut method for adding an ingredient to the unit which is a variable reference from another unit

func (*Subject) AssignInput

func (s *Subject) AssignInput(ts types.TupleSpace) error

AssignInput finds all ingredients in the state given and assigns it as input

func (*Subject) GetInputByName

func (s *Subject) GetInputByName(name string) (input *Input, err error)

GetInputByName returns the input field as a reflected value

func (*Subject) GetOutputByName

func (s *Subject) GetOutputByName(name string) (output *Output, err error)

GetOutputByName returns the output field as a reflected value

func (*Subject) GetSubject

func (s *Subject) GetSubject() interface{}

GetSubject returns the underlying subject

func (*Subject) NumVariables

func (s *Subject) NumVariables() int

NumVariables returns the number of dependencies from other actions

func (*Subject) RebuildSubject

func (s *Subject) RebuildSubject(resolver Resolver) error

RebuildSubject rebuilds the subject by resolving a new instance of the subject using the subjec resolver. The recipe for every input is copied after the subject has been analysed

func (*Subject) SetName

func (s *Subject) SetName(name string)

SetName sets the name of the subject

func (*Subject) SetResolver

func (s *Subject) SetResolver(resolver Resolver)

SetResolver sets the resolver used to identify objects

func (*Subject) StoreOutput

func (s *Subject) StoreOutput(ts types.TupleSpace) error

StoreOutput saves the computed output in the state

func (*Subject) String

func (s *Subject) String() string

func (*Subject) Type

func (s *Subject) Type() string

Type returns the underlying struct name

func (*Subject) Validate

func (s *Subject) Validate() error

Validate makes sure that the unit is set up correctly for execution

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL