expressive 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/expressive.rb +1 -1
- data/lib/expressive/version.rb +1 -1
- data/lib/scope.rb +11 -0
- data/spec/expressive_spec.rb +21 -1
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/lib/expressive.rb
CHANGED
@@ -20,7 +20,7 @@ module Expressive
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.all_symbols
|
23
|
-
%w(+ - * / = set sum post >= > < <= and or if date get put lookup round $days_ago $hours_ago $minutes_ago)
|
23
|
+
%w(+ - * / = set sum post >= > < <= and or if date get put lookup round $days_ago $hours_ago $minutes_ago $append $id)
|
24
24
|
end
|
25
25
|
|
26
26
|
module Boolean
|
data/lib/expressive/version.rb
CHANGED
data/lib/scope.rb
CHANGED
@@ -78,6 +78,16 @@ module Expressive
|
|
78
78
|
scope[cells.first.text_value] = cells[1].eval(scope)
|
79
79
|
end
|
80
80
|
|
81
|
+
syntax('$append') do |scope, cells|
|
82
|
+
scope[cells.first.text_value] = [] if scope[cells.first.text_value].nil?
|
83
|
+
addition = cells[1].eval(scope)
|
84
|
+
if addition.is_a?(Array)
|
85
|
+
scope[cells.first.text_value] = scope[cells.first.text_value] | addition
|
86
|
+
else
|
87
|
+
scope[cells.first.text_value] << addition
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
81
91
|
syntax('lookup') do |scope, cells|
|
82
92
|
lookup_result = scope.lookups[cells.first.text_value]
|
83
93
|
if lookup_result
|
@@ -114,6 +124,7 @@ module Expressive
|
|
114
124
|
end
|
115
125
|
end
|
116
126
|
|
127
|
+
define('$id') {|*args| args.first.id }
|
117
128
|
define('+') {|a,b| a.to_f + b.to_f }
|
118
129
|
define('-') {|a,b| a.to_f - b.to_f }
|
119
130
|
define('*') {|a,b| a.to_f * b.to_f }
|
data/spec/expressive_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe "Expressive" do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
describe "all_symbols" do
|
9
|
-
it { Expressive.all_symbols.should =~ %w(+ - * / = set sum get put post >= > < <= and or if date lookup round $days_ago $hours_ago $minutes_ago) }
|
9
|
+
it { Expressive.all_symbols.should =~ %w(+ - * / = set sum get put post >= > < <= and or if date lookup round $days_ago $hours_ago $minutes_ago $append $id) }
|
10
10
|
end
|
11
11
|
|
12
12
|
describe "understands booleans" do
|
@@ -142,6 +142,26 @@ describe "Expressive" do
|
|
142
142
|
@scope["owned_by_id"].should eql @user2.id
|
143
143
|
@scope["owned_by_type"].should eql "RSpec::Mocks::Mock"
|
144
144
|
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
describe "understands adding values to lists" do
|
149
|
+
it "add a single value to a list of values" do
|
150
|
+
Expressive.run('($append participating_teams 1)', @scope)
|
151
|
+
@scope['participating_teams'].should == [1]
|
152
|
+
end
|
153
|
+
it "append to a list values list of values" do
|
154
|
+
@scope['participating_teams'] = [0]
|
155
|
+
Expressive.run('($append participating_teams (1 2 3))', @scope)
|
156
|
+
@scope['participating_teams'].should == [0, 1, 2, 3]
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "understands retrieving the id of an object" do
|
161
|
+
it do
|
162
|
+
@scope["an_object"] = mock(:an_object, id: 5)
|
163
|
+
Expressive.run('($id an_object)', @scope).should == 5
|
164
|
+
end
|
145
165
|
end
|
146
166
|
|
147
167
|
describe "understands time ranges" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: expressive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.17
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ruby_gntp
|
@@ -294,7 +294,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
294
294
|
version: '0'
|
295
295
|
segments:
|
296
296
|
- 0
|
297
|
-
hash:
|
297
|
+
hash: -4421834201384334289
|
298
298
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
299
299
|
none: false
|
300
300
|
requirements:
|
@@ -303,7 +303,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
303
303
|
version: '0'
|
304
304
|
segments:
|
305
305
|
- 0
|
306
|
-
hash:
|
306
|
+
hash: -4421834201384334289
|
307
307
|
requirements: []
|
308
308
|
rubyforge_project:
|
309
309
|
rubygems_version: 1.8.23
|