active_type 0.1.2 → 0.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 246d6b642fc001e5a1df57b9c4cd42e20a6fe68c
4
- data.tar.gz: dbce1038dc7d9d74d6258927e0e3a1bfb995af70
3
+ metadata.gz: e159c5c5648aa7f407cd38c73d3e05fa630aa2a4
4
+ data.tar.gz: 2bcb2536092006f2b519596e5f7b5c0655308920
5
5
  SHA512:
6
- metadata.gz: 68925ab89dbead458c046fcdea66fc7493e16e616af15aec2647c5800851f7bc6db00fc1f61077aadabebf310b1a52dec2c84e8f64c37aa012c0886173c5e5d4
7
- data.tar.gz: e7dd74a94787288cc37b6dadfbae1f4e3451cb6707c4733cd6e1dd357bc906b8bc323fe08102b7824d9661fee7d0fb57b6dc6a9e642618233f1f5514920233ac
6
+ metadata.gz: 6d1f0bac7db1d6382c1ab3f62c6e1f72bd82ac02a848b516340871bfeec9302fc95b09588ee7c040b6f0e35d8014640aa683238a8b9e909df7deff18a39f5c44
7
+ data.tar.gz: 3d1a06ab7508e69fea48fdcb5e9fa6aeed6ee3c42778d168fa23576ba0c2dbd67c09d4c04bd3b8cfda77131d250997b1f1016763b3b626e2f368eefe319b69bc
data/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - "1.8.7"
3
4
  - "1.9.3"
4
5
  - "2.0.0"
5
6
  - "2.1.0"
@@ -14,3 +15,9 @@ notifications:
14
15
  branches:
15
16
  only:
16
17
  - master
18
+ matrix:
19
+ exclude:
20
+ - rvm: "1.8.7"
21
+ gemfile: gemfiles/Gemfile.4.0
22
+ - rvm: "1.8.7"
23
+ gemfile: gemfiles/Gemfile.4.1
data/README.md CHANGED
@@ -72,7 +72,7 @@ These attributes can be assigned via constructor, mass-assignment, and are autom
72
72
  ```ruby
73
73
  sign_in = SignIn.new(date_of_birth: "1980-01-01", accepted_terms: "1")
74
74
  sign_in.date_of_birth.class # Date
75
- sign_in.accepted_terms # true
75
+ sign_in.accepted_terms? # true
76
76
  ```
77
77
 
78
78
  **`ActiveType::Object` actually inherits from `ActiveRecord::Base`, but simply skips all database access, inspired by [ActiveRecord Tableless](https://github.com/softace/activerecord-tableless).**
@@ -1,3 +1,3 @@
1
1
  module ActiveType
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -95,10 +95,12 @@ module ActiveType
95
95
  self.virtual_columns_hash = {}
96
96
  end
97
97
 
98
- def initialize(*)
99
- @virtual_attributes = {}
100
- @virtual_attributes_cache = {}
101
- super
98
+ def virtual_attributes
99
+ @virtual_attributes ||= {}
100
+ end
101
+
102
+ def virtual_attributes_cache
103
+ @virtual_attributes_cache ||= {}
102
104
  end
103
105
 
104
106
  def [](name)
@@ -125,15 +127,15 @@ module ActiveType
125
127
 
126
128
  def read_virtual_attribute(name)
127
129
  name = name.to_s
128
- @virtual_attributes_cache[name] ||= begin
129
- self.singleton_class._virtual_column(name).type_cast(@virtual_attributes[name])
130
+ virtual_attributes_cache[name] ||= begin
131
+ self.singleton_class._virtual_column(name).type_cast(virtual_attributes[name])
130
132
  end
131
133
  end
132
134
 
133
135
  def write_virtual_attribute(name, value)
134
136
  name = name.to_s
135
- @virtual_attributes_cache.delete(name)
136
- @virtual_attributes[name] = value
137
+ virtual_attributes_cache.delete(name)
138
+ virtual_attributes[name] = value
137
139
  end
138
140
 
139
141
  module ClassMethods
@@ -1,4 +1,21 @@
1
+ class User < ::ActiveRecord::Base
2
+ end
3
+
4
+ class Foo < ::ActiveType::Record[User]
5
+ def new
6
+ allocate
7
+ end
8
+ end
9
+
10
+
1
11
  shared_examples_for "ActiveRecord-like accessors" do |attributes|
12
+ it 'setup the virtual_attributes instance variable lazy' do
13
+ expect(Foo.new.virtual_attributes).to eq({})
14
+ end
15
+
16
+ it 'setup the virtual_attributes_cache instance variable lazy' do
17
+ expect(Foo.new.virtual_attributes_cache).to eq({})
18
+ end
2
19
 
3
20
  it 'allows to read and write' do
4
21
  attributes.each do |key, value|
@@ -124,7 +124,7 @@ shared_examples_for 'a coercible time column' do |column|
124
124
  it 'converts strings to times' do
125
125
  subject.send(:"#{column}=", "2010-10-01 12:15")
126
126
 
127
- subject.send(column).should == Time.new(2010, 10, 1, 12, 15)
127
+ subject.send(column).should == Time.local(2010, 10, 1, 12, 15)
128
128
  end
129
129
 
130
130
  it 'behaves consistently with ActiveRecord' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_type
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Kraze
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-28 00:00:00.000000000 Z
12
+ date: 2014-07-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  version: '0'
118
118
  requirements: []
119
119
  rubyforge_project:
120
- rubygems_version: 2.2.1
120
+ rubygems_version: 2.1.11
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: Make any Ruby object quack like ActiveRecord