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.
Instance Attribute Summary collapse
- #file_reader ⇒ Object readonly private
- #model_dir ⇒ Object readonly private
- #model_name ⇒ Object readonly private
Instance Method Summary collapse
- #belongs_to ⇒ Object private
- #class_methods ⇒ Object private
- #class_methods_with_arguments ⇒ Object private
- #collections ⇒ Object private
- #constants ⇒ Object private
- #eval_file ⇒ Object private
- #file_path ⇒ Object private
- #has_and_belongs_to_many ⇒ Object private
- #has_many ⇒ Object private
- #has_one ⇒ Object private
-
#initialize(options = {}) ⇒ ModelReader
constructor
private
A new instance of ModelReader.
- #instance_methods ⇒ Object private
- #instance_methods_with_arguments ⇒ Object private
- #klass ⇒ Object private
- #modules ⇒ Object private
- #parse(model_name) ⇒ Object private
- #primary_key ⇒ Object private
- #process_module_names(names) ⇒ Object private
- #read_file ⇒ Object private
- #real ⇒ Object private
- #relationships ⇒ Object private
- #relationships_types ⇒ Object private
- #scopes ⇒ Object private
- #scopes_with_arguments ⇒ Object private
- #single_relationships ⇒ Object private
- #table_name ⇒ Object private
Constructor Details
#initialize(options = {}) ⇒ ModelReader
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.
Returns a new instance of ModelReader.
7 8 9 10 |
# File 'lib/active_mocker/model_reader.rb', line 7 def initialize(={}) @file_reader = [:file_reader] ||= FileReader @model_dir = [:model_dir] end |
Instance Attribute Details
#file_reader ⇒ 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.
5 6 7 |
# File 'lib/active_mocker/model_reader.rb', line 5 def file_reader @file_reader end |
#model_dir ⇒ 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.
5 6 7 |
# File 'lib/active_mocker/model_reader.rb', line 5 def model_dir @model_dir end |
#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.
5 6 7 |
# File 'lib/active_mocker/model_reader.rb', line 5 def model_name @model_name end |
Instance Method Details
#belongs_to ⇒ 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.
101 102 103 |
# File 'lib/active_mocker/model_reader.rb', line 101 def belongs_to klass.relationships.belongs_to end |
#class_methods ⇒ 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.
55 56 57 |
# File 'lib/active_mocker/model_reader.rb', line 55 def class_methods klass.methods(false) end |
#class_methods_with_arguments ⇒ 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.
69 70 71 72 73 |
# File 'lib/active_mocker/model_reader.rb', line 69 def class_methods_with_arguments class_methods.map do |m| {m => klass.method(m).parameters } end end |
#collections ⇒ 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.
93 94 95 |
# File 'lib/active_mocker/model_reader.rb', line 93 def collections klass.collections.flatten.compact end |
#constants ⇒ 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.
125 126 127 128 129 130 131 132 |
# File 'lib/active_mocker/model_reader.rb', line 125 def constants const = {} klass.constants.each {|c| const[c] = klass.const_get(c)} const = const.reject do |c, v| v.class == Module || v.class == Class end const end |
#eval_file ⇒ 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.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/active_mocker/model_reader.rb', line 23 def eval_file failure = false begin m = Module.new m.module_eval(read_file, file_path) rescue SyntaxError => e Logger.error "ActiveMocker :: Error loading Model: #{model_name} \n \t\t\t\t\t\t\t\t`#{e}` \n" puts "ActiveMocker :: Error loading Model: #{model_name} \n \t\t\t\t\t\t\t\t`#{e}` \n" Logger.error "\t\t\t\t\t\t\t\t #{file_path}\n" puts "\t\t\t\t\t\t\t\t #{file_path}\n" failure = true rescue Exception => e Logger.error "ActiveMocker :: Error loading Model: #{model_name} \n \t\t\t\t\t\t\t\t`#{e}` \n" Logger.error "\t\t\t\t\t\t\t\t #{file_path}\n" failure = true end return m.const_get m.constants.first unless failure return false end |
#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.
51 52 53 |
# File 'lib/active_mocker/model_reader.rb', line 51 def file_path "#{model_dir}/#{model_name}.rb" end |
#has_and_belongs_to_many ⇒ 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.
109 110 111 |
# File 'lib/active_mocker/model_reader.rb', line 109 def has_and_belongs_to_many klass.relationships.has_and_belongs_to_many end |
#has_many ⇒ 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.
113 114 115 |
# File 'lib/active_mocker/model_reader.rb', line 113 def has_many klass.relationships.has_many end |
#has_one ⇒ 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.
105 106 107 |
# File 'lib/active_mocker/model_reader.rb', line 105 def has_one klass.relationships.has_one end |
#instance_methods ⇒ 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.
81 82 83 |
# File 'lib/active_mocker/model_reader.rb', line 81 def instance_methods klass.public_instance_methods(false) end |
#instance_methods_with_arguments ⇒ 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.
75 76 77 78 79 |
# File 'lib/active_mocker/model_reader.rb', line 75 def instance_methods_with_arguments instance_methods.map do |m| {m => klass.new.method(m).parameters } end 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.
19 20 21 |
# File 'lib/active_mocker/model_reader.rb', line 19 def klass @klass ||= eval_file end |
#modules ⇒ 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.
134 135 136 137 |
# File 'lib/active_mocker/model_reader.rb', line 134 def modules {included: process_module_names(klass._included), extended: process_module_names(klass._extended)} 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.
12 13 14 15 16 17 |
# File 'lib/active_mocker/model_reader.rb', line 12 def parse(model_name) @model_name = model_name klass return self unless @klass == false return false end |
#primary_key ⇒ 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.
121 122 123 |
# File 'lib/active_mocker/model_reader.rb', line 121 def primary_key klass.primary_key end |
#process_module_names(names) ⇒ 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.
139 140 141 |
# File 'lib/active_mocker/model_reader.rb', line 139 def process_module_names(names) names.reject { |m| /#{klass.inspect}/ =~ m.name }.map(&:inspect) end |
#read_file ⇒ 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.
47 48 49 |
# File 'lib/active_mocker/model_reader.rb', line 47 def read_file file_reader.read(file_path) end |
#real ⇒ 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.
43 44 45 |
# File 'lib/active_mocker/model_reader.rb', line 43 def real model_name.classify.constantize end |
#relationships ⇒ 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.
89 90 91 |
# File 'lib/active_mocker/model_reader.rb', line 89 def relationships relationships_types.to_h.values.flatten end |
#relationships_types ⇒ 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.
85 86 87 |
# File 'lib/active_mocker/model_reader.rb', line 85 def relationships_types klass.relationships end |
#scopes ⇒ 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 scopes klass.get_named_scopes end |
#scopes_with_arguments ⇒ 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 66 67 |
# File 'lib/active_mocker/model_reader.rb', line 63 def scopes_with_arguments scopes.map do |name, proc| {name => proc.parameters, :proc => proc} end end |
#single_relationships ⇒ 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.
97 98 99 |
# File 'lib/active_mocker/model_reader.rb', line 97 def single_relationships klass.single_relationships.flatten.compact end |
#table_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.
117 118 119 |
# File 'lib/active_mocker/model_reader.rb', line 117 def table_name klass.table_name end |