domain_model 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/domain_model.rb CHANGED
@@ -65,10 +65,18 @@ module DomainModel
65
65
  other.is_a?(self.class) && attributes == other.attributes
66
66
  end
67
67
 
68
+ def to_s
69
+ inspect
70
+ end
71
+
68
72
  def inspect
69
73
  "#<#{self.class} " + attributes.map { |n, v| "#{n}: #{v.inspect}" }.join(", ") + ">"
70
74
  end
71
75
 
76
+ def empty?
77
+ self.class.fields.all? { |f| send(f.name).nil? }
78
+ end
79
+
72
80
  def attributes
73
81
  attributes = {}
74
82
  self.class.fields.map(&:name).each do |name|
@@ -176,7 +184,6 @@ module DomainModel
176
184
  Validator.errors(self, value)
177
185
  end
178
186
 
179
-
180
187
  def monotype
181
188
  types.first if types.count == 1
182
189
  end
@@ -1,3 +1,3 @@
1
1
  module DomainModel
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -469,6 +469,16 @@ describe DomainModel do
469
469
  end
470
470
  end
471
471
 
472
+
473
+ describe "#to_s" do
474
+ before { define { field :field } }
475
+
476
+ it "shows the name and value of all fields" do
477
+ client = Client.new(:field => "VALUE")
478
+ expect(client.to_s).to match(/field: "VALUE"/)
479
+ end
480
+ end
481
+
472
482
  describe "#inspect" do
473
483
  before { define { field :field } }
474
484
 
@@ -478,6 +488,20 @@ describe DomainModel do
478
488
  end
479
489
  end
480
490
 
491
+ describe "#empty?" do
492
+ before { define { field :field } }
493
+
494
+ it "is true if all fields are nil" do
495
+ client = Client.new(:field => nil)
496
+ expect(client.empty?).to eq(true)
497
+ end
498
+
499
+ it "is false if any fields are set" do
500
+ client = Client.new(:field => "SET")
501
+ expect(client.empty?).to eq(false)
502
+ end
503
+ end
504
+
481
505
  describe "#valid?" do
482
506
  it "is true if there are no errors" do
483
507
  define { field :field }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domain_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.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: 2015-03-30 00:00:00.000000000 Z
12
+ date: 2015-05-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake