Module: EnumExporter

Defined in:
lib/enum_exporter.rb,
lib/enum_exporter/railtie.rb,
lib/enum_exporter/version.rb

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

VERSION =
'0.1.2'

Class Method Summary collapse

Class Method Details

.enumsObject



13
14
15
16
17
18
19
20
21
# File 'lib/enum_exporter.rb', line 13

def enums
  enums = []
  models.each do |model|
    if !model.defined_enums.empty?
      enums << {model.to_s => model.defined_enums}
    end
  end
  enums
end

.jsonObject



9
10
11
# File 'lib/enum_exporter.rb', line 9

def json
  enums.to_json
end

.modelsObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/enum_exporter.rb', line 23

def models
  return [] unless defined?(Rails)

  Rails.application.eager_load!

  descendants = []
  descendants |= ApplicationRecord.descendants if defined?(ApplicationRecord)
  descendants |= ActiveRecord::Base.descendants if defined?(ActiveRecord)

  descendants.sort_by {|m| m.to_s}
end

.yamlObject



5
6
7
# File 'lib/enum_exporter.rb', line 5

def yaml
  enums.to_yaml
end