class Abyme::Generators::ModelGenerator
Public Instance Methods
insert_abyme_config_in_model()
click to toggle source
# File lib/generators/abyme/model/model_generator.rb, line 11 def insert_abyme_config_in_model insert_abyme_configuration unless model_configured? insert_abymized_association end
Private Instance Methods
assign_names!(name)
click to toggle source
Calls superclass method
# File lib/generators/abyme/model/model_generator.rb, line 36 def assign_names!(name) # Remove abyme namespace name.gsub!(/abyme_/, "") super end
inject_abyme_attributes()
click to toggle source
# File lib/generators/abyme/model/model_generator.rb, line 50 def inject_abyme_attributes return '' if attributes.empty? return ", permit: :all_attributes" if attributes.map(&:name).include?('all_attributes') ", permit: [#{symbolized_attributes.join(', ')}]" end
insert_abyme_configuration()
click to toggle source
# File lib/generators/abyme/model/model_generator.rb, line 24 def insert_abyme_configuration if namespaced_model model = namespaced_model[2] namespace = namespaced_model[1] insert_into_file(model_file_path, after: /(^\s*class.*#{Regexp.quote(model)}.*$)/) do "\n include Abyme::Model\n" end else inject_into_class(model_file_path, class_name, " include Abyme::Model\n\n") end end
insert_abymized_association()
click to toggle source
# File lib/generators/abyme/model/model_generator.rb, line 18 def insert_abymized_association insert_into_file(model_file_path, after: /(^\s*(has_many|has_one|belongs_to)\s*:#{Regexp.quote(association)}.*$)/ ) do "\n#{insert_indentation}abymize :#{association}#{inject_abyme_attributes}\n" end end
insert_indentation()
click to toggle source
# File lib/generators/abyme/model/model_generator.rb, line 65 def insert_indentation namespaced_model ? " " : " " end
model_configured?()
click to toggle source
# File lib/generators/abyme/model/model_generator.rb, line 61 def model_configured? File.read(model_file_path).match?(/Abyme::Model/) end
model_file_path()
click to toggle source
# File lib/generators/abyme/model/model_generator.rb, line 46 def model_file_path Rails.root.join('app', 'models', "#{name}.rb") end
namespaced_model()
click to toggle source
# File lib/generators/abyme/model/model_generator.rb, line 42 def namespaced_model class_name.match(/(.*)[\/::](.*)/) end
symbolized_attributes()
click to toggle source
# File lib/generators/abyme/model/model_generator.rb, line 57 def symbolized_attributes attributes.map {|attr| ":#{attr.name.downcase}" } end