Class: Rys::PluginGenerator

Inherits:
Rails::Generators::PluginGenerator
  • Object
show all
Defined in:
lib/generators/rys/plugin/plugin_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ PluginGenerator


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/generators/rys/plugin/plugin_generator.rb', line 47

def initialize(*args)
  super

  if options[:path].present?
    path = options[:path]
    @destination_root_by = :path
  elsif ENV.has_key?('RYS_PLUGINS_PATH')
    path = ENV['RYS_PLUGINS_PATH']
    @destination_root_by = :env
  else
    path = Rails.root.join('rys_plugins').to_s
    FileUtils.mkdir_p(path)
    @destination_root_by = :in_root
  end

  if !Dir.exist?(path)
    raise NameError, "Path '#{path}' does not exist."
  end

  self.destination_root = path
end

Class Method Details

.exit_on_failure?Boolean


43
44
45
# File 'lib/generators/rys/plugin/plugin_generator.rb', line 43

def self.exit_on_failure?
  true
end

Instance Method Details

#append_to_gemfileObject


112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/generators/rys/plugin/plugin_generator.rb', line 112

def append_to_gemfile
  return if options[:skip_git]

  gemfile_local = Rails.root.join('Gemfile.local')

  if !gemfile_local.exist?
    create_file gemfile_local
  end

  case @destination_root_by
  when :path
    path = "'#{destination_root}'"
  when :env
    path = "ENV['RYS_PLUGINS_PATH'] + '/#{app_path}'"
  when :in_root
    path = "'rys_plugins/#{app_path}'"
  end

  entry = "\ngem '#{name}', path: #{path}, group: [:default, :rys]"
  append_file gemfile_local, entry
end

#create_patchesObject


100
101
102
# File 'lib/generators/rys/plugin/plugin_generator.rb', line 100

def create_patches
  directory 'patches'
end

#create_root_filesObject


89
90
91
92
93
94
95
96
97
98
# File 'lib/generators/rys/plugin/plugin_generator.rb', line 89

def create_root_files
  build(:readme)
  build(:rakefile)
  build(:gemspec)
  build(:gitignore) unless options[:skip_git]
  build(:gemfile)
  directory 'db'
  template '.gitlab-ci.yml'
  template '.rspec'
end

#create_test_filesObject


104
105
106
# File 'lib/generators/rys/plugin/plugin_generator.rb', line 104

def create_test_files
  directory 'spec'
end

#create_view_exampleObject


108
109
110
# File 'lib/generators/rys/plugin/plugin_generator.rb', line 108

def create_view_example
  template 'app/views/issues/%name%/_view_issues_show_details_bottom.html.erb'
end

#full?Boolean


73
74
75
# File 'lib/generators/rys/plugin/plugin_generator.rb', line 73

def full?
  true
end

#get_builder_classObject


85
86
87
# File 'lib/generators/rys/plugin/plugin_generator.rb', line 85

def get_builder_class
  PluginBuilder
end

#informationsObject


142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/generators/rys/plugin/plugin_generator.rb', line 142

def informations
  shell.say_status 'INFO', ''
  shell.say_status 'INFO', ''
  shell.say_status 'INFO', "Plugin was created in: #{destination_root}"
  shell.say_status 'INFO', "To set local path: bundle config local.#{name} #{destination_root}"

  one_liners = Rys::Engine.root.join('config/one_liners.txt')
  if one_liners.exist?
    line = one_liners.readlines.sample
    shell.say_status 'INFO', ''
    shell.say_status 'INFO', %{"#{line.chomp}"}
  end
end

#init_gitObject


134
135
136
137
138
139
140
# File 'lib/generators/rys/plugin/plugin_generator.rb', line 134

def init_git
  return if options[:skip_git]

  # Capture for less verbose
  run 'git init', capture: true
  git add: '.'
end

#mountable?Boolean


69
70
71
# File 'lib/generators/rys/plugin/plugin_generator.rb', line 69

def mountable?
  false
end

#name_pluralizeObject


81
82
83
# File 'lib/generators/rys/plugin/plugin_generator.rb', line 81

def name_pluralize
  @name_pluralize ||= name.pluralize
end

#with_dummy_app?Boolean


77
78
79
# File 'lib/generators/rys/plugin/plugin_generator.rb', line 77

def with_dummy_app?
  false
end