Class: Omen::Generators::PagesGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/omen/pages/pages_generator.rb

Overview

The least a host needs to see a reading at all: a name for one, a controller, three views and a route. All of it lands in the host and is the host's from then on -- Omen has no opinion about what a reading looks like. It has one about what it takes to draw one, and that is the part nobody should have to learn before their first question.

Constant Summary collapse

VIEWS =

One per action that renders, and the form the other two share.

%w[ index show _form ]
BROADCASTS =

Its own file rather than a line in the initializer, so that deleting these pages deletes everything they asked for. Declared on Omen::Reading and not on the name below it, because a question reaches its reading through the association: what a job is handed, and so what it broadcasts as, is always the gem's own class.

<<~RUBY
  # Refreshes every page showing a reading when its answer lands, which is long after the
  # response that asked for it went out. Written by `rails g omen:pages`, and safe to
  # delete along with the pages it was written for.
  ActiveSupport.on_load(:omen_reading) { broadcasts_refreshes }
RUBY

Instance Method Summary collapse

Instance Method Details

#add_route ⇒ void

This method returns an undefined value.



52
# File 'lib/generators/omen/pages/pages_generator.rb', line 52

def add_route = route "resources :#{plural_name}"

#check_collisions ⇒ void

This method returns an undefined value.

Raised on rather than written over: a host that already calls something Inquiry would otherwise find these pages standing where its own class used to, and quietly. The name is the argument, so omen:pages Consultation is the whole of the fix.



34
# File 'lib/generators/omen/pages/pages_generator.rb', line 34

def check_collisions = class_collisions class_name, "#{plural_name.camelize}Controller"

#copy_controller ⇒ void

This method returns an undefined value.



40
41
42
# File 'lib/generators/omen/pages/pages_generator.rb', line 40

def copy_controller
  template 'controller.rb', "app/controllers/#{plural_name}_controller.rb"
end

#copy_model ⇒ void

This method returns an undefined value.



37
# File 'lib/generators/omen/pages/pages_generator.rb', line 37

def copy_model = template 'model.rb', "app/models/#{singular_name}.rb"

#copy_views ⇒ void

This method returns an undefined value.



45
46
47
48
49
# File 'lib/generators/omen/pages/pages_generator.rb', line 45

def copy_views
  VIEWS.each do |view|
    template "#{view}.html.erb", "app/views/#{plural_name}/#{view}.html.erb"
  end
end

#declare_broadcasts ⇒ void

This method returns an undefined value.



55
56
57
58
59
# File 'lib/generators/omen/pages/pages_generator.rb', line 55

def declare_broadcasts
  return unless turbo?

  create_file 'config/initializers/omen_broadcasts.rb', BROADCASTS
end