Module: ActiveMocker::MockCreator::ClassMethods

Includes:
Attributes
Defined in:
lib/active_mocker/mock_creator.rb

Instance Method Summary collapse

Methods included from Attributes

#attributes

Instance Method Details

#abstract_classObject



205
206
207
# File 'lib/active_mocker/mock_creator.rb', line 205

def abstract_class
  schema_scrapper.abstract_class?
end

#associationsObject



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_classObject



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_namesObject



201
202
203
# File 'lib/active_mocker/mock_creator.rb', line 201

def attribute_names
  attributes.map { |a| a.name }
end

#attributes_with_defaultsObject



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_classObject



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_nameObject



209
210
211
# File 'lib/active_mocker/mock_creator.rb', line 209

def table_name
  schema_scrapper.table_name
end

#types_hashObject



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