12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/generators/sql_view/view/view_generator.rb', line 12
def create_everything
create_file "app/sql_views/#{file_name}_view.rb", <<-FILE
class #{class_name}View < SQLView::Model
#{top_code}
schema ->#{schema_code}
extend_model_with do
# sample how you can extend it, similar to regular AR model
#
# include SomeConcern
#
# belongs_to :user
# has_many :posts
#
# scope :ordered, -> { order(:created_at) }
# scope :by_role, ->(role) { where(role: role) }
end
end
FILE
create_file "db/migrate/#{self.class.next_migration_number("db/migrate")}_create_#{file_name}_view.rb", <<-FILE
class #{migration_class_name} < #{activerecord_migration_class}
def up
#{class_name}View.sql_view.up
end
def down
#{class_name}View.sql_view.down
end
end
FILE
end
|