Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.

Commit

Permalink
Updated comments for documentation, renamed MetaCollection.One to .Fi…
Browse files Browse the repository at this point in the history
…rst, added better errors
  • Loading branch information
jacquayj committed Aug 17, 2016
1 parent 9c3939f commit 54e84a1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func (col *Collection) Rm(recursive bool, force bool) error {
return nil
}

// Attribute gets specific metadata AVU triple for Collection
// Attribute gets slice of Meta AVU triples, matching by Attribute name for Collection
func (col *Collection) Attribute(attr string) (Metas, error) {
if mc, err := col.Meta(); err == nil {
return mc.Get(attr)
Expand Down
2 changes: 1 addition & 1 deletion dataobj.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ func (obj *DataObj) Stat() (map[string]interface{}, error) {
return result, nil
}

// Attribute returns a single Meta triple struct found by the attributes name
// Attribute gets slice of Meta AVU triples, matching by Attribute name for DataObj
func (obj *DataObj) Attribute(attrName string) (Metas, error) {
if meta, err := obj.Meta(); err == nil {
return meta.Get(attrName)
Expand Down
13 changes: 7 additions & 6 deletions meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Meta struct {

type Metas []*Meta

// MatchOne returns a single Meta struct from the slice, matching on Attribute, Value, and Units
func (ms Metas) MatchOne(m *Meta) *Meta {

if len(ms) > 0 {
Expand Down Expand Up @@ -300,8 +301,8 @@ func (mc *MetaCollection) String() string {
return str
}

// One finds a single Meta struct by it's Attribute field. Similar to Attribute() function of other types.
func (mc *MetaCollection) One(attr string) (*Meta, error) {
// First finds the first matching Meta struct by it's Attribute field
func (mc *MetaCollection) First(attr string) (*Meta, error) {
if err := mc.init(); err != nil {
return nil, err
}
Expand All @@ -315,7 +316,7 @@ func (mc *MetaCollection) One(attr string) (*Meta, error) {
return nil, newError(Fatal, fmt.Sprintf("iRods Get Meta Failed, no match"))
}

// One finds a single Meta struct by it's Attribute field. Similar to Attribute() function of other types.
// Get returns a Meta struct slice (since attributes can share the same name in iRods), matching by their Attribute field. Similar to Attribute() function of other types
func (mc *MetaCollection) Get(attr string) (Metas, error) {
if err := mc.init(); err != nil {
return nil, err
Expand All @@ -336,7 +337,7 @@ func (mc *MetaCollection) Get(attr string) (Metas, error) {
return result, nil
}

// All
// All returns a slice of all Meta structs in the MetaCollection
func (mc *MetaCollection) All() (Metas, error) {
if err := mc.init(); err != nil {
return nil, err
Expand All @@ -345,7 +346,7 @@ func (mc *MetaCollection) All() (Metas, error) {
return mc.Metas, nil
}

// Each
// Each accepts an iterator function for looping over all Meta structs in the MetaCollection
func (mc *MetaCollection) Each(iterator func(*Meta)) error {
if err := mc.init(); err != nil {
return err
Expand Down Expand Up @@ -432,7 +433,7 @@ func (mc *MetaCollection) Add(m Meta) (*Meta, error) {
if am := attrs.MatchOne(&m); am != nil {
return am, nil
}
return nil, er
return nil, newError(Fatal, fmt.Sprintf("iRods Add Meta Error: Unable to locate added meta triple"))
} else {
return nil, er
}
Expand Down

0 comments on commit 54e84a1

Please sign in to comment.