Module: ActiveMocker::MockCreator::ClassMethods

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

Instance Method Summary collapse

Methods included from Attributes

#attributes, #enums, #process_attr

Instance Method Details

#abstract_classObject



40
41
42
# File 'lib/active_mocker/mock_creator/class_methods.rb', line 40

def abstract_class
  schema_scrapper.abstract_class?
end

#associationsObject



22
23
24
25
26
# File 'lib/active_mocker/mock_creator/class_methods.rb', line 22

def associations
  @associations ||= schema_scrapper.associations.to_a.each_with_object({}) do |a, h|
    h[a.name] = nil
  end
end

#associations_by_classObject



28
29
30
31
32
33
34
# File 'lib/active_mocker/mock_creator/class_methods.rb', line 28

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



36
37
38
# File 'lib/active_mocker/mock_creator/class_methods.rb', line 36

def attribute_names
  attributes.map(&:name)
end

#attributes_with_defaultsObject



9
10
11
12
13
14
# File 'lib/active_mocker/mock_creator/class_methods.rb', line 9

def attributes_with_defaults
  types_hash
  attributes.each_with_object({}) do |attr, hash|
    hash[attr.name] = attr.default
  end
end

#mocked_classObject



48
49
50
# File 'lib/active_mocker/mock_creator/class_methods.rb', line 48

def mocked_class
  [nested_modules, class_name].compact.reject(&:empty?).join("::")
end

#table_nameObject



44
45
46
# File 'lib/active_mocker/mock_creator/class_methods.rb', line 44

def table_name
  schema_scrapper.table_name
end

#types_hashObject



16
17
18
19
20
# File 'lib/active_mocker/mock_creator/class_methods.rb', line 16

def types_hash
  @types_hash ||= attributes.each_with_object(HashNewStyle.new) do |attr, types|
    types[attr.name] = attr.type.to_s
  end.inspect
end