uber 0.0.4 → 0.0.5

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: 516c9e7445cdc09ca9cc33afce8ffbb32494d1c0
4
- data.tar.gz: d9e02ab06a8282723242cd9486331a44f1c42ce1
3
+ metadata.gz: edb6b44ba23dd1481ffbf6f258d045199811e0c4
4
+ data.tar.gz: 2f2146e0d6badc1744de2c4eaf1c087285b90146
5
5
  SHA512:
6
- metadata.gz: c517333088ac322d06847427c10694c6fbea60e20e74e433fb0f41f035478ea326c85169e6bf80572c81e6170684cb0b659ce5311a2ffc6476f09600913896d9
7
- data.tar.gz: 4cb7b1e5069343dc6209794f01f23af9305bec11a4d8dad6be89f3ab18e62793edf78272b56ab655a1ac1dbfb5fea7905aaf5ecc5ef8bbf0133ab1ed0d1037e3
6
+ metadata.gz: 5de60ad7830b232f1e5e0bcae0f12481320ca0737296e63cb84e3cd4d40b9ea9f142ee2390af1601d6d02fdf284df13cf76a263384ad82836fd90ad06e093529
7
+ data.tar.gz: 76dd7644a760d64eec0291f49cc1009cfd077e6d3e2bb2bf681924060fd44b3a89c82d106d9a27c1ad6b8b8ea89be2454494190aa801b9c30ed8ba5edd83bf26
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.0.5
2
+
3
+ Add `Uber::Version` for simple gem version deciders.
4
+
1
5
  # 0.0.4
2
6
 
3
7
  * Fix a bug where `dynamic: true` wouldn't invoke a method but try to run it as a block.
data/README.md CHANGED
@@ -65,15 +65,19 @@ Usually DSL methods accept a number of options that can either be static values,
65
65
  Here's an example from Cells.
66
66
 
67
67
  ```ruby
68
- cache :show, tags: lambda { Tag.last }, expire_in: 5.mins, ttl: :time_to_live
68
+ cache :show, tags: lambda { Tag.last }, expires_in: 5.mins, ttl: :time_to_live
69
69
  ```
70
70
 
71
- Usually, when processing these options, you'd have to check every option for its type, evaluate the `tag:` lambda in a particular context, call the `#time_to_live` instance method, etc.
71
+ Usually, when processing these options, you'd have to check every option for its type, evaluate the `tags:` lambda in a particular context, call the `#time_to_live` instance method, etc.
72
72
 
73
73
  This is abstracted in `Uber::Options` and could be implemented like this.
74
74
 
75
75
  ```ruby
76
- options = Uber::Options.new(tags: lambda { Tag.last }, expire_in: 5.mins, ttl: :time_to_live)
76
+ require 'uber/options'
77
+
78
+ options = Uber::Options.new(tags: lambda { Tag.last },
79
+ expires_in: 5.mins,
80
+ ttl: :time_to_live)
77
81
  ```
78
82
 
79
83
  Just initialize `Options` with your actual options hash. While this usually happens on class level at compile-time, evaluating the hash happens at run-time.
@@ -82,25 +86,27 @@ Just initialize `Options` with your actual options hash. While this usually happ
82
86
  class User < ActiveRecord::Base # this could be any Ruby class.
83
87
  # .. lots of code
84
88
 
85
- def time_to_live
89
+ def time_to_live(*args)
86
90
  "n/a"
87
91
  end
88
92
  end
89
93
 
90
94
  user = User.find(1)
91
95
 
