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
- #get_non_active_record_parent_class(source) ⇒ Object private
- #has_no_parent_class!(source) ⇒ 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.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/active_mocker/model_reader.rb', line 37 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.
70 71 72 |
# File 'lib/active_mocker/model_reader.rb', line 70 def file_path(m_name=model_name) "#{Config.model_dir}/#{m_name}.rb" end |
#get_non_active_record_parent_class(source) ⇒ 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.
25 26 27 |
# File 'lib/active_mocker/model_reader.rb', line 25 def get_non_active_record_parent_class(source) @parent_class = source.parent_class_name unless Config.model_base_classes.include?(source.parent_class_name) end |
#has_no_parent_class!(source) ⇒ 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.
29 30 31 |
# File 'lib/active_mocker/model_reader.rb', line 29 def has_no_parent_class!(source) raise ModelLoadError::HasNoParentClass.new("#{model_name}") unless source.has_parent_class? 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.
53 54 55 56 57 58 59 60 |
# File 'lib/active_mocker/model_reader.rb', line 53 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.
33 34 35 |
# File 'lib/active_mocker/model_reader.rb', line 33 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.
62 63 64 |
# File 'lib/active_mocker/model_reader.rb', line 62 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.
66 67 68 |
# File 'lib/active_mocker/model_reader.rb', line 66 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 |
# File 'lib/active_mocker/model_reader.rb', line 18 def sandbox_model source = RubyParse.new(read_file) has_no_parent_class!(source) get_non_active_record_parent_class(source) source.modify_parent_class('ActiveMocker::ActiveRecord::Base') end |