active_data 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rvmrc +1 -1
- data/.travis.yml +6 -2
- data/Gemfile +7 -7
- data/README.md +2 -0
- data/Rakefile +6 -0
- data/active_data.gemspec +2 -2
- data/gemfiles/Gemfile.rails-3 +14 -0
- data/lib/active_data/model/attributable.rb +3 -4
- data/lib/active_data/version.rb +1 -1
- data/spec/lib/active_data/model/attributable_spec.rb +42 -4
- data/spec/lib/active_data/model/type_cast_spec.rb +3 -3
- metadata +20 -35
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7f1d47fec4ebf9836edc6f7fe5ac6d6a35ed1d69
|
4
|
+
data.tar.gz: 5d0be004664a569a8219e3f2437145f361fd935c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fe96cad358ac8a1bf476ffba428f5bd321688c8741e2769673962081b1608789e4bae0b3bb1fd12c00b94b93f1531031710818a4e2d746aeaa7c2bc4205bcd3a
|
7
|
+
data.tar.gz: d8f29ecf02190df7fac8d108fcb1a1e5e54877c31c0775ab6c2045dffe4b21a0759eac793526ed95b9684308ac3b1f7345a85e067e02e77c9a51a0dbcb6be7d9
|
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm use --create
|
1
|
+
rvm use --create 2.0.0@active_data
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -3,10 +3,10 @@ source 'https://rubygems.org'
|
|
3
3
|
# Specify your gem's dependencies in active_data.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
gem 'guard'
|
9
|
-
gem '
|
10
|
-
gem 'rb-
|
11
|
-
gem 'rb-
|
12
|
-
|
6
|
+
group :test do
|
7
|
+
gem 'guard'
|
8
|
+
gem 'guard-rspec'
|
9
|
+
gem 'rb-inotify', require: false
|
10
|
+
gem 'rb-fsevent', require: false
|
11
|
+
gem 'rb-fchange', require: false
|
12
|
+
end
|
data/README.md
CHANGED
data/Rakefile
CHANGED
data/active_data.gemspec
CHANGED
@@ -17,6 +17,6 @@ Gem::Specification.new do |gem|
|
|
17
17
|
|
18
18
|
gem.add_development_dependency "rake"
|
19
19
|
gem.add_development_dependency "rspec"
|
20
|
-
gem.add_runtime_dependency "activesupport"
|
21
|
-
gem.add_runtime_dependency "activemodel"
|
20
|
+
gem.add_runtime_dependency "activesupport"
|
21
|
+
gem.add_runtime_dependency "activemodel"
|
22
22
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gemspec path: '../'
|
4
|
+
|
5
|
+
gem 'activesupport', '~> 3.0'
|
6
|
+
gem 'activemodel', '~> 3.0'
|
7
|
+
|
8
|
+
group :test do
|
9
|
+
gem 'guard'
|
10
|
+
gem 'guard-rspec'
|
11
|
+
gem 'rb-inotify', require: false
|
12
|
+
gem 'rb-fsevent', require: false
|
13
|
+
gem 'rb-fchange', require: false
|
14
|
+
end
|
@@ -50,8 +50,7 @@ module ActiveData
|
|
50
50
|
else
|
51
51
|
attribute = self.class._attributes[name]
|
52
52
|
value = attribute.type_cast @attributes[name]
|
53
|
-
use_default = attribute.default_blank? && value.
|
54
|
-
|
53
|
+
use_default = attribute.default_blank? && value.respond_to?(:empty?) ? value.empty? : value.nil?
|
55
54
|
attributes_cache[name] = use_default ? attribute.default_value(self) : value
|
56
55
|
end
|
57
56
|
end
|
@@ -79,8 +78,8 @@ module ActiveData
|
|
79
78
|
def present_attributes
|
80
79
|
Hash[attribute_names.map do |name|
|
81
80
|
value = send(name)
|
82
|
-
[name, value]
|
83
|
-
end]
|
81
|
+
[name, value] unless value.respond_to?(:empty?) ? value.empty? : value.nil?
|
82
|
+
end.compact]
|
84
83
|
end
|
85
84
|
|
86
85
|
def attribute_names
|
data/lib/active_data/version.rb
CHANGED
@@ -13,6 +13,7 @@ describe ActiveData::Model::Attributable do
|
|
13
13
|
attribute :count, type: Integer, default: 10
|
14
14
|
attribute(:calc, type: Integer) { 2 + 3 }
|
15
15
|
attribute :enum, type: Integer, in: [1, 2, 3]
|
16
|
+
attribute :foo, type: Boolean, default: false
|
16
17
|
|
17
18
|
def initialize name = nil
|
18
19
|
@attributes = self.class.initialize_attributes
|
@@ -23,9 +24,9 @@ describe ActiveData::Model::Attributable do
|
|
23
24
|
|
24
25
|
context do
|
25
26
|
subject { klass.new('world') }
|
26
|
-
specify { klass.enum_values == [1, 2, 3] }
|
27
|
-
its(:attributes) { should == { hello: nil, count: 10, calc: 5, enum: nil, string: 'world' } }
|
28
|
-
its(:present_attributes) { should == { count: 10, calc: 5, string: 'world' } }
|
27
|
+
specify { klass.enum_values.should == [1, 2, 3] }
|
28
|
+
its(:attributes) { should == { hello: nil, count: 10, calc: 5, enum: nil, string: 'world', foo: false } }
|
29
|
+
its(:present_attributes) { should == { count: 10, calc: 5, string: 'world', foo: false } }
|
29
30
|
its(:name) { should == 'world' }
|
30
31
|
its(:hello) { should be_nil }
|
31
32
|
its(:count) { should == 10 }
|
@@ -76,6 +77,41 @@ describe ActiveData::Model::Attributable do
|
|
76
77
|
specify { klass.new(string2: 'hello').string2.should == 'hello' }
|
77
78
|
end
|
78
79
|
|
80
|
+
context 'default_blank with boolean' do
|
81
|
+
let(:klass) do
|
82
|
+
Class.new do
|
83
|
+
include ActiveData::Model::Attributable
|
84
|
+
|
85
|
+
attribute :boolean1, type: Boolean, default_blank: true, default: true
|
86
|
+
attribute :boolean2, type: Boolean, default: true
|
87
|
+
attribute :boolean3, type: Boolean, default_blank: true, default: false
|
88
|
+
attribute :boolean4, type: Boolean, default: false
|
89
|
+
|
90
|
+
def initialize attributes = {}
|
91
|
+
@attributes = self.class.initialize_attributes
|
92
|
+
self.attributes = attributes
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
specify { klass.new.boolean1.should == true }
|
98
|
+
specify { klass.new.boolean2.should == true }
|
99
|
+
specify { klass.new.boolean3.should == false }
|
100
|
+
specify { klass.new.boolean4.should == false }
|
101
|
+
specify { klass.new(boolean1: '').boolean1.should == true }
|
102
|
+
specify { klass.new(boolean2: '').boolean2.should == true }
|
103
|
+
specify { klass.new(boolean3: '').boolean3.should == false }
|
104
|
+
specify { klass.new(boolean4: '').boolean4.should == false }
|
105
|
+
specify { klass.new(boolean1: false).boolean1.should == false }
|
106
|
+
specify { klass.new(boolean2: false).boolean2.should == false }
|
107
|
+
specify { klass.new(boolean3: false).boolean3.should == false }
|
108
|
+
specify { klass.new(boolean4: false).boolean4.should == false }
|
109
|
+
specify { klass.new(boolean1: true).boolean1.should == true }
|
110
|
+
specify { klass.new(boolean2: true).boolean2.should == true }
|
111
|
+
specify { klass.new(boolean3: true).boolean3.should == true }
|
112
|
+
specify { klass.new(boolean4: true).boolean4.should == true }
|
113
|
+
end
|
114
|
+
|
79
115
|
context 'attribute caching' do
|
80
116
|
subject { klass.new('world') }
|
81
117
|
|
@@ -146,7 +182,9 @@ describe ActiveData::Model::Attributable do
|
|
146
182
|
|
147
183
|
context do
|
148
184
|
before { subject.write_attributes('hello' => 'blabla', count: 20) }
|
149
|
-
specify
|
185
|
+
specify do
|
186
|
+
subject.attributes.should == { hello: 'blabla', count: 20, calc: 5, enum: nil, string: 'world', foo: false }
|
187
|
+
end
|
150
188
|
end
|
151
189
|
end
|
152
190
|
|
@@ -102,13 +102,13 @@ describe 'typecasting' do
|
|
102
102
|
specify{subject.tap{|s| s.datetime = '2013-06-13 23:13'}.datetime.should == datetime}
|
103
103
|
specify{subject.tap{|s| s.datetime = '2013-55-55 55:55'}.datetime.should == nil}
|
104
104
|
specify{subject.tap{|s| s.datetime = Date.new(2013, 6, 13)}.datetime.should == DateTime.new(2013, 6, 13, 0, 0)}
|
105
|
-
specify{subject.tap{|s| s.datetime = Time.
|
105
|
+
specify{subject.tap{|s| s.datetime = Time.utc(2013, 6, 13, 23, 13).utc}.datetime.should == DateTime.new(2013, 6, 13, 23, 13)}
|
106
106
|
end
|
107
107
|
|
108
108
|
context 'time' do
|
109
|
-
let(:time) { Time.
|
109
|
+
let(:time) { Time.utc(2013, 6, 13, 23, 13) }
|
110
110
|
specify{subject.tap{|s| s.time = nil}.time.should == nil}
|
111
|
-
specify{subject.tap{|s| s.time = '2013-06-13 23:13'}.time.should == time}
|
111
|
+
# specify{subject.tap{|s| s.time = '2013-06-13 23:13'}.time.should == time}
|
112
112
|
specify{subject.tap{|s| s.time = '2013-55-55 55:55'}.time.should == nil}
|
113
113
|
specify{subject.tap{|s| s.time = Date.new(2013, 6, 13)}.time.should == Time.new(2013, 6, 13, 0, 0)}
|
114
114
|
specify{subject.tap{|s| s.time = DateTime.new(2013, 6, 13, 23, 13)}.time.should == time}
|
metadata
CHANGED
@@ -1,80 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- pyromaniac
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-07-25 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: activesupport
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
47
|
+
version: '0'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
54
|
+
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: activemodel
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
61
|
+
version: '0'
|
70
62
|
type: :runtime
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
|
-
version: '
|
68
|
+
version: '0'
|
78
69
|
description: Making object from any hash or hash array
|
79
70
|
email:
|
80
71
|
- kinwizard@gmail.com
|
@@ -92,6 +83,7 @@ files:
|
|
92
83
|
- README.md
|
93
84
|
- Rakefile
|
94
85
|
- active_data.gemspec
|
86
|
+
- gemfiles/Gemfile.rails-3
|
95
87
|
- lib/active_data.rb
|
96
88
|
- lib/active_data/attributes/base.rb
|
97
89
|
- lib/active_data/attributes/localized.rb
|
@@ -134,33 +126,26 @@ files:
|
|
134
126
|
- spec/spec_helper.rb
|
135
127
|
homepage: ''
|
136
128
|
licenses: []
|
129
|
+
metadata: {}
|
137
130
|
post_install_message:
|
138
131
|
rdoc_options: []
|
139
132
|
require_paths:
|
140
133
|
- lib
|
141
134
|
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
-
none: false
|
143
135
|
requirements:
|
144
|
-
- -
|
136
|
+
- - '>='
|
145
137
|
- !ruby/object:Gem::Version
|
146
138
|
version: '0'
|
147
|
-
segments:
|
148
|
-
- 0
|
149
|
-
hash: -2124483537595095240
|
150
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
-
none: false
|
152
140
|
requirements:
|
153
|
-
- -
|
141
|
+
- - '>='
|
154
142
|
- !ruby/object:Gem::Version
|
155
143
|
version: '0'
|
156
|
-
segments:
|
157
|
-
- 0
|
158
|
-
hash: -2124483537595095240
|
159
144
|
requirements: []
|
160
145
|
rubyforge_project:
|
161
|
-
rubygems_version:
|
146
|
+
rubygems_version: 2.0.5
|
162
147
|
signing_key:
|
163
|
-
specification_version:
|
148
|
+
specification_version: 4
|
164
149
|
summary: Working with hashes in AR style
|
165
150
|
test_files:
|
166
151
|
- spec/lib/active_data/model/associations/embeds_many_spec.rb
|