module Marta::Json2Class

Here Marta is reading json files and precreating pageobject classes which were defined previously

Main trick of the Marta is parsing jsons files to classes. For example valid Foo.json file in a valid folder will turn into Foo class. Class content differs when Marta is set to learning mode and when it's not. Class will have methods = watir elements and vars = user defined vars with default values. Class will not accept any arguments for generated methods. The class will have default initialize method, engine method.

Also the class can has method_edit method. In theory it can be called like Foo.method_edit('new_method_name'). It should define new method even if learn mode is disabled. But I am never using such construction :) In learn mode any unknown method will cause dialog that will ask user about what element should be used.

Also for each method foo method foo_exact will be created and vice versa. Method wich ends with exact will use strict element searching scheme.

Private Instance Methods

build_content(data) click to toggle source
# File lib/marta/json_2_class.rb, line 88
def build_content(data)
  build_methods(data['meths']) if !data['meths'].nil?
  build_vars(data['vars']) if !data['vars'].nil?
end
build_method(name, content) click to toggle source
# File lib/marta/json_2_class.rb, line 105
def build_method(name, content)
  define_singleton_method name.to_sym do
    learn_status ? method_edit(name) : marta_magic_finder(content, name)
  end
  exact = name + '_exact'
  define_singleton_method exact.to_sym do
    learn_status ? method_edit(exact) : marta_simple_finder(content)
  end
end
build_methods(methods) click to toggle source
# File lib/marta/json_2_class.rb, line 93
def build_methods(methods)
  methods.each_pair do |method_name, content|
    build_method method_name, content
  end
end
build_var(name, content) click to toggle source
# File lib/marta/json_2_class.rb, line 115
def build_var(name, content)
  if !self.methods.include?(name.to_sym) and (@data['meths'][name].nil?)
    self.singleton_class.send(:attr_accessor, name.to_sym)
    instance_variable_set("@#{name}", process_string(content))
  elsif self.methods.include?(name.to_sym) and (@data['meths'][name].nil?)
    instance_variable_set("@#{name}", process_string(content))
  else
    if !@data['meths'][name].nil?
      warn "Marta will not create '#{name}' variable for #{self.class}"\
      " since it is already in use by method"
    end
  end
end
build_vars(vars) click to toggle source
# File lib/marta/json_2_class.rb, line 99
def build_vars(vars)
  vars.each do |var_name, default_value|
    build_var var_name, default_value
  end
end
correct_name(name) click to toggle source
# File lib/marta/json_2_class.rb, line 129
def correct_name(name)
  if name.to_s.end_with? "_exact"
    method_name = name.to_s[0..-7]
  else
    method_name = name.to_s
  end
  method_name
end
json_2_class(json, edit_enabled = true) click to toggle source
# File lib/marta/json_2_class.rb, line 84
def json_2_class(json, edit_enabled = true)
  SmartPageCreator.json_2_class(json, edit_enabled)
end
read_folder() click to toggle source
# File lib/marta/json_2_class.rb, line 80
def read_folder
  SmartPageCreator.create_all
end