attrio 0.6.2 → 0.7.0
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 +4 -4
- data/attrio.gemspec +1 -0
- data/lib/attrio/core_ext/object.rb +1 -1
- data/lib/attrio/default_value/base.rb +2 -2
- data/lib/attrio/initialize.rb +3 -2
- data/lib/attrio/reset.rb +0 -16
- data/lib/attrio/version.rb +2 -2
- data/spec/integration/inheritance_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -1
- data/spec/unit/attrio_spec.rb +5 -5
- data/spec/unit/default_value/callable_spec.rb +8 -8
- data/spec/unit/default_value/clonable_spec.rb +9 -9
- data/spec/unit/default_value/handle_spec.rb +1 -1
- metadata +16 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c26804a67602226869134d4830cd56bb002e6fa1
|
4
|
+
data.tar.gz: c51a28f44ef045e5025f83ba2881730b7a8d076c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13b609a39fc2baa89f90baa88745d8445c65752e80e81e9459063841cc38908110d868678b8e2127d6269460e8538b16829d57df39c9da2e1c91bca4bd2ad187
|
7
|
+
data.tar.gz: f6c218f0f6bb04c43216b6e378bd66cb14426c652e7929162a7f42160198fdd61c21983da5133e99f6ecf4e23fb084b89952c61aa24c8b0147d1330bd04d69b4
|
data/attrio.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.add_development_dependency 'rspec'
|
21
21
|
gem.add_development_dependency 'webmock', '~> 1.9.0'
|
22
22
|
gem.add_development_dependency 'simplecov'
|
23
|
+
gem.add_development_dependency 'json'
|
23
24
|
gem.add_development_dependency 'coveralls'
|
24
25
|
gem.add_development_dependency 'rake'
|
25
26
|
gem.add_development_dependency 'bundler'
|
data/lib/attrio/initialize.rb
CHANGED
@@ -5,16 +5,17 @@ module Attrio
|
|
5
5
|
def new(*args, &block)
|
6
6
|
obj = self.allocate
|
7
7
|
|
8
|
+
obj.send :initialize, *args, &block
|
9
|
+
|
8
10
|
obj.class.attrio.each do |group, options|
|
9
11
|
obj.instance_variable_set("@#{group}", {})
|
10
12
|
obj.class.send("#{group}").each do |name, attribute|
|
11
13
|
obj.send("#{group}")[name] = attribute.dup
|
12
14
|
obj.send("#{group}")[name].instance_variable_set(:@object, obj)
|
13
|
-
obj.send("#{group}")[name].reset!
|
15
|
+
obj.send("#{group}")[name].reset! if obj.send(name).blank?
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
|
-
obj.send :initialize, *args, &block
|
18
19
|
obj
|
19
20
|
end
|
20
21
|
end
|
data/lib/attrio/reset.rb
CHANGED
@@ -9,24 +9,8 @@ module Attrio
|
|
9
9
|
module ClassMethods
|
10
10
|
def define_attrio_reset(as)
|
11
11
|
define_method "reset_#{as.to_s}" do |attributes = []|
|
12
|
-
# self.send(as.to_s, attributes).values.each{ |attribute| self.send(attribute.writer_method_name, nil) }
|
13
|
-
# self.send("set_#{as.to_s}_defaults", attributes)
|
14
12
|
self.send(as.to_s, attributes).values.each{ |attribute| attribute.reset! }
|
15
13
|
end
|
16
|
-
|
17
|
-
# define_method "reset_#{as.to_s}_defaults" do |attributes = []|
|
18
|
-
# self.send(as.to_s, attributes).values.select{ |attribute| !attribute.default_value.nil? }.each { |attribute| self.send(attribute.writer_method_name, nil) }
|
19
|
-
# self.send("set_#{as.to_s}_defaults", attributes)
|
20
|
-
# end
|
21
|
-
|
22
|
-
# define_method "set_#{as.to_s}_defaults" do |attributes = []|
|
23
|
-
# self.send(as.to_s, attributes).values.select{ |attribute| !attribute.default_value.nil? }.each do |attribute|
|
24
|
-
# next if self.send(attribute.reader_method_name).present?
|
25
|
-
|
26
|
-
# default_value = attribute.default_value.is_a?(Attrio::DefaultValue::Base) ? attribute.default_value.call(self) : attribute.default_value
|
27
|
-
# self.send(attribute.writer_method_name, default_value)
|
28
|
-
# end
|
29
|
-
# end
|
30
14
|
end
|
31
15
|
end
|
32
16
|
end
|
data/lib/attrio/version.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe 'Attributes inheritance' do
|
3
|
+
describe 'Attributes inheritance' do
|
4
4
|
before(:all) do
|
5
5
|
class Parent
|
6
6
|
include Attrio
|
7
7
|
|
8
8
|
define_attributes do
|
9
9
|
attr :email, String
|
10
|
-
attr :name, String
|
10
|
+
attr :name, String
|
11
11
|
attr :created_at, DateTime, :default => proc{ Time.now }
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
class ChildWithoutAttributes < Parent
|
15
|
+
class ChildWithoutAttributes < Parent
|
16
16
|
end
|
17
17
|
|
18
18
|
class ChildWithNewAttributes < Parent
|
data/spec/spec_helper.rb
CHANGED
data/spec/unit/attrio_spec.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Attrio do
|
3
|
+
describe Attrio do
|
4
4
|
let(:model) do
|
5
5
|
attributes_name = self.respond_to?(:attributes_name) ? self.attributes_name : 'attributes'
|
6
|
-
|
7
|
-
Class.new do
|
6
|
+
|
7
|
+
Class.new do
|
8
8
|
include Attrio
|
9
9
|
|
10
10
|
define_attributes :as => attributes_name do
|
@@ -28,7 +28,7 @@ describe Attrio do
|
|
28
28
|
it { should respond_to(:reset_attributes) }
|
29
29
|
it { should respond_to(:attributes) }
|
30
30
|
|
31
|
-
context '#attributes' do
|
31
|
+
context '#attributes' do
|
32
32
|
it 'should be a kind of Hash' do
|
33
33
|
subject.attributes.should be_a_kind_of Hash
|
34
34
|
end
|
@@ -46,7 +46,7 @@ describe Attrio do
|
|
46
46
|
subject.attributes([:name]).keys.should match_array([:name])
|
47
47
|
end
|
48
48
|
|
49
|
-
it 'should return a blank set of attributes for not existing filter' do
|
49
|
+
it 'should return a blank set of attributes for not existing filter' do
|
50
50
|
subject.attributes([:not_existing_attribute]).keys.should match_array([])
|
51
51
|
end
|
52
52
|
end
|
@@ -7,17 +7,17 @@ describe Attrio::DefaultValue::Callable do
|
|
7
7
|
Class.new do
|
8
8
|
include Attrio
|
9
9
|
|
10
|
-
define_attributes do
|
11
|
-
attr :attribute, DateTime, :default => proc{ DateTime.now }
|
10
|
+
define_attributes do
|
11
|
+
attr :attribute, DateTime, :default => proc{ DateTime.now }
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
let(:object){ model.new }
|
17
17
|
|
18
|
-
let(:attribute){
|
19
|
-
let(:default_value){
|
20
|
-
let(:response) {
|
18
|
+
let(:attribute){ double('attribute')}
|
19
|
+
let(:default_value){ double('default_value')}
|
20
|
+
let(:response) { double('response') }
|
21
21
|
|
22
22
|
before { default_value.stub(:call => response) }
|
23
23
|
it 'should call the value with the object and attribute' do
|
@@ -25,12 +25,12 @@ describe Attrio::DefaultValue::Callable do
|
|
25
25
|
subject.call(object)
|
26
26
|
end
|
27
27
|
|
28
|
-
it "should set attribute value to appropriate type" do
|
29
|
-
object.attribute.should be_instance_of(DateTime)
|
28
|
+
it "should set attribute value to appropriate type" do
|
29
|
+
object.attribute.should be_instance_of(DateTime)
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should be evaluate attribute value every time" do
|
33
|
-
another_object = model.new
|
33
|
+
another_object = model.new
|
34
34
|
|
35
35
|
object.attribute.should_not be_equal(another_object.attribute)
|
36
36
|
end
|
@@ -7,18 +7,18 @@ describe Attrio::DefaultValue::Clonable do
|
|
7
7
|
Class.new do
|
8
8
|
include Attrio
|
9
9
|
|
10
|
-
define_attributes do
|
11
|
-
attr :attribute, Date, :default => Date.today
|
12
|
-
end
|
10
|
+
define_attributes do
|
11
|
+
attr :attribute, Date, :default => Date.today
|
12
|
+
end
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
let(:object){ model.new }
|
17
17
|
|
18
|
-
let(:attribute){
|
19
|
-
let(:default_value){
|
20
|
-
let(:instance) {
|
21
|
-
let(:clone) {
|
18
|
+
let(:attribute){ double('attribute')}
|
19
|
+
let(:default_value){ double('default_value')}
|
20
|
+
let(:instance) { double('instance') }
|
21
|
+
let(:clone) { double('clone') }
|
22
22
|
|
23
23
|
before { default_value.stub(:clone => clone) }
|
24
24
|
|
@@ -32,7 +32,7 @@ describe Attrio::DefaultValue::Clonable do
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should set attribute value to appropriate type" do
|
35
|
-
object.attribute.should be_instance_of(Date)
|
35
|
+
object.attribute.should be_instance_of(Date)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should not be equal to clonable object" do
|
@@ -41,5 +41,5 @@ describe Attrio::DefaultValue::Clonable do
|
|
41
41
|
|
42
42
|
it "should have the same value as clonable object" do
|
43
43
|
object.attribute.should == Date.today
|
44
|
-
end
|
44
|
+
end
|
45
45
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Attrio::DefaultValue::Base, '.handle' do
|
4
|
-
subject { described_class.handle(
|
4
|
+
subject { described_class.handle(double('attribute'), default) }
|
5
5
|
|
6
6
|
context 'when default is a symbol' do
|
7
7
|
let(:default) { :symbol }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attrio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Alexandrov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-11-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -53,6 +53,20 @@ dependencies:
|
|
53
53
|
- - '>='
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: json
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
56
70
|
- !ruby/object:Gem::Dependency
|
57
71
|
name: coveralls
|
58
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -202,4 +216,3 @@ test_files:
|
|
202
216
|
- spec/unit/types/integer_spec.rb
|
203
217
|
- spec/unit/types/symbol_spec.rb
|
204
218
|
- spec/unit/types/time_spec.rb
|
205
|
-
has_rdoc:
|