class Marta::Json2Class::SmartPageCreator

To create a special class we are using a special class

@note It is believed that no user will use it

Public Class Methods

create(class_name, data, edit) click to toggle source

Main class creation method.

SmartPage can be initialized with user data as well

# File lib/marta/json_2_class.rb, line 42
def self.create(class_name, data, edit)
  c = Class.new(SmartPage) do
    alias_method :old_init, :initialize
    define_method :initialize do |my_data=data, my_class_name=class_name,
                                  will_edit=edit|
      old_init(class_name, my_data, will_edit)
    end
  end
  # We are vanishing previous version of class
  if Kernel.constants.include?(class_name.to_sym)
    Kernel.send(:remove_const, class_name.to_sym)
  end
  # We are declaring our class
  Kernel.const_set class_name, c
end
create_all() click to toggle source

Marta is parsing all the files in pageobject folder into classes

# File lib/marta/json_2_class.rb, line 69
def self.create_all
  if File.directory?(SettingMaster.pageobjects_folder)
    Dir["#{SettingMaster.pageobjects_folder}/*.json"].each do |file_name|
      json_2_class(file_name, true) #true here
    end
  else
    FileUtils::mkdir_p SettingMaster.pageobjects_folder
  end
end
json_2_class(json, edit_enabled = true) click to toggle source

We are parsing file into a class

# File lib/marta/json_2_class.rb, line 59
def self.json_2_class(json, edit_enabled = true)
  data = ReaderWriter.file_2_hash(json)
  if !data.nil?
    class_name = File.basename(json, ".*")
    edit_mark = SettingMaster.learn_status and edit_enabled
    create class_name, data, edit_mark
  end
end