collabda 0.0.1a → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72411f5cfca47c38d7810c6d0619bfb68fda266a
4
- data.tar.gz: 5c73e2d894bbb0d1fbb64c7c527686a4826873f9
3
+ metadata.gz: 13114a383a52ca5a6177a72200d820379bbfa5b5
4
+ data.tar.gz: 40bd5d6768707b98d1c0d2b92be9a72b61025cb8
5
5
  SHA512:
6
- metadata.gz: 647e46c9f8395fd4e99d9534764073ec36408e77dc3663fc9af315872081056678ca2da94c0f41c614169cc78a908ff8dcb699fc6adcba41f0772973dfbc0255
7
- data.tar.gz: 762fa5e7c1d0e82ca7937b9d13330c2667c44bdd0147ba78cc5aaadfc58b4af65a0e14de5f9de1c6512218cb3650f9ed4153ce5680354254df8925f32e2ffb5a
6
+ metadata.gz: cbd2bbcc34f7c71b915cd5963dd62ffdeb74c2b159149f9dc61608e6c6c802d44440c484a1a656b7bfedc6ab426c39172ead16f088aa31c510d9cb99d47d8f91
7
+ data.tar.gz: 10e0d034de14e5c6a29eeb036e0d3047db38999d2420d5d7ae3b69c84eee69986d3fd71b98f687ce1303580812c94d1d0f2ca82b4851587e0f862a5b63a77e4f
data/lib/collabda.rb CHANGED
@@ -1,3 +1,6 @@
1
+ require 'json'
2
+ require 'yaml'
3
+
1
4
  module Collabda
2
5
  def self.included(base)
3
6
  base.extend(Enumerable)
@@ -24,9 +27,12 @@ module Collabda
24
27
  return model
25
28
  end
26
29
 
27
- # def self.watch_files
28
- # @classes.map{|c| c.source_path}
29
- # end
30
+ def initialize(attributes_hash={})
31
+ self.class.instance_variable_get("@properties").each do |attribute|
32
+ instance_variable_set("@#{attribute}",attributes_hash[attribute])
33
+ end
34
+ self.class.register_model(self)
35
+ end
30
36
 
31
37
  InvalidSource = Class.new(StandardError)
32
38
  MissingAttributes = Class.new(StandardError)
@@ -39,7 +45,12 @@ module Collabda
39
45
  end
40
46
 
41
47
  def all
42
- @collabda_models
48
+ @collabda_models || []
49
+ end
50
+
51
+ def register_model(model)
52
+ @collabda_models ||= []
53
+ @collabda_models << model
43
54
  end
44
55
 
45
56
  def each(&block)
@@ -54,17 +65,9 @@ module Collabda
54
65
  def build_collection
55
66
  check_validity
56
67
  fetch_data
57
- @collabda_models = @parsed_data.map do |el|
58
- build(el)
59
- end
60
- end
61
-
62
- def build(attributes_hash)
63
- model = self.new
64
- @properties.each do |attribute|
65
- model.instance_variable_set("@#{attribute}",attributes_hash[attribute])
68
+ @parsed_data.each do |el|
69
+ self.new(el)
66
70
  end
67
- model
68
71
  end
69
72
 
70
73
  def properties(*attributes)
@@ -72,10 +72,6 @@ describe "Collabda" do
72
72
  expect(Collabda.instance_variable_get(:@classes)).to include FooList
73
73
  end
74
74
 
75
- # it "maintains a list of yaml files to watch" do
76
- # expect(Collabda.watch_files).to include "spec/lib/foo.yaml"
77
- # end
78
-
79
75
  it "loads yaml data from file" do
80
76
  expect(model_class.parsed_data.count).to eq 3
81
77
  end
@@ -95,10 +91,15 @@ describe "Collabda" do
95
91
  end
96
92
 
97
93
  it "can build a new instance from an attributes hash, bypassing yaml" do
98
- instance = model_class.build(:name=>"Bat",:description=>"man")
94
+ YAML.should_not_receive(:load)
95
+ instance = model_class.new(:name=>"Bat",:description=>"man")
99
96
  expect(instance.description).to eq "man"
100
97
  end
101
98
 
99
+ it "adds to collection when creating an external instance with new" do
100
+ expect{model_class.new(:name=>"Bat",:description=>"man")}.to change{model_class.all.count}.by 1
101
+ end
102
+
102
103
  context "when collection built" do
103
104
  before(:each){model_class.build_collection}
104
105
  it "it provides access to all models" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: collabda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1a
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Edwards-Jones
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-19 00:00:00.000000000 Z
11
+ date: 2013-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -47,9 +47,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
47
47
  version: '0'
48
48
  required_rubygems_version: !ruby/object:Gem::Requirement
49
49
  requirements:
50
- - - '>'
50
+ - - '>='
51
51
  - !ruby/object:Gem::Version
52
- version: 1.3.1
52
+ version: '0'
53
53
  requirements: []
54
54
  rubyforge_project:
55
55
  rubygems_version: 2.1.9