Module: Marta::PublicMethods
- Includes:
- OptionsAndPaths
- Included in:
- Dialogs::MethodSpeaker, SmartPage
- Defined in:
- lib/marta/public_methods.rb
Overview
Methods that user can use out of the box in SmartPage
Instance Method Summary collapse
- #default_method_missing ⇒ Object
-
#engine ⇒ Object
User can get engine (normally browser instance or iframe element).
-
#initialize(my_class_name, my_data = ({"vars" => {},"meths" => {}}), will_edit = true) ⇒ Object
User can create pageobject class using SmartPage.new.
-
#method_edit(name) ⇒ Object
User can define a method for example in a middle of a debug session.
-
#method_missing(method_name, *args, &block) ⇒ Object
method missing hijacking It should be used only for SmartPage.
-
#open_page(url = nil) ⇒ Object
If page has url variable it can be opened like Page.new.open_page.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
method missing hijacking It should be used only for SmartPage
81 82 83 84 85 86 87 |
# File 'lib/marta/public_methods.rb', line 81 def method_missing(method_name, *args, &block) if learn_status method_edit(method_name)# , *args, &block) else default_method_missing(method_name, *args, &block) end end |
Instance Method Details
#default_method_missing ⇒ Object
78 |
# File 'lib/marta/public_methods.rb', line 78 alias_method :default_method_missing, :method_missing |
#engine ⇒ Object
User can get engine (normally browser instance or iframe element)
58 59 60 |
# File 'lib/marta/public_methods.rb', line 58 def engine SettingMaster.engine end |
#initialize(my_class_name, my_data = ({"vars" => {},"meths" => {}}), will_edit = true) ⇒ Object
User can create pageobject class using SmartPage.new
SmartPage can be created without all the data. But in that case it will be pretty useless until values are provided
The first argument is a class name. It is a constant-like string like “MyClass”. All data provided will be stored in MyClass.json Once it is created that way you can call it like MyClass.new. That argument is totally necessary one
The second argument is a marta’s special data hash. By default = “vars”=>{,“meths”=>{}}. You can take an existing json as well. Notice that rocket like syntax is a must here. It will be changed later
Third parameter is about to show or not default page creation dialog. So it can be true or false
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/marta/public_methods.rb', line 26 def initialize(my_class_name, my_data = ({"vars" => {},"meths" => {}}), will_edit = true) @data ||= my_data @class_name ||= my_class_name @edit_mark ||= will_edit data_vars = Hash.new build_content my_data if will_edit data_vars = page_edit my_class_name, my_data my_data["vars"] = data_vars if data_vars != Hash.new end # We need optimization here very much! build_content my_data end |
#method_edit(name) ⇒ Object
User can define a method for example in a middle of a debug session
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/marta/public_methods.rb', line 42 def method_edit(name) method_name = correct_name(name) exact_name = method_name.to_s + "_exact" data = user_method_dialogs(method_name) define_singleton_method method_name. to_sym do |meth_content=@data['meths'][method_name]| marta_magic_finder(meth_content, method_name) end define_singleton_method exact_name. to_sym do |meth_content=@data['meths'][method_name]| marta_simple_finder(meth_content) end public_send name.to_sym end |
#open_page(url = nil) ⇒ Object
If page has url variable it can be opened like Page.new.open_page
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/marta/public_methods.rb', line 63 def open_page(url = nil) @path ||= "" if !url.nil? engine.goto url elsif !@url.nil? and @url != "" engine.goto @url elsif base_url != "" engine.goto base_url + ((@path == "") ? "" : "/#{@path}") else raise ArgumentError, "You should set url to use open_page. You may"\ " also use base_url option for dance_with and path for page object" end self end |