representable 3.0.2 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ac8f58fd73f1e9aa9e35f3298490086dfb93d54
4
- data.tar.gz: 054dcc8fdcf9cc7ce6f223747af5914457d19e90
3
+ metadata.gz: c7190988a0107b8fdf04b353f9e4ce2839edbc63
4
+ data.tar.gz: 4822a18cbbccd0b1953d24223dba3adcbfc7bd43
5
5
  SHA512:
6
- metadata.gz: af903f251a75b3d57899b4a0b428a84ff5436885939a8b59b6fb42b9fa4f517efca96ccb9b01bee969d9602a542b2b58a81171be8f4175204090a0e6c8f292c2
7
- data.tar.gz: 58b9716576c0d790d1b4584ac480760c9539ca61cea4618574fec0e7cb9f415fe2b35d156839f1b2d1c531433fa652160faea4bb14b6d2299341e62c094ec426
6
+ metadata.gz: 6f58b1085876a04fc2ebeb076d94323b1ad45039cfb987693ebc9ddd957bdb367c02b5b64792e570981fe549eafae4c5390886613992187f5106b1d380c079ab
7
+ data.tar.gz: db17d2feb4dfe80e37c2a3934218ef6101478fa1c4ab167cd9876710de4a9a30c8798a8914f9f9ff95cdf6642c7fbe8b650ae8d46855f642e364c1badeb88bf4
@@ -2,9 +2,13 @@ language: ruby
2
2
  cache: bundler
3
3
  sudo: false
4
4
  rvm:
