Class: ActiveMocker::ModelReader Private
- Inherits:
-
Object
- Object
- ActiveMocker::ModelReader
- Defined in:
- lib/active_mocker/model_reader.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: ParsedProperties
Instance Attribute Summary collapse
- #model_name ⇒ Object readonly private
Instance Method Summary collapse
- #eval_file(string, file_path) ⇒ Object private
- #file_path(m_name = model_name) ⇒ Object private
- #klass ⇒ Object private
- #log_loading_error(msg, print_to_stdout = false) ⇒ Object private
- #module_namespace ⇒ Object private
- #parent_class ⇒ Object private
- #parse(model_name) ⇒ Object private
- #read_file(m_name = model_name) ⇒ Object private
- #sandbox_model ⇒ Object private
Instance Attribute Details
#model_name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
6 7 8 |
# File 'lib/active_mocker/model_reader.rb', line 6 def model_name @model_name end |
Instance Method Details
#eval_file(string, file_path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/active_mocker/model_reader.rb', line 34 def eval_file(string, file_path) failure = false begin module_namespace.module_eval(string, file_path) _klass = module_namespace.const_get(module_namespace.constants.last) rescue SyntaxError => e log_loading_error(e, true) failure = true rescue Exception => e log_loading_error(e, false) failure = true end return false if failure _klass end |
#file_path(m_name = model_name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
67 68 69 |
# File 'lib/active_mocker/model_reader.rb', line 67 def file_path(m_name=model_name) "#{Config.model_dir}/#{m_name}.rb" end |
#klass ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
14 15 16 |
# File 'lib/active_mocker/model_reader.rb', line 14 def klass @klass ||= eval_file(sandbox_model, file_path) end |
#log_loading_error(msg, print_to_stdout = false) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
50 51 52 53 54 55 56 57 |
# File 'lib/active_mocker/model_reader.rb', line 50 def log_loading_error(msg, print_to_stdout=false) main = "Error loading Model: #{model_name} \n\t#{msg}\n" file = "\t#{file_path}\n" stack_trace = msg.backtrace_locations.map{|e| "\t#{e}"}.join("\n") str = main + file + stack_trace Config.logger.error str print str if print_to_stdout end |
#module_namespace ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
30 31 32 |
# File 'lib/active_mocker/model_reader.rb', line 30 def module_namespace @module ||= Module.new end |
#parent_class ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
59 60 61 |
# File 'lib/active_mocker/model_reader.rb', line 59 def parent_class @parent_class end |
#parse(model_name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 11 12 |
# File 'lib/active_mocker/model_reader.rb', line 8 def parse(model_name) @model_name = model_name return ParsedProperties.new(klass, parent_class, model_name) if klass false end |
#read_file(m_name = model_name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
63 64 65 |
# File 'lib/active_mocker/model_reader.rb', line 63 def read_file(m_name=model_name) Config.file_reader.read(file_path(m_name)) end |
#sandbox_model ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/active_mocker/model_reader.rb', line 18 def sandbox_model source = RubyParse.new(read_file) if source.has_parent_class? && !Config.model_base_classes.include?(source.parent_class_name) @parent_class = source.parent_class_name end unless source.has_parent_class? raise ModelLoadError::HasNoParentClass.new("#{model_name}") end source.modify_parent_class('ActiveMocker::ActiveRecord::Base') end |