Class: CatalystAutomation::Base
- Inherits:
-
Object
- Object
- CatalystAutomation::Base
- Defined in:
- lib/catalyst_automation.rb
Class Method Summary collapse
- .connect_db(conn_str) ⇒ Object
- .create_const(const_name, key, const_type) ⇒ Object
- .create_iframes(db_pages, db_sections) ⇒ Object
- .create_pages(db_pages, db_sections) ⇒ Object
-
.create_personas(personas_data) ⇒ Object
def self.create_actions(db_actions) db_actions.each do |page| if page[page.class.eql?(Symbol) ? :type : “type”].eql? “page_action” Object.const_get(page[(page.class.eql?(Symbol) ? :name : “name”)]).class_eval do page[page.class.eql?(Symbol) ? :actions : “actions”].each do |action| define_method action[page.kind_of?(Symbol) ? :name : “name”].to_sym do action[page.kind_of?(Symbol) ? :action_methods : “action_methods”].each do |method| m_func = method[page.kind_of?(Symbol) ? :name : “name”].split(‘_’).last elem_array = method[page.kind_of?(Symbol) ? :name : “name”].split(‘_’) elem_array.pop func_name = “” elem_array.each do |e| func_name = func_name + “#e_” end func_name = func_name func_name = “#func_name.#m_func” param = method[page.kind_of?(Symbol) ? :param : “param”] if !param.eql?(“no_param”) eval(“#func_name(#param)”) else eval(“#func_name”) end end end end end end end end.
- .create_sections(db_pages) ⇒ Object
- .get_db_info(db_con, info) ⇒ Object
- .get_rest_api_info(rest_api, object) ⇒ Object
- .set_elements(const_name, key) ⇒ Object
- .set_iframes(const_name, key, db_pages) ⇒ Object
- .set_sections(const_name, key, db_sections) ⇒ Object
Class Method Details
.connect_db(conn_str) ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/catalyst_automation.rb', line 102 def self.connect_db(conn_str) db_conn = Mongo::Client.new(conn_str) begin yield db_conn rescue => error raise error end end |
.create_const(const_name, key, const_type) ⇒ Object
61 62 63 |
# File 'lib/catalyst_automation.rb', line 61 def self.create_const(const_name, key, const_type) Object.const_set(const_name[(const_name.class.eql?(Symbol) ? key : key.to_s)], const_type) end |
.create_iframes(db_pages, db_sections) ⇒ Object
136 137 138 139 140 141 142 143 |
# File 'lib/catalyst_automation.rb', line 136 def self.create_iframes(db_pages, db_sections) db_pages.each do |page| if page[(page.class.eql?(Symbol) ? :type : "type")].eql? "iframe" create_const(page, :name, Class.new(SitePrism::Page)) set_elements(page, :name) end end end |
.create_pages(db_pages, db_sections) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/catalyst_automation.rb', line 145 def self.create_pages(db_pages, db_sections) db_pages.each do |page| if page[(page.class.eql?(Symbol) ? :type : "type")].eql? "page" create_const(page, :name, Class.new(SitePrism::Page)) set_elements(page, :name) #set_sections(page, :name, db_sections) #set_iframes(page, :name, db_pages) Object.const_get(page[(page.class.eql?(Symbol) ? :name : "name")]).class_eval do set_url page[(page.class.eql?(Symbol) ? :url : "url")] end end end end |
.create_personas(personas_data) ⇒ Object
def self.create_actions(db_actions)
db_actions.each do |page|
if page[page.class.eql?(Symbol) ? :type : "type"].eql? "page_action"
Object.const_get(page[(page.class.eql?(Symbol) ? :name : "name")]).class_eval do
page[page.class.eql?(Symbol) ? :actions : "actions"].each do |action|
define_method action[page.kind_of?(Symbol) ? :name : "name"].to_sym do
action[page.kind_of?(Symbol) ? :action_methods : "action_methods"].each do |method|
m_func = method[page.kind_of?(Symbol) ? :name : "name"].split('_').last
elem_array = method[page.kind_of?(Symbol) ? :name : "name"].split('_')
elem_array.pop
func_name = ""
elem_array.each do |e|
func_name = func_name + "#{e}_"
end
func_name = func_name[0...-1]
func_name = "#{func_name}.#{m_func}"
param = method[page.kind_of?(Symbol) ? :param : "param"]
if !param.eql?("no_param")
eval("#{func_name}(#{param})")
else
eval("#{func_name}")
end
end
end
end
end
end
end
end
221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/catalyst_automation.rb', line 221 def self.create_personas(personas_data) personas_data.each do |persona| create_const(persona, :name, Class.new) Object.const_get(persona[(persona.class.eql?(Symbol) ? :name : "name")]).class_eval do persona[(persona.class.eql?(Symbol) ? :attributes : "attributes")].each do |attrs| name = attrs[(persona.kind_of?(Symbol) ? :name : "name")] value = attrs[(persona.kind_of?(Symbol) ? :value : "value")] define_method name.to_sym do value end end end end end |
.create_sections(db_pages) ⇒ Object
129 130 131 132 133 134 |
# File 'lib/catalyst_automation.rb', line 129 def self.create_sections(db_pages) db_pages.each do |section| create_const(section, :name, Class.new(SitePrism::Section)) set_elements(section, :name) end end |
.get_db_info(db_con, info) ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/catalyst_automation.rb', line 111 def self.get_db_info(db_con, info) m_info = [] db_info = db_con.database[info].find() db_info.each_entry do |entry| m_info << entry end return m_info end |
.get_rest_api_info(rest_api, object) ⇒ Object
120 121 122 123 124 125 126 127 |
# File 'lib/catalyst_automation.rb', line 120 def self.get_rest_api_info(rest_api, object) m_info = [] rest_info = JSON.parse(RestClient.get(rest_api + object)) rest_info.each do |entry| m_info << entry end return m_info end |
.set_elements(const_name, key) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/catalyst_automation.rb', line 65 def self.set_elements(const_name, key) Object.const_get(const_name[(const_name.kind_of?(Symbol) ? key : key.to_s)]).class_eval do const_name[(const_name.kind_of?(Symbol) ? :elements : "elements" )].each do |element| send(:element, element[(const_name.kind_of?(Symbol) ? :name : "name")], element[(const_name.kind_of?(Symbol) ? :path : "path")]) end end end |
.set_iframes(const_name, key, db_pages) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/catalyst_automation.rb', line 87 def self.set_iframes(const_name, key, db_pages) Object.const_get(const_name[(const_name.kind_of?(Symbol) ? :name : "name")]).class_eval do const_name[(const_name.kind_of?(Symbol) ? :iframes : "iframes")].each do |iframe| m_iframe_name = "" db_pages.each do |db_page| if iframe[:iframe_id].to_s.eql?(db_page[:_id].to_s) m_iframe_name = db_page[const_name.kind_of?(Symbol) ? :name : "name"] end end send(:iframe, iframe[(const_name.kind_of?(Symbol) ? :name : "name")], Object.const_get(m_iframe_name), iframe[(const_name.kind_of?(Symbol) ? :path : "path")]) end end end |
.set_sections(const_name, key, db_sections) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/catalyst_automation.rb', line 73 def self.set_sections(const_name, key, db_sections) Object.const_get(const_name[(const_name.kind_of?(Symbol) ? :name : "name")]).class_eval do const_name[(const_name.kind_of?(Symbol) ? :page_sections : "page_sections")].each do |section| m_class_name = "" db_sections.each do |db_section| if section[:section_id].to_s.eql?(db_section[:_id].to_s) m_class_name = db_section[const_name.kind_of?(Symbol) ? :name : "name"] end end send(:section, section[(const_name.kind_of?(Symbol) ? :name : "name")], Object.const_get(m_class_name), section[(const_name.kind_of?(Symbol) ? :path : "path")]) end end end |