yukata 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/yukata.rb +9 -10
  3. data/lib/yukata/coercer.rb +7 -1
  4. data/lib/yukata/coercion.rb +7 -0
  5. data/lib/yukata/coercions.rb +25 -0
  6. data/lib/yukata/coercions/boolean_definitions.rb +15 -0
  7. data/lib/yukata/coercions/date_definitions.rb +13 -0
  8. data/lib/yukata/coercions/date_time_definitions.rb +13 -0
  9. data/lib/yukata/coercions/fixnum_definitions.rb +15 -0
  10. data/lib/yukata/coercions/float_definitions.rb +13 -0
  11. data/lib/yukata/coercions/hash_definitions.rb +10 -0
  12. data/lib/yukata/coercions/integer_definitions.rb +12 -0
  13. data/lib/yukata/coercions/string_definitions.rb +26 -0
  14. data/lib/yukata/coercions/time_definitions.rb +13 -0
  15. data/lib/yukata/version.rb +1 -1
  16. data/spec/attribute_spec.rb +26 -0
  17. data/spec/base_spec.rb +30 -0
  18. data/spec/coercer_spec.rb +0 -0
  19. data/spec/coercion_spec.rb +21 -0
  20. data/spec/coercions/boolean_definitions_spec.rb +27 -0
  21. data/spec/coercions/date_definitions_spec.rb +45 -0
  22. data/spec/coercions/date_time_definitions_spec.rb +45 -0
  23. data/spec/coercions/fixnum_definitions_spec.rb +52 -0
  24. data/spec/spec_helper.rb +9 -0
  25. data/yukata.gemspec +1 -0
  26. metadata +41 -11
  27. data/lib/yukata/coercions/array.rb +0 -1
  28. data/lib/yukata/coercions/boolean.rb +0 -8
  29. data/lib/yukata/coercions/date.rb +0 -5
  30. data/lib/yukata/coercions/date_time.rb +0 -5
  31. data/lib/yukata/coercions/fixnum.rb +0 -7
  32. data/lib/yukata/coercions/float.rb +0 -5
  33. data/lib/yukata/coercions/hash.rb +0 -2
  34. data/lib/yukata/coercions/integer.rb +0 -4
  35. data/lib/yukata/coercions/string.rb +0 -26
  36. data/lib/yukata/coercions/time.rb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68d1cd6c9e92b7ccbba49d39f24f4d20355a6c96
4
- data.tar.gz: 8c9fab7697bc288497caecd0089dfde6e9310d57
3
+ metadata.gz: d7b57e16a64efce928a8711ebd9d5e5eb365b369
4
+ data.tar.gz: 0d2286cb23cc7d2f990dbe80bf76320186a74bab
5
5
  SHA512:
6
- metadata.gz: aaa51bd713c2164695f872340028cedcb1e9e5c2555a67c468a3e15e2294f73e79b171e71fdc41d9129f58e6f5fb086055a59bd786a83014995ba7bdf8f9f4a3
7
- data.tar.gz: 34cd56683a72bad059963563054c9f20742e6398a55ac3113be0cb771732247421c68a1809d88ba8727f3b8e395df3edffa998408be328c062ff3b5a92680c7b
6
+ metadata.gz: f73c161f1afbead3c48916976e0bc775c2741bdce4a94e03a737ecbee2d26ed30b12fd27c358e561f892543aeb7f5e1466363a185e67b9749eda1df5043a895a
7
+ data.tar.gz: 68749b61090828c39497aac9bb26d281b5ece1ad4cd19faa9810782591e3962610a158bb3100d749499562b541e11294841a9a3b439c277566615938893b4f4b
@@ -2,24 +2,23 @@ require 'json'
2
2
 
3
3
  require 'yukata/version'
4
4
  require 'yukata/errors'
5
+ require 'yukata/coercions'
5
6
  require 'yukata/coercion'
6
7
  require 'yukata/coercer'
7
8
 
8
9
  module Yukata
9
10
  def self.coercer
10
- @coercer ||= Yukata::Coercer.new
11
+ return @coercer if @coercer
12
+ @coercer = Yukata::Coercer.new
13
+ Yukata::Coercions.bind_to(@coercer)
14
+ @coercer
15
+ end
16
+
17
+ def self.coercer=(coercer)
18
+ @coercer = coercer
11
19
  end
12
20
  end
13
21
 
14
22
  require 'yukata/attribute'
15
23
  require 'yukata/base'
16
24
 
17
- require 'yukata/coercions/date'
18
- require 'yukata/coercions/date_time'
19
- require 'yukata/coercions/fixnum'
20
- require 'yukata/coercions/float'
21
- require 'yukata/coercions/integer'
22
- require 'yukata/coercions/string'
23
- require 'yukata/coercions/time'
24
- require 'yukata/coercions/hash'
25
- require 'yukata/coercions/boolean'
@@ -1,4 +1,8 @@
1
1
  module Yukata
2
+ # The class that coerces objects based on the definitions that are registered
3
+ # with it.
4
+ #
5
+ # @author Matthew A. Johnston
2
6
  class Coercer
3
7
  def initialize
4
8
  @coercions = Hash.new do |hash, origin|
@@ -34,7 +38,9 @@ module Yukata
34
38
  # @param object [Object] the object to coerce
35
39
  # @param target [Class] what you want the object to turn in to
36
40
  def coerce(object, target)
37
- @coercions[object.class][target].call(object)
41
+ @mutex.synchronize do
42
+ @coercions[object.class][target].call(object)
43
+ end
38
44
  end
39
45
  end
40
46
  end
@@ -1,15 +1,22 @@
1
1
  module Yukata
2
+ # This wraps the block that is provided when you register a coercion.
3
+ #
2
4
  # @author Matthew A. Johnston
3
5
  class Coercion
4
6
  # Just passes the object on through
5
7
  PASS_THROUGH = ->(obj, _) { obj }
6
8
 
9
+ # @param origin [Class] the class that the object is
10
+ # @param target [Class] the class you wish to coerce to
7
11
  def initialize(origin, target, &block)
8
12
  @origin = origin
9
13
  @target = target
10
14
  @block = block_given? ? block : PASS_THROUGH
11
15
  end
12
16
 
17
+ # Calls the coercion
18
+ #
19
+ # @return [Object]
13
20
  def call(object)
14
21
  @block.call(object, @target)
15
22
  end
@@ -0,0 +1,25 @@
1
+ require 'yukata/coercions/date_definitions'
2
+ require 'yukata/coercions/date_time_definitions'
3
+ require 'yukata/coercions/fixnum_definitions'
4
+ require 'yukata/coercions/float_definitions'
5
+ require 'yukata/coercions/integer_definitions'
6
+ require 'yukata/coercions/string_definitions'
7
+ require 'yukata/coercions/time_definitions'
8
+ require 'yukata/coercions/hash_definitions'
9
+ require 'yukata/coercions/boolean_definitions'
10
+
11
+ module Yukata
12
+ module Coercions
13
+ def self.bind_to(coercer)
14
+ Yukata::Coercions::DateDefinitions.bind_to(coercer)
15
+ Yukata::Coercions::DateTimeDefinitions.bind_to(coercer)
16
+ Yukata::Coercions::FixnumDefinitions.bind_to(coercer)
17
+ Yukata::Coercions::FloatDefinitions.bind_to(coercer)
18
+ Yukata::Coercions::IntegerDefinitions.bind_to(coercer)
19
+ Yukata::Coercions::StringDefinitions.bind_to(coercer)
20
+ Yukata::Coercions::TimeDefinitions.bind_to(coercer)
21
+ Yukata::Coercions::HashDefinitions.bind_to(coercer)
22
+ Yukata::Coercions::BooleanDefinitions.bind_to(coercer)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ unless defined?(Boolean)
2
+ class Boolean
3
+ end
4
+ end
5
+
6
+ module Yukata
7
+ module Coercions
8
+ class BooleanDefinitions
9
+ def self.bind_to(coercer)
10
+ coercer.register(TrueClass, String) { |o, _| 'true' }
11
+ coercer.register(FalseClass, String) { |o, _| 'false' }
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module Yukata
2
+ module Coercions
3
+ class DateDefinitions
4
+ def self.bind_to(coercer)
5
+ coercer.register(Date, Time) { |obj, _| obj.to_time }
6
+ coercer.register(Date, DateTime) { |obj, _| obj.to_datetime }
7
+ coercer.register(Date, Integer) { |obj, _| obj.to_time.to_i }
8
+ coercer.register(Date, Float) { |obj, _| obj.to_time.to_f }
9
+ coercer.register(Date, String) { |obj, _| obj.to_s }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Yukata
2
+ module Coercions
3
+ class DateTimeDefinitions
4
+ def self.bind_to(coercer)
5
+ coercer.register(DateTime, Time) { |obj, _| obj.to_time }
6
+ coercer.register(DateTime, Date) { |obj, _| obj.to_date }
7
+ coercer.register(DateTime, Integer) { |obj, _| obj.to_time.to_i }
8
+ coercer.register(DateTime, Float) { |obj, _| obj.to_time.to_f }
9
+ coercer.register(DateTime, String) { |obj, _| obj.to_s }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ module Yukata
2
+ module Coercions
3
+ class FixnumDefinitions
4
+ def self.bind_to(coercer)
5
+ coercer.register(Fixnum, String) { |obj, _| obj.to_s }
6
+ coercer.register(Fixnum, Time) { |obj, _| Time.at(obj) }
7
+ coercer.register(Fixnum, Date) { |obj, _| Time.at(obj).to_date }
8
+ coercer.register(Fixnum, DateTime) { |obj, _| Time.at(obj).to_datetime }
9
+ coercer.register(Fixnum, String) { |obj, _| obj.to_s }
10
+ coercer.register(Fixnum, Integer) { |obj, _| obj.to_i }
11
+ coercer.register(Fixnum, Float) { |obj, _| obj.to_f }
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module Yukata
2
+ module Coercions
3
+ class FloatDefinitions
4
+ def self.bind_to(coercer)
5
+ coercer.register(Float, Time) { |obj, _| Time.at(obj) }
6
+ coercer.register(Float, Date) { |obj, _| Time.at(obj).to_date }
7
+ coercer.register(Float, DateTime) { |obj, _| Time.at(obj).to_datetime }
8
+ coercer.register(Float, String) { |obj, _| obj.to_s }
9
+ coercer.register(Float, Integer) { |obj, _| obj.to_i }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ module Yukata
2
+ module Coercions
3
+ class HashDefinitions
4
+ def self.bind_to(coercer)
5
+ coercer.register(Hash, String) { |obj, _| obj.to_s }
6
+ coercer.register(Hash, Array) { |obj, _| obj.to_a }
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ module Yukata
2
+ module Coercions
3
+ class IntegerDefinitions
4
+ def self.bind_to(coercer)
5
+ coercer.register(Integer, Time) { |obj, _| Time.at(obj) }
6
+ coercer.register(Integer, Date) { |obj, _| Time.at(obj).to_date }
7
+ coercer.register(Integer, DateTime) { |obj, _| Time.at(obj).to_datetime }
8
+ coercer.register(Integer, String) { |obj, _| obj.to_s }
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,26 @@
1
+ module Yukata
2
+ module Coercions
3
+ class StringDefinitions
4
+ def self.bind_to(coercer)
5
+ # Attempt to parse the date. If it can't be parsed just return nil.
6
+ # Silently failing is about the only thing I can think of.
7
+ type_parser = -> (obj, target) do
8
+ begin
9
+ target.parse(obj)
10
+ rescue ArgumentError
11
+ nil
12
+ end
13
+ end
14
+
15
+ coercer.register(String, Time, &type_parser)
16
+ coercer.register(String, Date, &type_parser)
17
+ coercer.register(String, DateTime, &type_parser)
18
+ coercer.register(String, Integer) { |obj, _| obj.to_i }
19
+ coercer.register(String, Float) { |obj, _| obj.to_f }
20
+ coercer.register(String, Boolean) do |string, _|
21
+ %w(1 on t true y yes).include?(string.downcase)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ module Yukata
2
+ module Coercions
3
+ class TimeDefinitions
4
+ def self.bind_to(coercer)
5
+ coercer.register(Time, Date) { |obj, _| obj.to_date }
6
+ coercer.register(Time, DateTime) { |obj, _| obj.to_datetime }
7
+ coercer.register(Time, Integer) { |obj, _| obj.to_i }
8
+ coercer.register(Time, Float) { |obj, _| obj.to_f }
9
+ coercer.register(Time, String) { |obj, _| obj.to_s }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module Yukata
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yukata::Attribute do
4
+ describe '#initialize' do
5
+ context 'when the default is a proc' do
6
+ subject { Yukata::Attribute.new(String, { default: -> { 'nothing' } }) }
7
+ it 'sets the default' do
8
+ expect(subject.default).to eq('nothing')
9
+ end
10
+ end
11
+
12
+ context 'when the default is a String' do
13
+ subject { Yukata::Attribute.new(String, { default: 'nothing' }) }
14
+ it 'sets the default' do
15
+ expect(subject.default).to eq('nothing')
16
+ end
17
+ end
18
+
19
+ context 'when no default is provided' do
20
+ subject { Yukata::Attribute.new(String) }
21
+ it 'sets the default to nil' do
22
+ expect(subject.default).to eq(nil)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yukata::Base do
4
+ class MockedBase < Yukata::Base
5
+ attribute :id, Integer
6
+ attribute :foo, String
7
+ attribute :created_at, DateTime, default: -> { DateTime.now }
8
+ end
9
+
10
+ describe '#initialize' do
11
+ context 'when a hash is not passed' do
12
+ subject { MockedBase.new }
13
+
14
+ its(:id) { should be_nil }
15
+ its(:foo) { should be_nil }
16
+ its(:created_at) { should_not be_nil }
17
+ end
18
+
19
+ context 'when a hash is passed' do
20
+ let(:now) { DateTime.now }
21
+ let(:params) { { id: '1', foo: 'bar', created_at: now } }
22
+
23
+ subject { MockedBase.new(params) }
24
+
25
+ its(:id) { should eq(1) }
26
+ its(:foo) { should eq('bar') }
27
+ its(:created_at) { should eq(now) }
28
+ end
29
+ end
30
+ end
File without changes
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yukata::Coercion do
4
+ describe '#initialize' do
5
+ context 'when no block is provided' do
6
+ subject { Yukata::Coercion.new(Object, String) }
7
+ it 'becomes a pass through coercion' do
8
+ test = double('SomeObject')
9
+ expect(subject.call(test)).to eq(test)
10
+ end
11
+ end
12
+ context 'when a block is provided' do
13
+ subject { Yukata::Coercion.new(Object, String) { |o,_| o.to_s } }
14
+
15
+ it 'sets the block to the one that is provided' do
16
+ test = double('SomeObject', to_s: 'something')
17
+ expect(subject.call(test)).to eq('something')
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yukata::Coercions::BooleanDefinitions do
4
+ let(:coercer) { Yukata::Coercer.new }
5
+
6
+ before do
7
+ described_class.bind_to(coercer)
8
+ end
9
+
10
+ describe 'Boolean to String' do
11
+ context 'when the value is false' do
12
+ subject { coercer.coerce(false, String) }
13
+
14
+ it 'returns "false"' do
15
+ expect(subject).to eq('false')
16
+ end
17
+ end
18
+
19
+ context 'when the value is true' do
20
+ subject { coercer.coerce(true, String) }
21
+
22
+ it 'return "true"' do
23
+ expect(subject).to eq('true')
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yukata::Coercions::DateDefinitions do
4
+ let(:coercer) { Yukata::Coercer.new }
5
+ let(:date) { Date.today }
6
+
7
+ before do
8
+ described_class.bind_to(coercer)
9
+ end
10
+
11
+ describe 'Date to Time' do
12
+ subject { coercer.coerce(date, Time) }
13
+ it 'coerces to a Time' do
14
+ expect(subject).to eq(date.to_time)
15
+ end
16
+ end
17
+
18
+ describe 'Date to DateTime' do
19
+ subject { coercer.coerce(date, DateTime) }
20
+ it 'coerces to a DateTime' do
21
+ expect(subject).to eq(date.to_datetime)
22
+ end
23
+ end
24
+
25
+ describe 'Date to Integer' do
26
+ subject { coercer.coerce(date, Integer) }
27
+ it 'coerces to an Integer' do
28
+ expect(subject).to eq(date.to_time.to_i)
29
+ end
30
+ end
31
+
32
+ describe 'Date to Float' do
33
+ subject { coercer.coerce(date, Float) }
34
+ it 'coerces to a Float' do
35
+ expect(subject).to eq(date.to_time.to_f)
36
+ end
37
+ end
38
+
39
+ describe 'Date to String' do
40
+ subject { coercer.coerce(date, String) }
41
+ it 'coerces to a String' do
42
+ expect(subject).to eq(date.to_s)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yukata::Coercions::DateTimeDefinitions do
4
+ let(:coercer) { Yukata::Coercer.new }
5
+ let(:date) { DateTime.new }
6
+
7
+ before do
8
+ described_class.bind_to(coercer)
9
+ end
10
+
11
+ describe 'DateTime to Time' do
12
+ subject { coercer.coerce(date, Time) }
13
+ it 'coerces to a Time' do
14
+ expect(subject).to eq(date.to_time)
15
+ end
16
+ end
17
+
18
+ describe 'DateTime to Date' do
19
+ subject { coercer.coerce(date, Date) }
20
+ it 'coerces to a Date' do
21
+ expect(subject).to eq(date.to_date)
22
+ end
23
+ end
24
+
25
+ describe 'DateTime to Integer' do
26
+ subject { coercer.coerce(date, Integer) }
27
+ it 'coerces to an Integer' do
28
+ expect(subject).to eq(date.to_time.to_i)
29
+ end
30
+ end
31
+
32
+ describe 'DateTime to Float' do
33
+ subject { coercer.coerce(date, Float) }
34
+ it 'coerces to a Float' do
35
+ expect(subject).to eq(date.to_time.to_f)
36
+ end
37
+ end
38
+
39
+ describe 'DateTime to String' do
40
+ subject { coercer.coerce(date, String) }
41
+ it 'coerces to a String' do
42
+ expect(subject).to eq(date.to_s)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yukata::Coercions::FixnumDefinitions do
4
+ let(:coercer) { Yukata::Coercer.new }
5
+ let(:fixnum) { 1 }
6
+
7
+ before do
8
+ described_class.bind_to(coercer)
9
+ end
10
+
11
+ describe 'Fixnum to String' do
12
+ subject { coercer.coerce(fixnum, String) }
13
+ it 'coerces to a String' do
14
+ expect(subject).to eq(fixnum.to_s)
15
+ end
16
+ end
17
+
18
+ describe 'Fixnum to Time' do
19
+ subject { coercer.coerce(fixnum, Time) }
20
+ it 'coerces to a Time' do
21
+ expect(subject).to eq(Time.at(fixnum))
22
+ end
23
+ end
24
+
25
+ describe 'Fixnum to Date' do
26
+ subject { coercer.coerce(fixnum, Date) }
27
+ it 'coerces to a Date' do
28
+ expect(subject).to eq(Time.at(fixnum).to_date)
29
+ end
30
+ end
31
+
32
+ describe 'Fixnum to DateTime' do
33
+ subject { coercer.coerce(fixnum, DateTime) }
34
+ it 'coerces to a DateTime' do
35
+ expect(subject).to eq(Time.at(fixnum).to_datetime)
36
+ end
37
+ end
38
+
39
+ describe 'Fixnum to Integer' do
40
+ subject { coercer.coerce(fixnum, Integer) }
41
+ it 'coerces to a Integer' do
42
+ expect(subject).to eq(fixnum.to_i)
43
+ end
44
+ end
45
+
46
+ describe 'Fixnum to Float' do
47
+ subject { coercer.coerce(fixnum, Float) }
48
+ it 'coerces to a Float' do
49
+ expect(subject).to eq(fixnum.to_f)
50
+ end
51
+ end
52
+ end
@@ -1 +1,10 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
1
4
  require 'yukata'
5
+
6
+ RSpec.configure do |config|
7
+ config.expect_with :rspec do |c|
8
+ c.syntax = :expect
9
+ end
10
+ end
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency('bundler', '~> 1.3')
22
22
  spec.add_development_dependency('rspec')
23
23
  spec.add_development_dependency('rake')
24
+ spec.add_development_dependency('simplecov')
24
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yukata
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Johnston
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: Attributes for ruby objects
56
70
  email:
57
71
  - warmwaffles@gmail.com
@@ -72,18 +86,26 @@ files:
72
86
  - lib/yukata/base.rb
73
87
  - lib/yukata/coercer.rb
74
88
  - lib/yukata/coercion.rb
75
- - lib/yukata/coercions/array.rb
76
- - lib/yukata/coercions/boolean.rb
77
- - lib/yukata/coercions/date.rb
78
- - lib/yukata/coercions/date_time.rb
79
- - lib/yukata/coercions/fixnum.rb
80
- - lib/yukata/coercions/float.rb
81
- - lib/yukata/coercions/hash.rb
82
- - lib/yukata/coercions/integer.rb
83
- - lib/yukata/coercions/string.rb
84
- - lib/yukata/coercions/time.rb
89
+ - lib/yukata/coercions.rb
90
+ - lib/yukata/coercions/boolean_definitions.rb
91
+ - lib/yukata/coercions/date_definitions.rb
92
+ - lib/yukata/coercions/date_time_definitions.rb
93
+ - lib/yukata/coercions/fixnum_definitions.rb
94
+ - lib/yukata/coercions/float_definitions.rb
95
+ - lib/yukata/coercions/hash_definitions.rb
96
+ - lib/yukata/coercions/integer_definitions.rb
97
+ - lib/yukata/coercions/string_definitions.rb
98
+ - lib/yukata/coercions/time_definitions.rb
85
99
  - lib/yukata/errors.rb