92
- options.evaluate(user, *args) #=> {tags: "hot", expire_in: 300, ttl: "n/a"}
96
+ options.evaluate(user, *args) #=> {tags: "hot", expires_in: 300, ttl: "n/a"}
93
97
  ```
94
98
 
95
99
  ## Evaluating Dynamic Options
96
100
 
97
101
  To evaluate the options to a real hash, the following happens:
98
102
 
99
- * The `tags:` lambda is executed in `user` context (using `instance_exec`). This allows accessing instance variables or calling instance methods. All `*args` are passed as block parameters to the lambda.
103
+ * The `tags:` lambda is executed in `user` context (using `instance_exec`). This allows accessing instance variables or calling instance methods.
100
104
  * Nothing is done with `expires_in`'s value, it is static.
101
105
  * `user.time_to_live?` is called as the symbol `:time_to_live` indicates that this is an instance method.
102
106
 
103
- The default behaviour is to treat `Proc`s, lambdas and symbolized `:method` names as dynamic options, everything else is considered static. This is a pattern well-known from Rails and other frameworks.
107
+ The default behaviour is to treat `Proc`s, lambdas and symbolized `:method` names as dynamic options, everything else is considered static. Optional arguments from the `evaluate` call are passed in either as block or method arguments for dynamic options.
108
+
109
+ This is a pattern well-known from Rails and other frameworks.
104
110
 
105
111
  ## Evaluating Elements
106
112
 
@@ -127,12 +133,36 @@ Use `Options::Value#evaluate` to handle single values.
127
133
  Evaluating an options hash can be time-consuming. When `Options` contains static elements only, it behaves *and performs* like an ordinary hash.
128
134
 
129
135
 
