id 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- id (0.0.6)
4
+ id (0.0.7)
5
5
  activesupport
6
6
  money
7
7
  optional
@@ -17,7 +17,7 @@ GEM
17
17
  money (5.1.1)
18
18
  i18n (~> 0.6.0)
19
19
  multi_json (1.7.2)
20
- optional (0.0.3)
20
+ optional (0.0.4)
21
21
  rspec (2.13.0)
22
22
  rspec-core (~> 2.13.0)
23
23
  rspec-expectations (~> 2.13.0)
data/id.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'id'
3
- s.version = '0.0.7'
3
+ s.version = '0.0.8'
4
4
  s.date = '2013-03-28'
5
5
  s.summary = "Simple models based on hashes"
6
6
  s.description = "Developed at On The Beach Ltd. Contact russell.dunphy@onthebeach.co.uk"
data/lib/id/all.rb CHANGED
@@ -2,3 +2,4 @@ require_relative 'missing_attribute_error'
2
2
  require_relative 'hashifier'
3
3
  require_relative 'model/all'
4
4
  require_relative 'model'
5
+ require_relative 'timestamps'
data/lib/id/model.rb CHANGED
@@ -2,7 +2,7 @@ module Id
2
2
  module Model
3
3
  attr_reader :data
4
4
 
5
- def initialize(data)
5
+ def initialize(data = {})
6
6
  @data = Hashifier.hashify(data)
7
7
  end
8
8
 
@@ -0,0 +1,23 @@
1
+ module Id
2
+ module Timestamps
3
+
4
+ def self.included(base)
5
+ base.field :created_at
6
+ base.field :updated_at
7
+ end
8
+
9
+ def initialize(data = {})
10
+ super data.merge(_timestamps data)
11
+ end
12
+
13
+ private
14
+
15
+ def _timestamps(data, now=Time.now)
16
+ {
17
+ created_at: data.fetch('created_at', now),
18
+ updated_at: now
19
+ }
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ class TimeStampedModel
4
+ include Id::Model
5
+ include Id::Timestamps
6
+
7
+ field :foo
8
+ field :bar
9
+ end
10
+
11
+ module Id
12
+ describe Timestamps do
13
+
14
+ let (:model) { TimeStampedModel.new(foo: 999, bar: 666) }
15
+
16
+ it 'should have a created_at date' do
17
+ model.created_at.should be_a Time
18
+ end
19
+
20
+ it 'should have an updated_at date' do
21
+ model.updated_at.should be_a Time
22
+ end
23
+
24
+ it 'should update the updated at when set is called' do
25
+ updated = model.set(foo: 123)
26
+ expect(updated.created_at).to be < updated.updated_at
27
+ end
28
+
29
+ it 'should update the updated at when unset is called' do
30
+ updated = model.unset(:foo)
31
+ expect(updated.created_at).to be < updated.updated_at
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ class Mike
4
+ include Id::Model
5
+
6
+ field :cat
7
+ field :dog, optional: true
8
+
9
+ def catdog
10
+ dog.value_or cat
11
+ end
12
+
13
+ end
14
+
15
+ describe "Foobar" do
16
+ let (:mike) { Mike.new(cat: 'pooface') }
17
+ it 'returns cat' do
18
+ mike.catdog.should eq 'pooface'
19
+ end
20
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -119,11 +119,14 @@ files:
119
119
  - lib/id/model/has_many.rb
120
120
  - lib/id/model/has_one.rb
121
121
  - lib/id/model/type_casts.rb
122
+ - lib/id/timestamps.rb
122
123
  - spec/lib/id/model/association_spec.rb
123
124
  - spec/lib/id/model/builder_spec.rb
124
125
  - spec/lib/id/model/has_one_spec.rb
125
126
  - spec/lib/id/model/type_casts_spec.rb
126
127
  - spec/lib/id/model_spec.rb
128
+ - spec/lib/id/timestamps_spec.rb
129
+ - spec/lib/mike_spec.rb
127
130
  - spec/spec_helper.rb
128
131
  homepage: http://github.com/onthebeach/id
129
132
  licenses: []
@@ -155,5 +158,7 @@ test_files:
155
158
  - spec/lib/id/model/has_one_spec.rb
156
159
  - spec/lib/id/model/type_casts_spec.rb
157
160
  - spec/lib/id/model_spec.rb
161
+ - spec/lib/id/timestamps_spec.rb
162
+ - spec/lib/mike_spec.rb
158
163
  - spec/spec_helper.rb
159
164
  has_rdoc: