Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/backflip.rb

Defined Under Namespace

Modules: FriendlyId

Constant Summary collapse

@@attributes =
[]
@@supporting_attributes =
[]
@@migrations =
[]

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



51
52
# File 'lib/backflip.rb', line 51

def method_missing(meth, *args, &block)
end

Class Method Details

.belongs_to(model, *args) ⇒ Object



23
24
25
# File 'lib/backflip.rb', line 23

def self.belongs_to(model, *args)
  @@attributes << "#{model}_id:integer"
end

.friendly_id(name, parameters = {}, *args) ⇒ Object



42
43
44
45
46
# File 'lib/backflip.rb', line 42

def self.friendly_id(name, parameters = {}, *args)
  if parameters.has_key?(:use)
    @@supporting_attributes << "#{parameters[:use].to_s}:string"
  end
end

.generate_migrationsObject



54
55
56
57
58
59
# File 'lib/backflip.rb', line 54

def self.generate_migrations
  puts "rails g model #{self.name.underscore} #{@@attributes.join(' ')} #{@@supporting_attributes.join(' ')} --skip"
  @@migrations.each do |migration|
    puts migration
  end
end

.has_attached_file(file, *args) ⇒ Object



35
36
37
38
39
40
# File 'lib/backflip.rb', line 35

def self.has_attached_file(file, *args)
  @@supporting_attributes << "#{file}_file_name:string"
  @@supporting_attributes << "#{file}_file_size:integer"
  @@supporting_attributes << "#{file}_file_content_type:string"
  @@supporting_attributes << "#{file}_file_updated_at:datetime"
end

.has_many(model, *args) ⇒ Object



27
28
29
# File 'lib/backflip.rb', line 27

def self.has_many(model, *args)
  @@migrations << "rails g migration add_#{self.name.underscore}_to_#{model} #{self.name.underscore}_id:integer"
end

.has_one(model, *args) ⇒ Object



31
32
33
# File 'lib/backflip.rb', line 31

def self.has_one(model, *args)
  @@migrations << "rails g migration add_#{self.name.underscore}_to_#{model} #{self.name.underscore}_id:integer"
end

.method_missing(meth, *args, &block) ⇒ Object

this helps with things like ‘has_friendly_id’, etc. etc.



49
50
# File 'lib/backflip.rb', line 49

def self.method_missing(meth, *args, &block)
end