Module: ActiveMocker::MockCreator::ClassMethods
- Includes:
- Attributes
- Defined in:
- lib/active_mocker/mock_creator.rb
Instance Method Summary collapse
- #abstract_class ⇒ Object
- #associations ⇒ Object
- #associations_by_class ⇒ Object
- #attribute_names ⇒ Object
- #attributes_with_defaults ⇒ Object
- #mocked_class ⇒ Object
- #table_name ⇒ Object
- #types_hash ⇒ Object
Methods included from Attributes
Instance Method Details
#abstract_class ⇒ Object
205 206 207 |
# File 'lib/active_mocker/mock_creator.rb', line 205 def abstract_class schema_scrapper.abstract_class? end |
#associations ⇒ Object
187 188 189 190 191 |
# File 'lib/active_mocker/mock_creator.rb', line 187 def associations @associations ||= schema_scrapper.associations.to_a.each_with_object({}) do |a, h| h[a.name] = nil end end |
#associations_by_class ⇒ Object
193 194 195 196 197 198 199 |
# File 'lib/active_mocker/mock_creator.rb', line 193 def associations_by_class schema_scrapper.associations.to_a.each_with_object({}) do |r, hash| hash[r.class_name.to_s] ||= {} hash[r.class_name.to_s][r.type] ||= [] hash[r.class_name.to_s][r.type] << r.name end end |
#attribute_names ⇒ Object
201 202 203 |
# File 'lib/active_mocker/mock_creator.rb', line 201 def attribute_names attributes.map { |a| a.name } end |
#attributes_with_defaults ⇒ Object
175 176 177 178 179 |
# File 'lib/active_mocker/mock_creator.rb', line 175 def attributes_with_defaults attributes.each_with_object({}) do |attr, hash| hash[attr.name] = Virtus::Attribute.build(attr.type).coerce(attr.default) end end |
#mocked_class ⇒ Object
213 214 215 |
# File 'lib/active_mocker/mock_creator.rb', line 213 def mocked_class [nested_modules, class_name].compact.reject(&:empty?).join("::") end |
#table_name ⇒ Object
209 210 211 |
# File 'lib/active_mocker/mock_creator.rb', line 209 def table_name schema_scrapper.table_name end |
#types_hash ⇒ Object
181 182 183 184 185 |
# File 'lib/active_mocker/mock_creator.rb', line 181 def types_hash attributes.each_with_object(HashNewStyle.new) do |attr, types| types[attr.name] = "#{attr.type}" end.inspect end |