factor 0.1.04 → 0.1.05

Sign up to get free protection for your applications and to get access to all the features.
data/lib/client/client.rb CHANGED
@@ -12,6 +12,12 @@ module Factor
12
12
 
13
13
  def initialize(host="http://factor.io")
14
14
  @host=host
15
+
16
+ if ENV["FACTOR_HOST"]
17
+ @host=ENV['FACTOR_HOST']
18
+ code.call("Using #{@host} as host address")
19
+ end
20
+
15
21
  end
16
22
 
17
23
  def register(email,password)
@@ -77,11 +83,10 @@ module Factor
77
83
  # unzip download zip into unzipped directory
78
84
  unzip(temp_file.path,unzip_dir)
79
85
 
80
- code.call(channel.to_json)
81
86
  filename = unzip_dir + "/" + channel['module_name'].split(/(?=[A-Z])/).map{ |x| x.downcase }.join('_') + ".rb"
82
87
 
83
- code.call("loading '#{filename}' into engine")
84
- engine.load_channel(filename)
88
+ code.call("loading '#{channel["name"]}' into engine")
89
+ engine.load_channel(filename, channel)
85
90
  end
86
91
 
87
92
 
@@ -12,6 +12,7 @@ module Factor
12
12
  # Engine needs modules that contain the code, workflows to run, and message bus for communication
13
13
  def initialize(username,token)
14
14
  @channel_modules=Hash.new
15
+ @channel_definitions=Array.new
15
16
  @workflows = Hash.new
16
17
  @message_bus = MessageBus.new(username,token)
17
18
  @credentials = Hash.new
@@ -26,12 +27,14 @@ module Factor
26
27
  # the filename is lowercase with "_" for spaces
27
28
  # and the module inside must be camal cased to match
28
29
  # once loaded it is in the channel_modules Hash
29
- def load_channel filename
30
+ def load_channel filename, definition
30
31
  filename = File.absolute_path(File.expand_path(filename.path)) if filename.is_a?(File) # just in case someone passes in a File not a String (i.e. me)
31
32
  require filename
32
- channel_module_name = File.basename(filename).gsub('.rb','').split('_').map{|ea| ea.capitalize}.join('')
33
+ # channel_module_name = File.basename(filename).gsub('.rb','').split('_').map{|ea| ea.capitalize}.join('')
34
+ channel_module_name = definition['module_name']
33
35
  channel_module= self.class.const_get(channel_module_name)
34
36
  @channel_modules[channel_module_name]=channel_module
37
+ @channel_definitions << definition
35
38
  end
36
39
 
37
40
  def load_credentials credentials
@@ -80,7 +83,7 @@ module Factor
80
83
  target = activity["target"]
81
84
  params_template = activity["params"]
82
85
 
83
- if match(target)
86
+ # if match(target)
84
87
  values = message.body.merge(@credentials)
85
88
 
86
89
  # this maps the input values passed in with the templated defined in the workflow
@@ -89,7 +92,7 @@ module Factor
89
92
  response_message = message.respond(event.params,event.class.name.split("::").last)
90
93
 
91
94
  @message_bus.send response_message
92
- end
95
+ # end
93
96
  end
94
97
  else
95
98
  # workflow doesn't exist
@@ -103,15 +106,28 @@ module Factor
103
106
  end
104
107
  end
105
108
 
106
- def call_channel_method(channel_name,class_name,params)
107
- channel_module = @channel_modules[channel_name]
108
- command = channel_module.const_get(class_name)
109
- puts "command: #{command.inspect}"
109
+ def call_channel_method(channel_name,action_name,params)
110
+ channel_module_name = get_channel_module(channel_name)
111
+ channel_module = @channel_modules[channel_module_name]
112
+ action_class = get_action_class(action_name)
113
+ command = channel_module.const_get(action_class)
110
114
  command.new.do_work(params)
111
115
  end
112
116
 
113
117
  private
114
118
 
119
+ def get_channel_module(channel_name)
120
+ @channel_definitions.select { |channel_definition| channel_definition['name']==channel_name }.first['module_name']
121
+ end
122
+
123
+ def get_action_class(action_name)
124
+ @channel_definitions.each do |channel_definition|
125
+ channel_definition['actions'].each do |action|
126
+ return action["class_name"] if action['name']==action_name
127
+ end
128
+ end
129
+ end
130
+
115
131
  def render_template(source,values)
116
132
  #params = Hash.new
117
133
 
@@ -130,14 +146,14 @@ module Factor
130
146
  params
131
147
  end
132
148
 
133
- def match(target)
134
- return true if target==nil || target==""
135
- facts={}
136
- #Facter.each {|k,v| facts[k]=v}
137
- @tags.each {|k,v| facts[k]=v}
138
- key,value=target.split("=")
139
- facts[key]==value
140
- end
149
+ # def match(target)
150
+ # return true if target==nil || target==""
151
+ # facts={}
152
+ # #Facter.each {|k,v| facts[k]=v}
153
+ # @tags.each {|k,v| facts[k]=v}
154
+ # key,value=target.split("=")
155
+ # facts[key]==value
156
+ # end
141
157
 
142
158
 
143
159
  end
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- require 'json/pure'
2
+ require 'json'
3
3
 
4
4
  module Factor
5
5
  module Runtime
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.1.04
4
+ version: 0.1.05
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -98,7 +98,7 @@ dependencies:
98
98
  requirements:
99
99
  - - ! '>='
100
100
  - !ruby/object:Gem::Version
101
- version: 1.7.5
101
+ version: 1.7.6
102
102
  type: :runtime
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,7 +106,7 @@ dependencies:
106
106
  requirements:
107
107
  - - ! '>='
108
108
  - !ruby/object:Gem::Version
109
- version: 1.7.5
109
+ version: 1.7.6
110
110
  - !ruby/object:Gem::Dependency
111
111
  name: amqp
112
112
  requirement: !ruby/object:Gem::Requirement