Class: PixelproSdk::AddPage

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/pixelpro_sdk/add_page.rb

Overview

add or edit files to the rails project

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



9
10
11
# File 'lib/pixelpro_sdk/add_page.rb', line 9

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#add_controller_file(name) ⇒ Object

Add controller files to the rails project
config_ui for the ui page for configration
ins for install the pixel app
info for display dll
event for response pixel pro action event(optional)



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pixelpro_sdk/add_page.rb', line 18

def add_controller_file name
  camelize_name = name.camelize
  create_file "app/controllers/#{name}_controller.rb" do
    "class #{camelize_name}Controller < ApplicationController\n
      skip_before_action :verify_authenticity_token\n
      def config_ui
        # Add your codes here
      end

      def ins
        # Add your codes here
      end

      def info
        # Add your codes here
        render: {success: true, ddl: '0160'}
      end

      def event
        # Add your codes here
      end\nend\n"
  end
end

#add_migrate_fileObject



57
58
59
# File 'lib/pixelpro_sdk/add_page.rb', line 57

def add_migrate_file
  execute :bundle, "rails generate migration CreatePixel pixel_uid:string user_id:integer"
end

#append_route(name) ⇒ Object

Append route to the config/routes file



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pixelpro_sdk/add_page.rb', line 43

def append_route name
  if (::File.exist? "config/routes.rb")
    append_to_file "config/routes.rb" do
      "Rails.application.routes.draw do
        get 'info' => '#{name}#info'
        get 'event' => '#{name}#event'
        get 'config' => '#{name}#config_ui'
        post 'ins' => '#{name}#ins'\nend\n"
    end
  else
    raise "No Routes File Found"
  end
end