Skip to content

Commit

Permalink
Implement v1 of If procedure (#44)
Browse files Browse the repository at this point in the history
* Introduce reference to "raw" params

* Delegate accessor :raw_params to @parameters (parameter_interpreter)

* Add duration method to Sleep model to move out parameters handling out of the partial

* Introduce Att model.

Related to #37

* Fix child nid, prepending exid twice or many times before nid when dealing with nested children sequence/concurence/if.

Related to #37

* Unskip if spec, update fixture, and complete if spec

Related to #37

* Make If a branch procedure, and v1 of view

* Align sqlite version (1.3.6) with ActiveRecord 4.2.8 requirement

* Fix edit spec: current nid format
  • Loading branch information
jfrioux authored Apr 27, 2019
1 parent 951d6cd commit 5d1b035
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ group :test do
gem 'statesman', '~> 2.0.1'
gem 'statesman-events', '~> 0.0.1'
gem "jquery-rails"
gem "sqlite3"
gem "sqlite3", '~> 1.3.6'
gem "twitter-bootstrap-rails"
end

Expand Down
8 changes: 8 additions & 0 deletions app/models/floristry/att.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Floristry
class Att < LeafProcedure
def comparison

"(#{raw_params[0][1][0][1]} #{raw_params[0][0]} #{raw_params[0][1][1][1]})"
end
end
end
3 changes: 2 additions & 1 deletion app/models/floristry/if.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module Floristry
class If < LeafProcedure
class If < BranchProcedure

end
end
2 changes: 1 addition & 1 deletion app/models/floristry/leaf_procedure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class LeafProcedure < Procedure
attr_accessor :payload
attr_reader :param, :params

delegate :param, :params, to: :@parameters
delegate :param, :params, :raw_params, to: :@parameters

def initialize(id, name, params, payload, era)

Expand Down
3 changes: 2 additions & 1 deletion app/models/floristry/parameters_interpreter.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module Floristry
class ParametersInterpreter

attr_reader :params
attr_reader :params, :raw_params

def initialize(params)

@params = []
@raw_params = params
interpret params
end

Expand Down
4 changes: 4 additions & 0 deletions app/models/floristry/sleep.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module Floristry
class Sleep < LeafProcedure

def duration

params[0]
end
end
end
2 changes: 1 addition & 1 deletion app/models/floristry/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def branch(expid, parent_node)
child_nid = "#{expid}#{NID_SEP}#{i}"
if child_node.is_a? Array # todo -> why does payload ends up ad [3] in a sequence, adding `nil` at [2] ?
branch_or_leaf = is_branch?(child_node[0].camelize) ? :branch : :leaf
obj << self.send(branch_or_leaf, "#{exid}!#{child_nid}", child_node)
obj << self.send(branch_or_leaf, child_nid, child_node)
end
end

Expand Down
1 change: 1 addition & 0 deletions app/views/floristry/workflows/_flo_att.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<pre>if <%= flo_att.comparison %></pre>
15 changes: 14 additions & 1 deletion app/views/floristry/workflows/_flo_if.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
If <pre><%= floIf.inspect %></pre>
<div class="rat-sequence">
<%- flo_if.each_with_index do |child, index| %>
<%= render :partial => child,
:layout => child.layout,
:object => child,
:locals => {:leaf => child} %>

<% if index == 0 %>
<p>then</p>
<% elsif index != flo_if.size - 1 %>
<p>else</p>
<% end %>
<%- end %>
</div>
2 changes: 1 addition & 1 deletion app/views/floristry/workflows/_flo_sleep.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<div class="rat-part-header">
</div>
<div class="rat-part">
Sleep for <pre><%= flo_sleep.params[0] %></pre>
Sleep for <pre><%= flo_sleep.duration %></pre>
</div>
</div>
2 changes: 1 addition & 1 deletion spec/controllers/workflows_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@

context "if" do
it 'renders the if partial' do
skip("not implemented")
sequence = floristry_trails(:sequence_if)
get :edit, id: sequence.wfid
expect(response).to render_template(partial: '_flo_if')
expect(response.body).to match /if \(0 &gt; 3\).*/im
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/rails_app/Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
source 'https://rubygems.org'

# ~Standard Rails stack
gem "sqlite3", '~> 1.3.6'
gem 'rails', '4.2.8'
gem 'sqlite3'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/floristry_trails.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sequence_cron:

sequence_if:
wfid: test-u0-11111111.1337.iftruebob
tree: '["sequence",[["if",[["_boo",true,4],["bob",[["_att",[["_",[],5]],5]],5,{"ret":"bob"}]],3]],2,{},{}]'
tree: '["sequence",[["if",[["_att",[["\u003e",[["_num",0,3],["_num",3,3]],3]],3],["sequence",[["alice",[["_att",[["_",[],5]],5]],5]],4],["sequence",[["bob",[["_att",[["_",[],7]],7]],7,{"ret":"bob","bob_tstamp":"2019-02-16 10:44:15 -0500"}]],6]],3]],2,{},{"name":"If 0 \u003e 1 alice else bob"}]'

sequence_set:
wfid: test-u0-11111111.1337.seqthatsets
Expand Down
2 changes: 1 addition & 1 deletion spec/views/workflows/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
context "in progress workflow" do
it "display one participant as 'closed' and the other as 'open'" do
wf = stub_workflow
wf.current_nids = ["#{wf.id}!0_1"]
wf.current_nids = ["0_1"]
assign(:wf, wf)
render

Expand Down

0 comments on commit 5d1b035

Please sign in to comment.