tempo-cli 0.2.1 → 0.2.2
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 +4 -4
- data/Gemfile.lock +12 -12
- data/bin/tempo +1 -1
- data/lib/tempo/models/base.rb +31 -5
- data/lib/tempo/models/project.rb +4 -0
- data/lib/tempo/version.rb +1 -1
- data/test/lib/tempo/models/base_test.rb +59 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e0e749497d74a2c5e925fd047c19040e672ec24
|
4
|
+
data.tar.gz: a4923005458055bcf4439e939a8f278d65459296
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2524f53d37306e60ced9e55015ac57c1e962540113170b190abb7937a7a2eb16dd0ef7d5825d9ac574895649df0b0f49d3fe146e64a75c9800c51dc42a30aaa3
|
7
|
+
data.tar.gz: 66e4108bba0f37681e7a1f4e701f5e3a7de62705770351f9e5954e998351a73f85328e4e20bdf06ba392905b45c60f4b638051a9fe5aa0c417629f1509016b78
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tempo-cli (0.1
|
5
|
-
chronic (~> 0.10
|
6
|
-
gli (~> 2.10
|
4
|
+
tempo-cli (0.2.1)
|
5
|
+
chronic (~> 0.10)
|
6
|
+
gli (~> 2.10)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
@@ -27,16 +27,16 @@ GEM
|
|
27
27
|
ffi (1.9.0)
|
28
28
|
gherkin (2.12.0)
|
29
29
|
multi_json (~> 1.3)
|
30
|
-
gli (2.
|
31
|
-
json (1.8.
|
30
|
+
gli (2.11.0)
|
31
|
+
json (1.8.1)
|
32
32
|
method_source (0.8.1)
|
33
33
|
multi_json (1.7.7)
|
34
34
|
pry (0.9.12.2)
|
35
35
|
coderay (~> 1.0.5)
|
36
36
|
method_source (~> 0.8)
|
37
37
|
slop (~> 3.4)
|
38
|
-
rake (10.
|
39
|
-
rdoc (4.
|
38
|
+
rake (10.3.2)
|
39
|
+
rdoc (4.1.1)
|
40
40
|
json (~> 1.4)
|
41
41
|
rspec-expectations (2.13.0)
|
42
42
|
diff-lcs (>= 1.1.3, < 2.0)
|
@@ -48,9 +48,9 @@ PLATFORMS
|
|
48
48
|
ruby
|
49
49
|
|
50
50
|
DEPENDENCIES
|
51
|
-
aruba
|
52
|
-
pry (~> 0.9
|
53
|
-
rake
|
54
|
-
rdoc
|
51
|
+
aruba (~> 0.5)
|
52
|
+
pry (~> 0.9)
|
53
|
+
rake (~> 10.3)
|
54
|
+
rdoc (~> 4.1)
|
55
55
|
tempo-cli!
|
56
|
-
turn (~> 0.9
|
56
|
+
turn (~> 0.9)
|
data/bin/tempo
CHANGED
data/lib/tempo/models/base.rb
CHANGED
@@ -52,17 +52,43 @@ module Tempo
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def method_missing(meth, *args, &block)
|
55
|
+
if respond_to? meth
|
56
|
+
if meth.to_s =~ /^find_by_(.+)$/
|
57
|
+
self.class.send(:define_method, meth) do |*args|
|
58
|
+
run_find_by_method($1, *args)
|
59
|
+
end
|
60
|
+
self.send(meth, *args)
|
55
61
|
|
56
|
-
|
57
|
-
|
62
|
+
elsif meth.to_s =~ /^sort_by_(.+)$/
|
63
|
+
self.class.send(:define_method, meth) do |*args, &block|
|
64
|
+
run_sort_by_method($1, *args, &block)
|
65
|
+
end
|
66
|
+
self.send(meth, *args, &block)
|
58
67
|
|
59
|
-
|
60
|
-
|
68
|
+
else
|
69
|
+
super
|
70
|
+
end
|
61
71
|
else
|
62
72
|
super
|
63
73
|
end
|
64
74
|
end
|
65
75
|
|
76
|
+
def respond_to?(method_id, include_private = false)
|
77
|
+
if method_id.to_s =~ /^find_by_(.+)$/ || method_id.to_s =~ /^sort_by_(.+)$/
|
78
|
+
instances_have_attributes? $1.split('_and_')
|
79
|
+
else
|
80
|
+
super
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def instances_have_attributes?(attrs)
|
85
|
+
finder_attrs = attrs.map { |key| "@#{key}".to_sym }
|
86
|
+
model_attrs = index.map { |i| i.instance_variables }.flatten.uniq
|
87
|
+
|
88
|
+
# Make sure all attributes are present in index objects
|
89
|
+
(model_attrs & finder_attrs).size == finder_attrs.size
|
90
|
+
end
|
91
|
+
|
66
92
|
def run_sort_by_method(attribute, args=@index.clone, &block)
|
67
93
|
attr = "@#{attribute}".to_sym
|
68
94
|
args.sort! { |a,b| a.instance_variable_get( attr ) <=> b.instance_variable_get( attr ) }
|
@@ -70,7 +96,7 @@ module Tempo
|
|
70
96
|
block.call args
|
71
97
|
end
|
72
98
|
|
73
|
-
def run_find_by_method(attrs, *args
|
99
|
+
def run_find_by_method(attrs, *args)
|
74
100
|
# Make an array of attribute names
|
75
101
|
attrs = attrs.split('_and_')
|
76
102
|
|
data/lib/tempo/models/project.rb
CHANGED
data/lib/tempo/version.rb
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
|
+
# Used to test define_method is called
|
4
|
+
# the first time a find_by_ and sort_by_
|
5
|
+
# is called. Don't use for any other tests
|
6
|
+
class Plant < Tempo::Model::Base
|
7
|
+
attr_accessor :stem, :leaf
|
8
|
+
|
9
|
+
def initialize( options={} )
|
10
|
+
super options
|
11
|
+
@stem = options.fetch(:stem, "woody")
|
12
|
+
@leaf = options.fetch(:leaf, "broad")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
|
3
17
|
describe Tempo do
|
4
18
|
|
5
19
|
before do
|
@@ -8,6 +22,11 @@ describe Tempo do
|
|
8
22
|
Dir.mkdir(@dir, 0700) unless File.exists?(@dir)
|
9
23
|
end
|
10
24
|
|
25
|
+
def after_teardown
|
26
|
+
Tempo::Model::Animal.clear_all
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
11
30
|
describe "Model::Base" do
|
12
31
|
|
13
32
|
it "is inheritable from" do
|
@@ -127,10 +146,6 @@ describe Tempo do
|
|
127
146
|
search = Tempo::Model::Animal.find_by_species("Versicolor")
|
128
147
|
search.must_equal [ @gray_tree_frog ]
|
129
148
|
|
130
|
-
# # test, does this work, and should it?
|
131
|
-
# search = Tempo::Model::Animal.find_by_species("h. color")
|
132
|
-
# search.must_equal [ @gray_tree_frog ]
|
133
|
-
|
134
149
|
search = Tempo::Model::Animal.find_by_genious("hyla")
|
135
150
|
search.length.must_equal 5
|
136
151
|
|
@@ -138,6 +153,26 @@ describe Tempo do
|
|
138
153
|
search.must_equal [ @gray_tree_frog ]
|
139
154
|
end
|
140
155
|
|
156
|
+
it "responds to find_by_ method" do
|
157
|
+
# Current behavior raises error if no instances exist.
|
158
|
+
# This behavior could be relaxed, or models could be made
|
159
|
+
# to explicity declare findable attributes
|
160
|
+
frog_factory
|
161
|
+
Tempo::Model::Animal.must_respond_to :find_by_species
|
162
|
+
end
|
163
|
+
|
164
|
+
it "doesn't respond to find_by_ method for non-existent attribute" do
|
165
|
+
Tempo::Model::Animal.wont_respond_to :find_by_blah
|
166
|
+
proc { Tempo::Model::Animal.find_by_blah 1 }.must_raise NoMethodError
|
167
|
+
end
|
168
|
+
|
169
|
+
it "defines find_by_ methods after first call" do
|
170
|
+
plant = Plant.new
|
171
|
+
Plant.methods.include?(:find_by_stem).must_equal false
|
172
|
+
Plant.find_by_stem("woody")
|
173
|
+
Plant.methods.include?(:find_by_stem).must_equal true
|
174
|
+
end
|
175
|
+
|
141
176
|
it "has a sort_by_ method" do
|
142
177
|
frog_factory
|
143
178
|
list = Tempo::Model::Animal.sort_by_species [ @gray_tree_frog, @pine_barrens_tree_frog ]
|
@@ -160,6 +195,26 @@ describe Tempo do
|
|
160
195
|
list.must_equal "h. andersonii, h. avivoca, h. chinensis, h. chrysoscelis, h. versicolor"
|
161
196
|
end
|
162
197
|
|
198
|
+
it "responds to sort_by_ method" do
|
199
|
+
# Current behavior raises error if no instances exist.
|
200
|
+
# This behavior could be relaxed, or models could be made
|
201
|
+
# to explicity declare sortable attributes
|
202
|
+
frog_factory
|
203
|
+
Tempo::Model::Animal.must_respond_to :sort_by_species
|
204
|
+
end
|
205
|
+
|
206
|
+
it "doesn't respond to sort_by_ method for non-existent attribute" do
|
207
|
+
Tempo::Model::Animal.wont_respond_to :sort_by_blah
|
208
|
+
proc { Tempo::Model::Animal.sort_by_blah }.must_raise NoMethodError
|
209
|
+
end
|
210
|
+
|
211
|
+
it "defines sort_by methods after first call" do
|
212
|
+
plant = Plant.new
|
213
|
+
Plant.methods.include?(:sort_by_stem).must_equal false
|
214
|
+
Plant.sort_by_stem
|
215
|
+
Plant.methods.include?(:sort_by_stem).must_equal true
|
216
|
+
end
|
217
|
+
|
163
218
|
it "has a method_missing method" do
|
164
219
|
proc { Tempo::Model::Animal.foo }.must_raise NoMethodError
|
165
220
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tempo-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Gabel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|