86
100
  - lib/yukata/version.rb
101
+ - spec/attribute_spec.rb
102
+ - spec/base_spec.rb
103
+ - spec/coercer_spec.rb
104
+ - spec/coercion_spec.rb
105
+ - spec/coercions/boolean_definitions_spec.rb
106
+ - spec/coercions/date_definitions_spec.rb
107
+ - spec/coercions/date_time_definitions_spec.rb
108
+ - spec/coercions/fixnum_definitions_spec.rb
87
109
  - spec/spec_helper.rb
88
110
  - spec/yukata_spec.rb
89
111
  - yukata.gemspec
@@ -112,5 +134,13 @@ signing_key:
112
134
  specification_version: 4
113
135
  summary: Attributes for ruby objects
114
136
  test_files:
137
+ - spec/attribute_spec.rb
138
+ - spec/base_spec.rb
139
+ - spec/coercer_spec.rb
140
+ - spec/coercion_spec.rb
141
+ - spec/coercions/boolean_definitions_spec.rb
142
+ - spec/coercions/date_definitions_spec.rb
143
+ - spec/coercions/date_time_definitions_spec.rb
144
+ - spec/coercions/fixnum_definitions_spec.rb
115
145
  - spec/spec_helper.rb
116
146
  - spec/yukata_spec.rb
