blobject 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,6 +5,8 @@ source "http://rubygems.org"
5
5
 
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
8
+ gemspec
9
+
8
10
  group :development do
9
11
  gem "shoulda", ">= 0"
10
12
  gem "bundler", "~> 1.0.0"
data/Gemfile.lock CHANGED
@@ -1,3 +1,9 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ blobject (0.1.0)
5
+ blobject
6
+
1
7
  GEM
2
8
  remote: http://rubygems.org/
3
9
  specs:
@@ -14,6 +20,7 @@ PLATFORMS
14
20
  ruby
15
21
 
16
22
  DEPENDENCIES
23
+ blobject!
17
24
  bundler (~> 1.0.0)
18
25
  jeweler (~> 1.5.2)
19
26
  rcov
data/README.rdoc CHANGED
@@ -1,6 +1,30 @@
1
1
  = blobject
2
2
 
3
- Description goes here.
3
+ Blobject is for building untyped blobs of data.
4
+
5
+ An ActiveRecord is not usually enough for view data. The required view data could be more than on ActiveRecords and/or the resultant calculations of some business logic.
6
+
7
+ = Features
8
+
9
+ * call a chain of methods and build an object graph automagically
10
+ * check the existence of a value with 'method?'
11
+ * overrides ruby freeze
12
+ * recursively loads data from JSON strings
13
+ * empty? recursive
14
+
15
+ * init with an object and list of accessors to copy
16
+ * init with hash
17
+ * init with block (frozen)
18
+
19
+
20
+ = Example Usage
21
+
22
+
23
+
24
+ = Limitations
25
+
26
+ Blobjects are intended for de/serialization and there for the cycles in the object graph will lead to a non terminating thread.
27
+
4
28
 
5
29
  == Contributing to blobject
6
30
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/blobject.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{blobject}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Sam Taylor"]
12
- s.date = %q{2011-02-12}
12
+ s.date = %q{2011-04-06}
13
13
  s.description = %q{coming soon}
14
14
  s.email = %q{sjltaylor@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "blobject.gemspec",
28
+ "blobject.psd",
28
29
  "lib/blobject.rb",
29
30
  "test/helper.rb",
30
31
  "test/test_blobject.rb"
@@ -43,17 +44,44 @@ Gem::Specification.new do |s|
43
44
  s.specification_version = 3
44
45
 
45
46
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<blobject>, [">= 0"])
48
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
49
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
50
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
51
+ s.add_development_dependency(%q<rcov>, [">= 0"])
52
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
53
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
54
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
55
+ s.add_development_dependency(%q<rcov>, [">= 0"])
46
56
  s.add_development_dependency(%q<shoulda>, [">= 0"])
47
57
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
48
58
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
49
59
  s.add_development_dependency(%q<rcov>, [">= 0"])
50
60
  else
61
+ s.add_dependency(%q<blobject>, [">= 0"])
62
+ s.add_dependency(%q<shoulda>, [">= 0"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
65
+ s.add_dependency(%q<rcov>, [">= 0"])
66
+ s.add_dependency(%q<shoulda>, [">= 0"])
67
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
68
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
69
+ s.add_dependency(%q<rcov>, [">= 0"])
51
70
  s.add_dependency(%q<shoulda>, [">= 0"])
52
71
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
53
72
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
54
73
  s.add_dependency(%q<rcov>, [">= 0"])
55
74
  end
56
75
  else
76
+ s.add_dependency(%q<blobject>, [">= 0"])
77
+ s.add_dependency(%q<shoulda>, [">= 0"])
78
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
79
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
80
+ s.add_dependency(%q<rcov>, [">= 0"])
81
+ s.add_dependency(%q<shoulda>, [">= 0"])
82
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
83
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
84
+ s.add_dependency(%q<rcov>, [">= 0"])
57
85
  s.add_dependency(%q<shoulda>, [">= 0"])
58
86
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
59
87
  s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
data/blobject.psd ADDED
Binary file
data/lib/blobject.rb CHANGED
@@ -1,3 +1,7 @@
1
+ def blobject *parameters, &block
2
+ Blobject.new *parameters, &block
3
+ end
4
+
1
5
  # similar to OpenStruct
2
6
  # b.foo.bar = 8 automatically creates a blobject called "foo" on "b"
3
7
  # to check whether a variable is defined use the '?' syntax i.e: b.is_it_here? => nil, b.foo? == b.foo
@@ -25,10 +29,20 @@ public
25
29
  unfreeze
26
30
  end
27
31
 
28
- def initialize hash_of_initial_values={}
32
+ def initialize hash_of_initial_values_or_an_object={}, array_of_methods_to_copy_data_from_object=[]
29
33
  @values = {}
30
- merge_hash hash_of_initial_values
31
- yield self if block_given?
34
+
35
+ if (hash_of_initial_values_or_an_object.class == Hash)
36
+ merge_hash hash_of_initial_values_or_an_object
37
+ else
38
+ array_of_methods_to_copy_data_from_object.each do |accessor|
39
+ @values[accessor.to_s] = hash_of_initial_values_or_an_object.send accessor
40
+ end
41
+ end
42
+
43
+ if block_given?
44
+ yield self
45
+ end
32
46
  self
33
47
  end
34
48
 
@@ -46,7 +60,9 @@ public
46
60
  @values[assignment.to_s] = args[0]
47
61
  else
48
62
  # return the value or a new blobject
49
- return @values[str] unless @values[str].nil?
63
+ value = @values[str]
64
+
65
+ return value unless value.nil?
50
66
  return nil if frozen?
51
67
  @values[str] = Blobject.new
52
68
  return @values[str]
@@ -66,7 +82,7 @@ public
66
82
  value = Blobject.blobjectify_array value
67
83
  end
68
84
 
69
- @values[key] = value
85
+ @values[key.to_s] = value
70
86
  end
71
87
  self
72
88
  end
@@ -136,6 +152,20 @@ public
136
152
  end
137
153
 
138
154
  def blank?
139
- @values.blank?
155
+ empty?
156
+ end
157
+
158
+ def empty?
159
+ @values.empty? || @values.values.empty? || !@values.values.any? do |v|
160
+ # if the value is a Blobject, Hash or Array return
161
+ # true if it is not empty.
162
+ # else just return true, the value is regarded as not empty.
163
+ if [Blobject, Array, Hash].include?(v.class)
164
+ !v.empty?
165
+ else
166
+ true
167
+ end
168
+ end
140
169
  end
170
+
141
171
  end
data/test/helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
+
3
4
  begin
4
5
  Bundler.setup(:default, :development)
5
6
  rescue Bundler::BundlerError => e
@@ -1,7 +1,45 @@
1
1
  require 'helper'
2
2
 
3
3
  class TestBlobject < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
4
+ should "not be empty? if the blobject has data" do
5
+ b = Blobject.new
6
+ b.data = 'LOOK! some data. :)'
7
+ assert !b.empty?
8
+ end
9
+
10
+ should "not be empty if the blobject complex with real data" do
11
+ b = Blobject.new
12
+ b.colors.red = '#ff0000'
13
+ assert !b.empty?
14
+ end
15
+
16
+ should 'report empty when there are no descendants' do
17
+ assert Blobject.new.empty?
18
+ end
19
+
20
+ should 'report empty? as true when descendants are empty Hash, Array or Blobjects' do
21
+ b = Blobject.new
22
+ b.array = []
23
+ b.hash = {}
24
+ b.blobject = Blobject.new
25
+ assert b.empty?
26
+ end
27
+
28
+ should 'report empty? as false when descendants include a non-empty Array' do
29
+ b = Blobject.new
30
+ b.array = [1,2,3,4,5]
31
+ assert !b.empty?
32
+ end
33
+
34
+ should 'report empty? as false when descendants include a non-empty Hash' do
35
+ b = Blobject.new
36
+ b.hash = {:key1 => 1, :key2 =>2, :key3 => 3}
37
+ assert !b.empty?
38
+ end
39
+
40
+ should 'report empty? as false when descendants include a non-empty Blobject' do
41
+ b = Blobject.new
42
+ b.blobject = Blobject.new :initial_data => [1,2,3]
43
+ assert !b.empty?
6
44
  end
7
45
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: blobject
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sam Taylor
@@ -10,23 +10,34 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-12 00:00:00 +00:00
13
+ date: 2011-04-06 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
- name: shoulda
17
+ name: blobject
18
18
  requirement: &id001 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
23
  version: "0"
24
- type: :development
24
+ type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: shoulda
29
29
  requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: bundler
40
+ requirement: &id003 !ruby/object:Gem::Requirement
30
41
  none: false
31
42
  requirements:
32
43
  - - ~>
@@ -34,10 +45,10 @@ dependencies:
34
45
  version: 1.0.0
35
46
  type: :development
36
47
  prerelease: false
37
- version_requirements: *id002
48
+ version_requirements: *id003
38
49
  - !ruby/object:Gem::Dependency
39
50
  name: jeweler
40
- requirement: &id003 !ruby/object:Gem::Requirement
51
+ requirement: &id004 !ruby/object:Gem::Requirement
41
52
  none: false
42
53
  requirements:
43
54
  - - ~>
@@ -45,10 +56,10 @@ dependencies:
45
56
  version: 1.5.2
46
57
  type: :development
47
58
  prerelease: false
48
- version_requirements: *id003
59
+ version_requirements: *id004
49
60
  - !ruby/object:Gem::Dependency
50
61
  name: rcov
51
- requirement: &id004 !ruby/object:Gem::Requirement
62
+ requirement: &id005 !ruby/object:Gem::Requirement
52
63
  none: false
53
64
  requirements:
54
65
  - - ">="
@@ -56,7 +67,95 @@ dependencies:
56
67
  version: "0"
57
68
  type: :development
58
69
  prerelease: false
59
- version_requirements: *id004
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: shoulda
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: bundler
84
+ requirement: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 1.0.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *id007
93
+ - !ruby/object:Gem::Dependency
94
+ name: jeweler
95
+ requirement: &id008 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ~>
99
+ - !ruby/object:Gem::Version
100
+ version: 1.5.2
101
+ type: :development
102
+ prerelease: false
103
+ version_requirements: *id008
104
+ - !ruby/object:Gem::Dependency
105
+ name: rcov
106
+ requirement: &id009 !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: "0"
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: *id009
115
+ - !ruby/object:Gem::Dependency
116
+ name: shoulda
117
+ requirement: &id010 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: "0"
123
+ type: :development
124
+ prerelease: false
125
+ version_requirements: *id010
126
+ - !ruby/object:Gem::Dependency
127
+ name: bundler
128
+ requirement: &id011 !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 1.0.0
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: *id011
137
+ - !ruby/object:Gem::Dependency
138
+ name: jeweler
139
+ requirement: &id012 !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ~>
143
+ - !ruby/object:Gem::Version
144
+ version: 1.5.2
145
+ type: :development
146
+ prerelease: false
147
+ version_requirements: *id012
148
+ - !ruby/object:Gem::Dependency
149
+ name: rcov
150
+ requirement: &id013 !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: "0"
156
+ type: :development
157
+ prerelease: false
158
+ version_requirements: *id013
60
159
  description: coming soon
61
160
  email: sjltaylor@gmail.com
62
161
  executables: []
@@ -75,6 +174,7 @@ files:
75
174
  - Rakefile
76
175
  - VERSION
77
176
  - blobject.gemspec
177
+ - blobject.psd
78
178
  - lib/blobject.rb
79
179
  - test/helper.rb
80
180
  - test/test_blobject.rb
@@ -92,7 +192,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
192
  requirements:
93
193
  - - ">="
94
194
  - !ruby/object:Gem::Version
95
- hash: -783933415863142450
195
+ hash: 4269951930364776276
96
196
  segments:
97
197
  - 0
98
198
  version: "0"