attributor-flatpack 1.0.0 → 1.1.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: dc8bedaf5f09ed13a4b6bac5ac5b7bdb0f8c634c
4
- data.tar.gz: dd820df64508af2d10f7a114175691409e8759c6
3
+ metadata.gz: f5e442b5e561133fe9d83121a0de9452cad5e72a
4
+ data.tar.gz: fc258569802189aa6c891ed13a5077e4d11a5e34
5
5
  SHA512:
6
- metadata.gz: d7c3e4cba1a21f388e8dc4ddb15a3e806b5737f0ef70bb0afccbd414ab71589b5bd67722a72f850e104a3d74b92c9b3619089818cc77b448c784d3b1fe547cf2
7
- data.tar.gz: ab0426155b984d93f8fb7017210543defc88d765cba7b3a34b0e36f61278ecb6a23245e24b96b98f6d314383b8db1f304c39c7406b7f9ec016b6fad12d5f07e0
6
+ metadata.gz: 264a8c5d4846613446b0b72c6de974a2ff80dd986c033608fea95ace756155e885ce62c4203d25208f0c0c56445b721e6d612beef2609ad09efb654a35d88b06
7
+ data.tar.gz: e6907e886c0d43c79e9b6fd9230d66be5f9e9d5aead09c0e8a3f83cc1d07cb65a3979c10db107d010a683ec13e5463e8b58a33f1dde203c8e9778baaab95a4c4
data/.rubocop.yml CHANGED
@@ -12,6 +12,8 @@ Metrics/MethodLength:
12
12
  Enabled: false
13
13
  Metrics/ClassLength:
14
14
  Enabled: false
15
+ Metrics/LineLength:
16
+ Max: 85
15
17
  Style/RedundantSelf:
16
18
  Enabled: false
17
19
  Style/DoubleNegation:
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # attributor-flatpack changelog
2
+
3
+ ## 1.1
4
+
5
+ * Significant performance improvements. See [benchmark results](benchmark/output.txt) for comparisons.
6
+
7
+ ## 1.0
8
+
9
+ * Initial Release
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Attributor::Flatpack
2
+ [![Gem Version](https://badge.fury.io/rb/attributor-flatpack.svg)](https://badge.fury.io/rb/attributor-flatpack)
2
3
  [![Build Status](https://travis-ci.org/careo/attributor-flatpack.svg?branch=master)](https://travis-ci.org/careo/attributor-flatpack)
3
4
  [![Code Climate](https://codeclimate.com/github/careo/attributor-flatpack/badges/gpa.svg)](https://codeclimate.com/github/careo/attributor-flatpack)
4
5
  [![Test Coverage](https://codeclimate.com/github/careo/attributor-flatpack/badges/coverage.svg)](https://codeclimate.com/github/careo/attributor-flatpack/coverage)
data/benchmark/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gem 'benchmark-ips'
3
+ gem 'attributor-flatpack', path: '../'
@@ -0,0 +1,90 @@
1
+ require 'bundler/setup'
2
+ Bundler.require
3
+
4
+ class ConfigHash < Attributor::Hash
5
+ keys allow_extra: true do
6
+ key 'HOME', String
7
+ key 'PATH', String
8
+ end
9
+ end
10
+
11
+ class ConfigFlatpack < Attributor::Flatpack::Config
12
+ keys do
13
+ key :home, String
14
+ key :path, String
15
+ end
16
+ end
17
+
18
+ class ConfigModel < Attributor::Model
19
+ attributes do
20
+ attribute :home, String
21
+ attribute :path, String
22
+ end
23
+ end
24
+
25
+ ConfigStruct = Struct.new(:home, :path)
26
+
27
+ class Poro
28
+ attr_accessor :home, :path
29
+ def initialize(home, path)
30
+ @home = home
31
+ @path = path
32
+ end
33
+ end
34
+
35
+ HOME = ENV['HOME']
36
+ PATH = ENV['PATH']
37
+
38
+ config_hash = ConfigHash.load(ENV)
39
+ config_flatpack = ConfigFlatpack.load(ENV)
40
+ config_model = ConfigModel.load(home: HOME, path: PATH)
41
+ config_struct = ConfigStruct.new(HOME, PATH)
42
+ poro = Poro.new(HOME, PATH)
43
+
44
+ puts RUBY_DESCRIPTION
45
+
46
+ Benchmark.ips do |x|
47
+ x.report 'constants' do |i|
48
+ i.times do
49
+ HOME == PATH
50
+ end
51
+ end
52
+
53
+ x.report 'ENV' do |i|
54
+ i.times do
55
+ ENV['HOME'] == ENV['PATH']
56
+ end
57
+ end
58
+
59
+ x.report 'Attributor::Hash' do |i|
60
+ i.times do
61
+ config_hash['HOME'] == config_hash['PATH']
62
+ end
63
+ end
64
+
65
+ x.report 'Attributor::Flatpack' do |i|
66
+ i.times do
67
+ config_flatpack.home == config_flatpack.path
68
+ end
69
+ end
70
+
71
+ x.report 'Attributor::Model' do |i|
72
+ i.times do
73
+ config_model.home == config_model.path
74
+ end
75
+ end
76
+
77
+ x.report 'Ruby Struct' do |i|
78
+ i.times do
79
+ config_struct.home == config_struct.path
80
+ end
81
+ end
82
+
83
+ x.report 'PORO' do |i|
84
+ i.times do
85
+ poro.home == poro.path
86
+ end
87
+ end
88
+
89
+ x.compare!
90
+ end
@@ -0,0 +1,27 @@
1
+ ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]
2
+ Warming up --------------------------------------
3
+ constants 93.664k i/100ms
4
+ ENV 24.570k i/100ms
5
+ Attributor::Hash 52.668k i/100ms
6
+ Attributor::Flatpack 52.263k i/100ms
7
+ Attributor::Model 79.844k i/100ms
8
+ Ruby Struct 85.377k i/100ms
9
+ PORO 82.365k i/100ms
10
+ Calculating -------------------------------------
11
+ constants 13.543M (±10.8%) i/s - 66.689M
12
+ ENV 681.551k (± 8.9%) i/s - 3.391M
13
+ Attributor::Hash 2.084M (± 6.5%) i/s - 10.376M
14
+ Attributor::Flatpack 1.633M (± 5.3%) i/s - 8.153M
15
+ Attributor::Model 4.681M (± 6.7%) i/s - 23.314M
16
+ Ruby Struct 6.468M (± 7.3%) i/s - 32.187M
17
+ PORO 8.423M (± 7.0%) i/s - 41.924M
18
+
19
+ Comparison:
20
+ constants: 13543356.2 i/s
21
+ PORO: 8422557.3 i/s - 1.61x slower
22
+ Ruby Struct: 6467625.6 i/s - 2.09x slower
23
+ Attributor::Model: 4680600.5 i/s - 2.89x slower
24
+ Attributor::Hash: 2084217.5 i/s - 6.50x slower
25
+ Attributor::Flatpack: 1632932.0 i/s - 8.29x slower
26
+ ENV: 681551.4 i/s - 19.87x slower
27
+
@@ -28,14 +28,16 @@ module Attributor
28
28
  end
29
29
 
30
30
  def define_reader(name)
31
+ attribute = self.class.keys[name]
32
+ context = default_context(name)
33
+
31
34
  define_singleton_method(name) do
32
- get(name)
35
+ get(name, attribute: attribute, context: context)
33
36
  end
34
37
 
35
- attribute = self.class.keys[name]
36
38
  if attribute.type == Attributor::Boolean
37
39
  define_singleton_method(name.to_s + '?') do
38
- !!get(name)
40
+ !!get(name, attribute: attribute, context: context)
39
41
  end
40
42
  end
41
43
  end
@@ -51,10 +53,8 @@ module Attributor
51
53
  generate_subcontext(Attributor::DEFAULT_ROOT_CONTEXT, key)
52
54
  end
53
55
 
54
- def get(key, context: default_context(key))
55
- unless (attribute = self.class.keys[key])
56
- raise UndefinedKey.new(key, context)
57
- end
56
+ def get(key, context: default_context(key), attribute: self.class.keys[key])
57
+ raise UndefinedKey.new(key, context) unless attribute
58
58
 
59
59
  @contents[key] ||= _get(key, attribute: attribute, context: context)
60
60
  end
@@ -1,5 +1,5 @@
1
1
  module Attributor
2
2
  module Flatpack
3
- VERSION = '1.0.0'.freeze
3
+ VERSION = '1.1.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attributor-flatpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dane Jensen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-09 00:00:00.000000000 Z
11
+ date: 2016-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: attributor
@@ -191,12 +191,16 @@ files:
191
191
  - ".rubocop.yml"
192
192
  - ".ruby-version"
193
193
  - ".travis.yml"
194
+ - CHANGELOG.md
194
195
  - Gemfile
195
196
  - Guardfile
196
197
  - LICENSE.txt
197
198
  - README.md
198
199
  - Rakefile
199
200
  - attributor-flatpack.gemspec
201
+ - benchmark/Gemfile
202
+ - benchmark/bench.rb
203
+ - benchmark/output.txt
200
204
  - bin/console
201
205
  - bin/setup
202
206
  - examples/sample_config.rb