Class: Marta::Json2Class::SmartPageCreator
- Inherits:
-
Object
- Object
- Marta::Json2Class::SmartPageCreator
- Includes:
- OptionsAndPaths, ReadWrite
- Defined in:
- lib/marta/json_2_class.rb
Overview
Note:
It is believed that no user will use it
To create a special class we are using a special class
Class Method Summary collapse
-
.create(class_name, data, edit) ⇒ Object
Main class creation method.
-
.create_all ⇒ Object
Marta is parsing all the files in pageobject folder into classes.
-
.json_2_class(json, edit_enabled = true) ⇒ Object
We are parsing file into a class.
Class Method Details
.create(class_name, data, edit) ⇒ Object
Main class creation method.
SmartPage can be initialized with user data as well
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# 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 ⇒ Object
Marta is parsing all the files in pageobject folder into classes
69 70 71 72 73 74 75 76 77 |
# 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) ⇒ Object
We are parsing file into a class
59 60 61 62 63 64 65 66 |
# 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 |