Class: ActiveMocker::ModelReader::ParsedProperties Private
- Inherits:
-
Object
- Object
- ActiveMocker::ModelReader::ParsedProperties
- 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
- #klass ⇒ Object readonly private
- #model_name ⇒ Object readonly private
- #parent_class ⇒ Object readonly private
Instance Method Summary collapse
- #abstract_class ⇒ Object private
- #belongs_to ⇒ Object private
- #class_methods ⇒ Object private
- #class_methods_with_arguments ⇒ Object private
- #constants ⇒ Object private
- #has_and_belongs_to_many ⇒ Object private
- #has_many ⇒ Object private
- #has_one ⇒ Object private
-
#initialize(klass, parent_class, model_name) ⇒ ParsedProperties
constructor
private
A new instance of ParsedProperties.
- #instance_methods ⇒ Object private
- #instance_methods_with_arguments ⇒ Object private
- #modules ⇒ Object private
- #primary_key ⇒ Object private
- #process_module_names(names) ⇒ Object private
- #rails_version ⇒ Object private
- #scopes ⇒ Object private
- #scopes_with_arguments ⇒ Object private
- #select_only_current_class(type) ⇒ Object private
- #table_name ⇒ Object private
Constructor Details
#initialize(klass, parent_class, model_name) ⇒ ParsedProperties
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 ParsedProperties.
75 76 77 78 79 |
# File 'lib/active_mocker/model_reader.rb', line 75 def initialize(klass, parent_class, model_name) @klass = klass @parent_class = parent_class @model_name = model_name end |
Instance Attribute Details
#klass ⇒ 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.
73 74 75 |
# File 'lib/active_mocker/model_reader.rb', line 73 def klass @klass 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.
73 74 75 |
# File 'lib/active_mocker/model_reader.rb', line 73 def model_name @model_name end |
#parent_class ⇒ 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.
73 74 75 |
# File 'lib/active_mocker/model_reader.rb', line 73 def parent_class @parent_class end |
Instance Method Details
#abstract_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.
89 90 91 |
# File 'lib/active_mocker/model_reader.rb', line 89 def abstract_class rails_version.try(:abstract_class) end |
#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.
99 100 101 |
# File 'lib/active_mocker/model_reader.rb', line 99 def belongs_to select_only_current_class(: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.
125 126 127 |
# File 'lib/active_mocker/model_reader.rb', line 125 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.
139 140 141 142 143 |
# File 'lib/active_mocker/model_reader.rb', line 139 def class_methods_with_arguments class_methods.map do |m| {m => klass.method(m).parameters} end 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.
157 158 159 160 161 162 163 164 |
# File 'lib/active_mocker/model_reader.rb', line 157 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 |
#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.
107 108 109 |
# File 'lib/active_mocker/model_reader.rb', line 107 def has_and_belongs_to_many select_only_current_class(: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.
111 112 113 |
# File 'lib/active_mocker/model_reader.rb', line 111 def has_many select_only_current_class(: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.
103 104 105 |
# File 'lib/active_mocker/model_reader.rb', line 103 def has_one select_only_current_class(: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.
151 152 153 154 155 |
# File 'lib/active_mocker/model_reader.rb', line 151 def instance_methods methods = klass.public_instance_methods(false) methods << klass.superclass.public_instance_methods(false) if klass.superclass != ActiveRecord::Base methods.flatten 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.
145 146 147 148 149 |
# File 'lib/active_mocker/model_reader.rb', line 145 def instance_methods_with_arguments instance_methods.map do |m| {m => klass.instance_method(m).parameters} end 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.
166 167 168 169 |
# File 'lib/active_mocker/model_reader.rb', line 166 def modules {included: process_module_names(klass._included), extended: process_module_names(klass._extended)} 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 rails_version.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.
171 172 173 |
# File 'lib/active_mocker/model_reader.rb', line 171 def process_module_names(names) names.reject { |m| /#{klass.inspect}/ =~ m.name }.map(&:inspect) end |
#rails_version ⇒ 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 84 85 86 87 |
# File 'lib/active_mocker/model_reader.rb', line 81 def rails_version begin @rails_version ||= model_name.classify.constantize rescue raise ModelLoadError::LoadingModelInRails.new($!, model_name) end 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.
129 130 131 |
# File 'lib/active_mocker/model_reader.rb', line 129 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.
133 134 135 136 137 |
# File 'lib/active_mocker/model_reader.rb', line 133 def scopes_with_arguments scopes.map do |name, proc| {name => proc.parameters, :proc => proc} end end |
#select_only_current_class(type) ⇒ 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 96 97 |
# File 'lib/active_mocker/model_reader.rb', line 93 def select_only_current_class(type) rails_version.reflect_on_all_associations(type).select do |a| klass.relationships.send(type).map(&:name).include?(a.name) end 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.
115 116 117 118 119 |
# File 'lib/active_mocker/model_reader.rb', line 115 def table_name return rails_version.try(:table_name) if rails_version.try(:superclass).try(:name) == 'ActiveRecord::Base' return nil if rails_version.superclass.try(:table_name) == rails_version.try(:table_name) rails_version.try(:table_name) end |