Class: Fae::BaseGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/fae/base_generator.rb

Constant Summary collapse

@@attributes_flat =
[]
@@attribute_names =
[]
@@association_names =
[]
@@attachments =
[]
@@graphql_attributes =
[]
@@has_position =
false
@@display_field =
''

Instance Method Summary collapse

Instance Method Details

#check_template_supportObject



17
18
19
20
# File 'lib/generators/fae/base_generator.rb', line 17

def check_template_support
  supported_templates = ['slim']
  raise "Fae::UnsupportedTemplate: the template engine you defined isn't supported" unless supported_templates.include?(options.template)
end

#set_globalsObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/generators/fae/base_generator.rb', line 22

def set_globals
  if attributes.present?
    attributes.each do |arg|
      # :image and :file args get used to generate association defs and form elements
      # we don't want them in attributes_flat or attribute_names as they are not real model generator field options
      if is_attachment(arg)
        @@attachments << arg
      else
        @@attributes_flat << "#{arg.name}:#{arg.type}" + (arg.has_index? ? ":index" : "")
      end

      if options.polymorphic
        @@attributes_flat << "#{polymorphic_name}:references{polymorphic}"
      end

      if is_association(arg)
        @@association_names << arg.name.gsub(/_id$/, '')
      elsif !is_attachment(arg)
        @@attribute_names << arg.name
      end
      @@has_position = true if arg.name === 'position'

      @@graphql_attributes << graphql_object(arg)
    end

    @@attributes_flat = @@attributes_flat.uniq.join(' ')
    @@association_names.uniq!
    @@attribute_names.uniq!
    @@attachments.uniq!
    @@graphql_attributes.uniq!
  end
end