Class: Yamo::Collection

Inherits:
Object
  • Object
show all
Extended by:
Enumerable
Defined in:
lib/yamo/collection.rb

Instance Attribute Summary collapse

Attributes inherited from Object

#data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Object

create_accessors, load_and_validate_file, load_and_validate_source, schema, validate_data, validator

Constructor Details

#initialize(name, data) ⇒ Collection

Returns a new instance of Collection.



13
14
15
16
# File 'lib/yamo/collection.rb', line 13

def initialize(name, data)
  @name = name
  @data = data
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/yamo/collection.rb', line 11

def name
  @name
end

Class Method Details

.eachObject



30
31
32
33
34
35
# File 'lib/yamo/collection.rb', line 30

def self.each
  Dir.foreach(@objectdir) do |o|
    next if o.match(/^\./)
    yield get(o)
  end
end

.get(name) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/yamo/collection.rb', line 22

def self.get(name)
  begin
    self.new(name, load_and_validate_file("#{@objectdir}/#{name}"))
  rescue Errno::ENOENT
    nil
  end
end

.objectdir(objectdir) ⇒ Object



18
19
20
# File 'lib/yamo/collection.rb', line 18

def self.objectdir(objectdir)
  @objectdir = objectdir
end

Instance Method Details

#to_sObject

Include name in to_s



38
39
40
# File 'lib/yamo/collection.rb', line 38

def to_s
  return '#<' + self.class.to_s + ":" + self.name + '>'
end