structure 0.18.0 → 0.19.0

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.
data/lib/structure.rb CHANGED
@@ -15,8 +15,6 @@ end
15
15
  class Structure
16
16
  include Enumerable
17
17
 
18
- autoload :Static,'structure/static'
19
-
20
18
  class << self
21
19
  # Returns attribute keys and their default values.
22
20
  def defaults
@@ -84,14 +82,6 @@ class Structure
84
82
  def many(name)
85
83
  key name, Array, :default => []
86
84
  end
87
-
88
- # Renders the structure static by setting the path for a YAML file
89
- # that stores the records.
90
- def set_data_file(path)
91
- extend Static unless self.respond_to? :all
92
-
93
- @data_path = path
94
- end
95
85
  end
96
86
 
97
87
  # Creates a new structure.
@@ -1,3 +1,3 @@
1
1
  class Structure
2
- VERSION = '0.18.0'
2
+ VERSION = '0.19.0'
3
3
  end
@@ -89,51 +89,3 @@ class TestStructure < Test::Unit::TestCase
89
89
  assert_equal false, person.as_json(:except => :name).has_key?(:name)
90
90
  end
91
91
  end
92
-
93
- class City < Structure
94
- key :name
95
- end
96
-
97
- class Stadt < Structure
98
- key :name
99
- end
100
-
101
- class TestStatic < Test::Unit::TestCase
102
- def fix(klass, path)
103
- klass.instance_variable_set(:@all, nil)
104
- klass.instance_variable_set(:@id_cnt, nil)
105
- fixture = File.expand_path("../fixtures/#{path}.yml", __FILE__)
106
- klass.set_data_file(fixture)
107
- end
108
-
109
- test "should enumerate at the class level" do
110
- fix City, 'cities'
111
- assert_respond_to City, :map
112
- end
113
-
114
- test "should return all records" do
115
- fix City, 'cities'
116
- cities = City.all
117
- assert_kind_of City, cities.first
118
- assert_equal 2, cities.size
119
- end
120
-
121
- test "should find a record" do
122
- fix City, 'cities'
123
- assert 'New York', City.find(1).name
124
- assert_nil City.find(4)
125
- end
126
-
127
- test "should work if records contain no id field" do
128
- fix City, 'cities_without_ids'
129
- assert_equal 'New York', City.find(1).name
130
- assert_equal 'Paris', City.find(3).name
131
- end
132
-
133
- test "should auto increment independently in each structure" do
134
- fix City, 'cities_without_ids'
135
- fix Stadt, 'cities_without_ids'
136
- assert_equal 'New York', City.find(1).name
137
- assert_equal 'New York', Stadt.find(1).name
138
- end
139
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: structure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.19.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-26 00:00:00.000000000Z
12
+ date: 2011-08-27 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Structure is a typed, nestable key/value container.
15
15
  email:
@@ -26,11 +26,8 @@ files:
26
26
  - Rakefile
27
27
  - lib/structure.rb
28
28
  - lib/structure/rails.rb
29
- - lib/structure/static.rb
30
29
  - lib/structure/version.rb
31
30
  - structure.gemspec
32
- - test/fixtures/cities.yml
33
- - test/fixtures/cities_without_ids.yml
34
31
  - test/structure_test.rb
35
32
  homepage: http://github.com/hakanensari/structure
36
33
  licenses: []
@@ -46,7 +43,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
46
43
  version: '0'
47
44
  segments:
48
45
  - 0
49
- hash: 1483598005415559765
46
+ hash: 4009138194620496744
50
47
  required_rubygems_version: !ruby/object:Gem::Requirement
51
48
  none: false
52
49
  requirements:
@@ -55,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
52
  version: '0'
56
53
  segments:
57
54
  - 0
58
- hash: 1483598005415559765
55
+ hash: 4009138194620496744
59
56
  requirements: []
60
57
  rubyforge_project: structure
61
58
  rubygems_version: 1.8.6
@@ -63,6 +60,4 @@ signing_key:
63
60
  specification_version: 3
64
61
  summary: A typed, nestable key/value container
65
62
  test_files:
66
- - test/fixtures/cities.yml
67
- - test/fixtures/cities_without_ids.yml
68
63
  - test/structure_test.rb
@@ -1,40 +0,0 @@
1
- require 'yaml'
2
-
3
- # This module provides the class methods that render a structure
4
- # static, where records are sourced from a YAML file.
5
- class Structure
6
- module Static
7
- include Enumerable
8
-
9
- def self.extended(base)
10
- base.key(:_id, Integer)
11
- end
12
-
13
- # The data file path.
14
- attr :data_path
15
-
16
- # Returns all records.
17
- def all
18
- @all ||= YAML.load_file(data_path).map do |hsh|
19
- hsh['_id'] ||= hsh.delete('id') || hsh.delete('ID') || incr_id
20
- new(hsh)
21
- end
22
- end
23
-
24
- # Yields each record to given block.
25
- def each(&block)
26
- all.each { |item| block.call(item) }
27
- end
28
-
29
- # Finds a record by its ID.
30
- def find(id)
31
- super() { |item| item._id == id }
32
- end
33
-
34
- private
35
-
36
- def incr_id
37
- @id_cnt = @id_cnt.to_i + 1
38
- end
39
- end
40
- end
@@ -1,5 +0,0 @@
1
- ---
2
- - id: 1
3
- name: New York
4
- - id: 2
5
- name: Tokyo
@@ -1,4 +0,0 @@
1
- ---
2
- - name: New York
3
- - name: Tokyo
4
- - name: Paris