5
- - 1.9.3
6
- - 2.0.0
7
- - 2.1.1
8
- - 2.3.1
9
- before_install:
10
- - gem install bundler
5
+ - 1.9.3-p551
6
+ - 2.0.0-p648
7
+ - 2.1.9
8
+ - 2.2.6
9
+ - 2.3.3
10
+ - 2.4.0
11
+ matrix:
12
+ include:
13
+ - rvm: jruby-9.1.5.0
14
+ env: JRUBY_OPTS="--profile.api"
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 3.0.3
2
+
3
+ * Replace `Uber::Option` with the new [`Declarative::Option`](https://github.com/apotonick/declarative-option). This should result in a significant performance boost.
4
+
1
5
  # 3.0.2
2
6
 
3
7
  * Initialize `Config@wrap` to avoid Ruby's warning.
data/Gemfile CHANGED
@@ -3,10 +3,12 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :test do
6
- gem "nokogiri", require: false
6
+ gem 'nokogiri', '~> 1.6.8', require: false
7
7
  gem "multi_json", require: false
8
8
  gem "minitest-line"
9
9
  end
10
10
 
11
11
  # gem "declarative", path: "../declarative"
12
12
  # gem "declarative", github: "apotonick/declarative"
13
+
14
+ # gem "uber","0.0.15" #, path: "../uber"
@@ -1,5 +1,6 @@
1
1
  require "uber/delegates"
2
-
2
+ require "uber/callable"
3
+ require "declarative/option"
3
4
  require "declarative/schema"
4
5
 
5
6
  require "representable/config"
@@ -20,14 +20,14 @@ module Representable
20
20
 
21
21
  def wrap=(value)
22
22
  value = value.to_s if value.is_a?(Symbol)
23
- @wrap = Uber::Options::Value.new(value)
23
+ @wrap = ::Declarative::Option(value, instance_exec: true, callable: Uber::Callable)
24
24
  end
25
25
 
26
26
  # Computes the wrap string or returns false.
27
27
  def wrap_for(represented, *args, &block)
28
28
  return unless @wrap
29
29
 
30
- value = @wrap.evaluate(represented, *args)
30
+ value = @wrap.(represented, *args)
31
31
 
32
32
  return value if value != true
33
33
  infer_name_for(represented.class.name)
@@ -1,4 +1,3 @@
1
- require "uber/options"
2
1
  require "representable/populator"
3
2
 
4
3
  module Representable
@@ -102,7 +101,7 @@ module Representable
102
101
  @runtime_options = {}
103
102
 
104
103
  for name, value in options
105
- value = Uber::Options::Value.new(value) if dynamic_options.include?(name)
104
+ value = ::Declarative::Option(value, instance_exec: true, callable: Uber::Callable) if dynamic_options.include?(name)
106
105
  @runtime_options[name] = value
107
106
  end
108
107
  end
@@ -1,3 +1,3 @@
1
1
  module Representable
2
- VERSION = "3.0.2"
2
+ VERSION = "3.0.3"
3
3
  end
@@ -1,3 +1,4 @@
1
+ require 'psych'
1
2
  require 'representable/hash'
2
3
  require 'representable/yaml/binding'
3
4
 
@@ -21,12 +21,14 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.required_ruby_version = '>= 1.9.3'
23
23
 
24
- spec.add_dependency "uber", ">= 0.0.15", "< 0.2.0"
25
- spec.add_dependency "declarative", "~> 0.0.5"
24
+ spec.add_dependency "uber", "< 0.2.0"
25
+ spec.add_dependency "declarative", "< 0.1.0"
26
+ spec.add_dependency "declarative-option", "< 0.2.0"
26
27
 
27
28
  spec.add_development_dependency "rake"
28
29
  spec.add_development_dependency "test_xml", "0.1.6"
29
30
  spec.add_development_dependency "minitest"
30
31
  spec.add_development_dependency "virtus"
31
- spec.add_development_dependency "ruby-prof"
32
+ spec.add_development_dependency "multi_json"
33
+ spec.add_development_dependency "ruby-prof" if RUBY_ENGINE == "ruby" # mri
32
34
  end
@@ -62,4 +62,4 @@ class AsXmlTest < MiniTest::Spec
62
62
  skip
63
63
  representer.new(Album.new(Band.new("Offspring"))).to_xml.must_equal ""
64
64
  end
65
- end
65
+ end
@@ -1,5 +1,28 @@
1
1
  require "test_helper"
2
- require 'ruby-prof'
2
+
3
+ class Profiler
4
+ def self.profile(&block)
5
+ case RUBY_ENGINE
6
+ when "ruby"
7
+ require 'ruby-prof'
8
+
9
+ output = StringIO.new
10
+ profile_result = RubyProf.profile(&block)
11
+ printer = RubyProf::FlatPrinter.new(profile_result)
12
+ printer.print(output)
13
+ output.string
14
+ when "jruby"
15
+ require 'jruby/profiler'
16
+
17
+ output_stream = java.io.ByteArrayOutputStream.new
18
+ print_stream = java.io.PrintStream.new(output_stream)
19
+ profile_result = JRuby::Profiler.profile(&block)
20
+ printer = JRuby::Profiler::FlatProfilePrinter.new(profile_result)
21
+ printer.printProfile(print_stream)
22
+ output_stream.toString
23
+ end
24
+ end
25
+ end
3
26
 
4
27
  class CachedTest < MiniTest::Spec
5
28
  # TODO: also test with feature(Cached)
@@ -55,28 +78,23 @@ class CachedTest < MiniTest::Spec
55
78
  it do
56
79
  representer.to_hash
57
80
 
58
- RubyProf.start
59
- representer.to_hash
60
- res = RubyProf.stop
61
-
62
- printer = RubyProf::FlatPrinter.new(res)
63
-
64
- data = StringIO.new
65
- printer.print(data)
66
- data = data.string
67
-
68
- printer.print(STDOUT)
81
+ data = Profiler.profile { representer.to_hash }
69
82
 
70
83
  # 3 songs get decorated.
71
- data.must_match "3 Representable::Function::Decorate#call"
84
+ data.must_match /3\s*Representable::Function::Decorate#call/m
85
+ # These weird Regexp bellow are a quick workaround to accomodate
86
+ # the different profiler result formats.
87
+ # - "3 <Class::Representable::Decorator>#prepare" -> At MRI Ruby
88
+ # - "3 Representable::Decorator.prepare" -> At JRuby
89
+
72
90
  # 3 nested decorator is instantiated for 3 Songs, though.
73
- data.must_match "3 <Class::Representable::Decorator>#prepare"
91
+ data.must_match /3\s*(<Class::)?Representable::Decorator\>?[\#.]prepare/m
74
92
  # no Binding is instantiated at runtime.
75
93
  data.wont_match "Representable::Binding#initialize"
76
94
  # 2 mappers for Album, Song
77
95
  # data.must_match "2 Representable::Mapper::Methods#initialize"
78
96
  # title, songs, 3x title, composer
79
- data.must_match "8 Representable::Binding#render_pipeline"
97
+ data.must_match /8\s*Representable::Binding[#\.]render_pipeline/m
80
98
  data.wont_match "render_functions"
81
99
  data.wont_match "Representable::Binding::Factories#render_functions"
82
100
  end
@@ -116,25 +134,17 @@ class CachedTest < MiniTest::Spec
116
134
  representer = AlbumRepresenter.new(Model::Album.new)
117
135
  representer.from_hash(album_hash)
118
136
 
119
- RubyProf.start
120
- # puts "#{representer.class.representable_attrs.get(:songs).representer_module.representable_attrs.inspect}"
121
- representer.from_hash(album_hash)
122
- res = RubyProf.stop
123
-
124
- printer = RubyProf::FlatPrinter.new(res)
125
-
126
- data = StringIO.new
127
- printer.print(data)
128
- data = data.string
137
+ data = Profiler.profile { representer.from_hash(album_hash) }
129
138
 
130
139
  # only 2 nested decorators are instantiated, Song, and Artist.
131
- data.must_match "5 <Class::Representable::Decorator>#prepare"
140
+ # Didn't like the regexp?
141
+ # MRI and JRuby has different output formats. See note above.
142
+ data.must_match /5\s*(<Class::)?Representable::Decorator>?[#\.]prepare/
132
143
  # a total of 5 properties in the object graph.
133
144
  data.wont_match "Representable::Binding#initialize"
134
145
 
135
-
136
146
  data.wont_match "parse_functions" # no pipeline creation.
137
- data.must_match "10 Representable::Binding#parse_pipeline"
147
+ data.must_match /10\s*Representable::Binding[#\.]parse_pipeline/
138
148
  # three mappers for Album, Song, composer
139
149
  # data.must_match "3 Representable::Mapper::Methods#initialize"
140
150
  # # 6 deserializers as the songs collection uses 2.
@@ -87,7 +87,7 @@ class DefinitionTest < MiniTest::Spec
87
87
  describe "#delete!" do
88
88
  let (:definition) { Definition.new(:song, serialize: "remove me!") }
89
89
 
90
- before { definition[:serialize].evaluate(nil).must_equal "remove me!" }
90
+ before { definition[:serialize].(nil).must_equal "remove me!" }
91
91
 
92
92
  it { definition.delete!(:serialize)[:serialize].must_equal nil }
93
93
  end
@@ -158,10 +158,10 @@ class DefinitionTest < MiniTest::Spec
158
158
 
159
159
 
160
160
  describe "#clone" do
161
- subject { Representable::Definition.new(:title, :volume => 9, :clonable => Uber::Options::Value.new(1)) }
161
+ subject { Representable::Definition.new(:title, :volume => 9, :clonable => Declarative::Option(1)) }
162
162
 
163
163
  it { subject.clone.must_be_kind_of Representable::Definition }
164
- it { subject.clone[:clonable].evaluate(nil).must_equal 1 }
164
+ it { subject.clone[:clonable].(nil).must_equal 1 }
165
165
 
166
166
  it "clones @options" do
167
167
  @def.merge!(:volume => 9)
@@ -1,4 +1,5 @@
1
1
  require 'test_helper'
2
+ require 'json'
2
3
 
3
4
  module JsonTest
4
5
  class JSONPublicMethodsTest < Minitest::Spec
@@ -1,7 +1,5 @@
1
1
  require 'representable'
2
2
 
3
- require "psych"
4
-
5
3
  require 'minitest/autorun'
6
4
  require 'test_xml/mini_test'
7
5
 
metadata CHANGED
@@ -1,22 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: representable
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-03 00:00:00.000000000 Z
11
+ date: 2017-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uber
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 0.0.15
20
17
  - - "<"
21
18
  - !ruby/object:Gem::Version
22
19
  version: 0.2.0
@@ -24,9 +21,6 @@ dependencies:
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: 0.0.15
30
24
  - - "<"
31
25
  - !ruby/object:Gem::Version
32
26
  version: 0.2.0
@@ -34,16 +28,30 @@ dependencies:
34
28
  name: declarative
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
- - - "~>"
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "<"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: declarative-option
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "<"
38
46
  - !ruby/object:Gem::Version
39
- version: 0.0.5
47
+ version: 0.2.0
40
48
  type: :runtime
41
49
  prerelease: false
42
50
  version_requirements: !ruby/object:Gem::Requirement
43
51
  requirements:
44
- - - "~>"
52
+ - - "<"
45
53
  - !ruby/object:Gem::Version
46
- version: 0.0.5
54
+ version: 0.2.0
47
55
  - !ruby/object:Gem::Dependency
48
56
  name: rake
49
57
  requirement: !ruby/object:Gem::Requirement
@@ -100,6 +108,20 @@ dependencies:
100
108
  - - ">="
101
109
  - !ruby/object:Gem::Version
102
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: multi_json
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
103
125
  - !ruby/object:Gem::Dependency
104
126
  name: ruby-prof
105
127
  requirement: !ruby/object:Gem::Requirement