@@ -1 +0,0 @@
1
- Yukata.coercer.coerce(Array, String) { |obj, _| obj.to_s }
@@ -1,8 +0,0 @@
1
- unless defined?(Boolean)
2
- class Boolean
3
- end
4
- end
5
-
6
- Yukata.coercer.register(String, Boolean) do |string, _|
7
- %w(1 on t true y yes).include?(string.downcase)
8
- end
@@ -1,5 +0,0 @@
1
- Yukata.coercer.register(Date, Time) { |obj, _| obj.to_time }
2
- Yukata.coercer.register(Date, DateTime) { |obj, _| obj.to_datetime }
3
- Yukata.coercer.register(Date, Integer) { |obj, _| obj.to_time.to_i }
4
- Yukata.coercer.register(Date, Float) { |obj, _| obj.to_time.to_f }
5
- Yukata.coercer.register(Date, String) { |obj, _| obj.to_s }
@@ -1,5 +0,0 @@
1
- Yukata.coercer.register(DateTime, Time) { |obj, _| obj.to_time }
2
- Yukata.coercer.register(DateTime, Date) { |obj, _| obj.to_date }
3
- Yukata.coercer.register(DateTime, Integer) { |obj, _| obj.to_time.to_i }
4
- Yukata.coercer.register(DateTime, Float) { |obj, _| obj.to_time.to_f }
5
- Yukata.coercer.register(DateTime, String) { |obj, _| obj.to_s }
@@ -1,7 +0,0 @@
1
- Yukata.coercer.register(Fixnum, String) { |obj, _| obj.to_s }
2
- Yukata.coercer.register(Fixnum, Time) { |obj, _| Time.at(obj) }
3
- Yukata.coercer.register(Fixnum, Date) { |obj, _| Time.at(obj).to_date }
4
- Yukata.coercer.register(Fixnum, DateTime) { |obj, _| Time.at(obj).to_datetime }
5
- Yukata.coercer.register(Fixnum, String) { |obj, _| obj.to_s }
6
- Yukata.coercer.register(Fixnum, Integer) { |obj, _| obj.to_i }
7
- Yukata.coercer.register(Fixnum, Float) { |obj, _| obj.to_f }
@@ -1,5 +0,0 @@
1
- Yukata.coercer.register(Float, Time) { |obj, _| Time.at(obj) }
2
- Yukata.coercer.register(Float, Date) { |obj, _| Time.at(obj).to_date }
3
- Yukata.coercer.register(Float, DateTime) { |obj, _| Time.at(obj).to_datetime }
4
- Yukata.coercer.register(Float, String) { |obj, _| obj.to_s }
5
- Yukata.coercer.register(Float, Integer) { |obj, _| obj.to_i }
@@ -1,2 +0,0 @@
1
- Yukata.coercer.register(Hash, String) { |obj, _| obj.to_s }
2
- Yukata.coercer.register(Hash, Array) { |obj, _| obj.to_a }
@@ -1,4 +0,0 @@
1
- Yukata.coercer.register(Integer, Time) { |obj, _| Time.at(obj) }
2
- Yukata.coercer.register(Integer, Date) { |obj, _| Time.at(obj).to_date }
3
- Yukata.coercer.register(Integer, DateTime) { |obj, _| Time.at(obj).to_datetime }
4
- Yukata.coercer.register(Integer, String) { |obj, _| obj.to_s }
@@ -1,26 +0,0 @@
1
- Yukata.coercer.register(String, Time) do |obj, type|
2
- begin
3
- type.parse(obj)
4
- rescue ArgumentError
5
- nil
6
- end
7
- end
8
-
9
- Yukata.coercer.register(String, Date) do |obj, type|
10
- begin
11
- type.parse(obj)
12
- rescue ArgumentError
13
- nil
14
- end
15
- end
16
-
17
- Yukata.coercer.register(String, DateTime) do |obj, type|
18
- begin
19
- type.parse(obj)
20
- rescue ArgumentError
21
- nil
22
- end
23
- end
24
-
25
- Yukata.coercer.register(String, Integer) { |obj, _| obj.to_i }
26
- Yukata.coercer.register(String, Float) { |obj, _| obj.to_f }
@@ -1,5 +0,0 @@
1
- Yukata.coercer.register(Time, Date) { |obj, _| obj.to_date }
2
- Yukata.coercer.register(Time, DateTime) { |obj, _| obj.to_datetime }
3
- Yukata.coercer.register(Time, Integer) { |obj, _| obj.to_i }
4
- Yukata.coercer.register(Time, Float) { |obj, _| obj.to_f }
5
- Yukata.coercer.register(Time, String) { |obj, _| obj.to_s }