Module: Collabda::ClassMethods

Defined in:
lib/collabda.rb

Instance Method Summary collapse

Instance Method Details

#allObject



47
48
49
# File 'lib/collabda.rb', line 47

def all
  @collabda_models || []
end

#build_collectionObject



65
66
67
68
69
70
71
72
# File 'lib/collabda.rb', line 65

def build_collection
  check_validity
  fetch_data
  @collabda_models = []
  @parsed_data.each do |el|
    self.new(el)
  end
end

#check_validityObject

Raises:



60
61
62
63
# File 'lib/collabda.rb', line 60

def check_validity
  raise InvalidSource if @source_path.nil?
  raise MissingAttributes if @properties.nil?
end

#each(&block) ⇒ Object



56
57
58
# File 'lib/collabda.rb', line 56

def each(&block)
  all.each(&block)
end

#parsed_dataObject



82
83
84
# File 'lib/collabda.rb', line 82

def parsed_data
  @parsed_data
end

#properties(*attributes) ⇒ Object



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

def properties(*attributes)
  @properties=attributes
end

#register_model(model) ⇒ Object



51
52
53
54
# File 'lib/collabda.rb', line 51

def register_model(model)
  @collabda_models ||= []
  @collabda_models << model
end

#source(path, options = {}) ⇒ Object



41
42
43
44
45
# File 'lib/collabda.rb', line 41

def source(path, options={})
  @source_path = path
  @format = options[:type] || :yaml
  fetch_data
end

#source_pathObject



78
79
80
# File 'lib/collabda.rb', line 78

def source_path
  @source_path
end