130
- Uber::Options.new volume: 9, track: lambda { |s| s.track }
136
+ # Version
137
+
138
+ When writing gems against other gems involves checking for versions and loading appropriate version strategies (e.g. "is Rails >= 4.0?". Uber gives you `Version` for easy, semantic version deciders.
139
+
140
+ ```ruby
141
+ version = Uber::Version.new("1.2.3")
142
+ ```
143
+
144
+ The API currently gives you `>=` and `~`.
145
+
146
+ ```ruby
147
+ version >= "1.1" #=> true
148
+ version >= "1.3" #=> false
149
+ ```
150
+
151
+ The `~` method does a semantic check (currently on major and minor level, only).
152
+
153
+ ```ruby
154
+ version.~ "1.1" #=> false
155
+ version.~ "1.2" #=> true
156
+ version.~ "1.3" #=> false
157
+ ```
131
158
 
159
+ Accepting a list of versions, it makes it simple to check for multiple minor versions.
132
160
 
133
- dynamic: true
161
+ ```ruby
162
+ version.~ "1.1", "1.0" #=> false
163
+ version.~ "1.1", "1.2" #=> true
164
+ ```
134
165
 
135
- only use for declarative assets, not at runtime (use a hash)
136
166
 
137
167
  # Undocumented Features
138
168
 
@@ -0,0 +1,3 @@
1
+ module Uber
2
+ VERSION = "0.0.5"
3
+ end
@@ -1,3 +1,32 @@
1
1
  module Uber
2
- VERSION = "0.0.4"
3
- end
2
+ class Version < Hash
3
+ def initialize(version)
4
+ @version = Gem::Version.new(version)
5
+ major, minor, patch = @version.segments
6
+
7
+ self[:major] = major || 0
8
+ self[:minor] = minor || 0
9
+ self[:patch] = patch || 0
10
+ end
11
+
12
+ def >=(version)
13
+ major, minor, patch = parse(version)
14
+
15
+ self[:major] >= major and self[:minor] >= minor and self[:patch] >= patch
16
+ end
17
+
18
+ def ~(*versions)
19
+ !! versions.find do |v|
20
+ major, minor, patch = parse(v)
21
+
22
+ self[:major] == major and self[:minor] == minor
23
+ end
24
+ end
25
+
26
+ private
27
+ def parse(version)
28
+ major, minor, patch = Gem::Version.new(version).segments
29
+ [major||0, minor||0, patch||0]
30
+ end
31
+ end
32
+ end
@@ -21,9 +21,6 @@ class InheritanceTest < MiniTest::Spec
21
21
 
22
22
  CODE_BLOCK = lambda { |base| base.class_eval { extend ClassMethods } } # i want that to be executed at every include
23
23
 
24
- instance_exec do
25
- @block = CODE_BLOCK # this would happen in inherited_included do .. end
26
- end
27
24
 
28
25
  def self.included(includer) #
29
26
  # CODE_BLOCK.call(base)
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+
4
+ class VersionTest < MiniTest::Spec
5
+ subject { Uber::Version.new("1.2.3") } # Rails version
6
+
7
+ it { subject.~("1.0").must_equal false }
8
+ it { subject.~("1.1").must_equal false }
9
+ it { subject.~("1.2").must_equal true }
10
+ it { subject.~("1.3").must_equal false }
11
+ it { subject.~("2.2").must_equal false }
12
+ it { subject.~("1.0", "1.1").must_equal false }
13
+ it { subject.~("1.0", "1.1", "1.2").must_equal true }
14
+ it { subject.~("1.2", "1.3").must_equal true }
15
+
16
+ it { (subject >= "1.2").must_equal true }
17
+ it { (subject >= "1.1").must_equal true }
18
+ it { (subject >= "1.3").must_equal false }
19
+ it { (subject >= "2.1").must_equal false }
20
+ end
@@ -1,12 +1,13 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/uber/version', __FILE__)
2
+ require File.expand_path('../lib/uber/uber_version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Nick Sutterer"]
6
6
  gem.email = ["apotonick@gmail.com"]
7
7
  gem.description = %q{A gem-authoring framework.}
8
8
  gem.summary = %q{Gem-authoring tools like class method inheritance in modules, dynamic options and more.}
9
- gem.homepage = ""
9
+ gem.homepage = "https://github.com/apotonick/uber"
10
+ gem.license = "MIT"
10
11
 
11
12
  gem.files = `git ls-files`.split($\)
12
13
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-08 00:00:00.000000000 Z
11
+ date: 2014-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.10.1
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.10.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 5.0.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 5.0.0
41
41
  description: A gem-authoring framework.
@@ -45,7 +45,7 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
- - .gitignore
48
+ - ".gitignore"
49
49
  - CHANGES.md
50
50
  - Gemfile
51
51
  - LICENSE
@@ -54,15 +54,18 @@ files:
54
54
  - lib/uber.rb
55
55
  - lib/uber/inheritable_attr.rb
56
56
  - lib/uber/options.rb
57
+ - lib/uber/uber_version.rb
57
58
  - lib/uber/version.rb
58
59
  - test/inheritable_attr_test.rb
59
60
  - test/inheritance_test.rb
60
61
  - test/options_test.rb
61
62
  - test/test_helper.rb
63
+ - test/version_test.rb
62
64
  - test/zeugs.rb
63
65
  - uber.gemspec
64
- homepage: ''
65
- licenses: []
66
+ homepage: https://github.com/apotonick/uber
67
+ licenses:
68
+ - MIT
66
69
  metadata: {}
67
70
  post_install_message:
68
71
  rdoc_options: []
@@ -70,17 +73,17 @@ require_paths:
70
73
  - lib
71
74
  required_ruby_version: !ruby/object:Gem::Requirement
72
75
  requirements:
73
- - - '>='
76
+ - - ">="
74
77
  - !ruby/object:Gem::Version
75
78
  version: '0'
76
79
  required_rubygems_version: !ruby/object:Gem::Requirement
77
80
  requirements:
78
- - - '>='
81
+ - - ">="
79
82
  - !ruby/object:Gem::Version
80
83
  version: '0'
81
84
  requirements: []
82
85
  rubyforge_project:
83
- rubygems_version: 2.0.3
86
+ rubygems_version: 2.2.1
84
87
  signing_key:
85
88
  specification_version: 4
86
89
  summary: Gem-authoring tools like class method inheritance in modules, dynamic options
@@ -90,4 +93,6 @@ test_files:
90
93
  - test/inheritance_test.rb
91
94
  - test/options_test.rb
92
95
  - test/test_helper.rb
96
+ - test/version_test.rb
93
97
  - test/zeugs.rb
98
+ has_rdoc: