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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a48e9858e6427010ea2fd9a3eed6bbce23ec937
4
- data.tar.gz: a12796dd65e3629247a51b3d98934bdf5eda6a8f
3
+ metadata.gz: c26804a67602226869134d4830cd56bb002e6fa1
4
+ data.tar.gz: c51a28f44ef045e5025f83ba2881730b7a8d076c
5
5
  SHA512:
6
- metadata.gz: c39c375f692678255881a6dbd488e9a45cafb931e0a83b745a8fe214a75c5d1d76a62d95efc730af924966998d134990e29469ef43270072c10a99f303cb349f
7
- data.tar.gz: 5c403918f66223d3c3d3eddf19379ac115505fcf31b2a5fd69185db2d93d1a6adc9444235c58c3ca07fc722f6668bc1d29d7da68b8ed626edb4e4eb3f225843b
6
+ metadata.gz: 13b609a39fc2baa89f90baa88745d8445c65752e80e81e9459063841cc38908110d868678b8e2127d6269460e8538b16829d57df39c9da2e1c91bca4bd2ad187
7
+ data.tar.gz: f6c218f0f6bb04c43216b6e378bd66cb14426c652e7929162a7f42160198fdd61c21983da5133e99f6ecf4e23fb084b89952c61aa24c8b0147d1330bd04d69b4
@@ -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'
@@ -2,7 +2,7 @@
2
2
 
3
3
  class Object
4
4
  def blank?
5
- !self
5
+ !self
6
6
  end unless method_defined? :blank?
7
7
 
8
8
  def present?
@@ -19,9 +19,9 @@ module Attrio
19
19
  @attribute = attribute; @value = value;
20
20
  end
21
21
 
22
- # Evaluates the value
22
+ # Evaluates the value
23
23
  # @return [Object] evaluated value
24
- #
24
+ #
25
25
  def call(instance)
26
26
  raise NotImplementedError
27
27
  end
@@ -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
@@ -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
@@ -3,8 +3,8 @@
3
3
  module Attrio
4
4
  module Version
5
5
  MAJOR = 0
6
- MINOR = 6
7
- PATCH = 2
6
+ MINOR = 7
7
+ PATCH = 0
8
8
  BUILD = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
@@ -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
@@ -6,7 +6,7 @@ $:.unshift File.expand_path('../../lib', __FILE__)
6
6
  require 'attrio'
7
7
  require 'rspec'
8
8
  require 'webmock/rspec'
9
-
9
+ require 'json'
10
10
  require 'coveralls'
11
11
  Coveralls.wear!
12
12
 
@@ -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){ mock('attribute')}
19
- let(:default_value){ mock('default_value')}
20
- let(:response) { stub('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){ mock('attribute')}
19
- let(:default_value){ mock('default_value')}
20
- let(:instance) { mock('instance') }
21
- let(:clone) { mock('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(mock('attribute'), default) }
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.6.2
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-10-20 00:00:00.000000000 Z
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: