class RailsRbs::Generators::RuleGenerator
Public Instance Methods
generate_migrations()
click to toggle source
# File lib/generators/rails_rbs/rule_generator.rb, line 21 def generate_migrations unless default_rule_migrations_exist? if name == 'date_range' migration_template 'date_range_rule_migration.rb', "#{migration_path}/add_date_range_rule.rb" elsif name == 'location' migration_template 'location_rule_migration.rb', "#{migration_path}/add_location_rule.rb" end end end
generate_rule_model()
click to toggle source
# File lib/generators/rails_rbs/rule_generator.rb, line 17 def generate_rule_model invoke("active_record:model", [model_name], migration: false, parent: 'Rule') unless model_exists?(name: model_name) end
inject_rule()
click to toggle source
# File lib/generators/rails_rbs/rule_generator.rb, line 31 def inject_rule default_rules = %w[equality date_range location] # The built in rules of the gem if default_rules.include?(name) content = default_rule_content else content = empty_rule_content end inject_into_class(model_path(name: model_name), "#{name.to_s.camelize}Rule", content) end
Private Instance Methods
default_rule_content()
click to toggle source
# File lib/generators/rails_rbs/rule_generator.rb, line 51 def default_rule_content <<-CONTENT default_rule :#{name} CONTENT end
empty_rule_content()
click to toggle source
# File lib/generators/rails_rbs/rule_generator.rb, line 42 def empty_rule_content <<-CONTENT def follows_rule?(*objects) # Your rule logic here! false end CONTENT end
model_name()
click to toggle source
# File lib/generators/rails_rbs/rule_generator.rb, line 57 def model_name "#{name}_rule" end