factor 0.0.99 → 0.1.00

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,12 +23,9 @@ module Factor
23
23
  puts @client.get_channels
24
24
  end
25
25
 
26
- desc "add NAME DIRECTORY", "add a key and value for the credential"
27
- def add(name,directory)
28
-
29
- #contents=File.open(File.expand_path(filename), "rb") {|f| f.read}
30
-
31
- puts @client.add_channel(name,directory)
26
+ desc "add DIRECTORY DEFINITION", "add a key and value for the credential"
27
+ def add(directory,definition_file)
28
+ puts @client.add_channel(directory,definition_file)
32
29
  end
33
30
 
34
31
  desc "remove NAME", "remove a workflow"
@@ -18,10 +18,10 @@ module Factor
18
18
  puts @client.set_credential(key,value)
19
19
  end
20
20
 
21
- desc "remove KEY", "remove a value from the credentials bag"
22
- def remove(key)
23
- puts @client.remove_credential(key)
24
- end
21
+ # desc "remove KEY", "remove a value from the credentials bag"
22
+ # def remove(key)
23
+ # puts @client.remove_credential(key)
24
+ # end
25
25
 
26
26
  end
27
27
  end
@@ -32,10 +32,10 @@ module Factor
32
32
  puts @client.add_workflow(name,contents)
33
33
  end
34
34
 
35
- desc "remove NAME", "remove a workflow"
36
- def remove(name)
37
- puts @client.remove_workflow(name)
38
- end
35
+ # desc "remove NAME", "remove a workflow"
36
+ # def remove(name)
37
+ # puts @client.remove_workflow(name)
38
+ # end
39
39
 
40
40
 
41
41
 
@@ -11,6 +11,7 @@ module Factor
11
11
  attr_accessor :host
12
12
 
13
13
  def initialize(host="http://factor.io")
14
+ #def initialize(host="http://localhost:3000/")
14
15
  @host=host
15
16
  end
16
17
 
@@ -114,24 +115,25 @@ module Factor
114
115
  rest_get("workflows")
115
116
  end
116
117
 
117
- def remove_workflow(name="")
118
- rest_delete("workflows",{:name=>name})
119
- end
118
+ # def remove_workflow(name="")
119
+ # rest_delete("workflows",{:name=>name})
120
+ # end
120
121
 
121
122
 
122
123
  # channels
123
- def add_channel(key,path)
124
- file=zip(path)
125
- rest_post("channels",{:name=>key,:zip=>file})
124
+ def add_channel(path,definition_file)
125
+ file=zip(File.expand_path(path))
126
+ definition = File.read(definition_file)
127
+ rest_post("channels",{:zip=>file,:definition=>definition})
126
128
  end
127
129
 
128
130
  def get_channels()
129
131
  rest_get("channels")
130
132
  end
131
133
 
132
- def remove_channel(name="")
133
- rest_delete("channels",{:name=>name})
134
- end
134
+ # def remove_channel(name="")
135
+ # rest_delete("channels",{:name=>name})
136
+ # end
135
137
 
136
138
 
137
139
 
@@ -174,7 +176,7 @@ module Factor
174
176
  def zip(directory)
175
177
  path=directory.dup
176
178
  path.sub!(%r[/$],'')
177
- zip_path = File.join(path,File.basename(path))+'.zip'
179
+ zip_path = File.join(path,"..",File.basename(path))+'.zip'
178
180
  FileUtils.rm zip_path, :force=>true
179
181
  Zip::ZipFile.open(zip_path, 'w') do |zip|
180
182
  Dir["#{path}/**/**"].reject{|f|f==zip_path}.each do |file|
@@ -31,7 +31,7 @@ module Factor
31
31
  require filename
32
32
  channel_module_name = File.basename(filename).gsub('.rb','').split('_').map{|ea| ea.capitalize}.join('')
33
33
  channel_module= self.class.const_get(channel_module_name)
34
- @channel_modules[channel_module.definition["module"]]=channel_module
34
+ @channel_modules[channel_module_name]=channel_module
35
35
  end
36
36
 
37
37
  def load_credentials credentials
@@ -54,6 +54,7 @@ module Factor
54
54
 
55
55
  def launch workflow, params
56
56
  instance_id=SecureRandom.hex
57
+
57
58
  @message_bus.start do
58
59
  message = Message.new
59
60
  message.position << "start"
@@ -76,8 +77,8 @@ module Factor
76
77
  if !activity.nil?
77
78
  action = activity["action"]
78
79
  channel = activity["channel"]
79
- method = activity["method"]
80
80
  target = activity["target"]
81
+ params_template = activity["params"]
81
82
 
82
83
 
83
84
  if match(target)
@@ -87,13 +88,15 @@ module Factor
87
88
 
88
89
  #puts "[activity-params] #{activity["params"]}"
89
90
  #puts "[values] #{values}"
90
- params = render_template(activity["params"],values)
91
- #puts "[params] #{params}"
91
+ params = render_template(params_template,values)
92
+ puts "[rendered params] #{params}"
92
93
 
93
- event = call_channel_method(channel,method,params)
94
+ event = call_channel_method(channel,action,params)
94
95
 
96
+ # puts "event #{event.inspect}"
95
97
  response_message = message.respond(event.params,event.class.name.split("::").last)
96
98
 
99
+ # puts "response #{response_message.inspect}"
97
100
 
98
101
  @message_bus.send response_message
99
102
  end
@@ -114,6 +117,7 @@ module Factor
114
117
  def call_channel_method(channel_name,class_name,params)
115
118
  channel_module = @channel_modules[channel_name]
116
119
  command = channel_module.const_get(class_name)
120
+ puts "command: #{command.inspect}"
117
121
  command.new.do_work(params)
118
122
  end
119
123
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.99
4
+ version: 0.1.00
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: