Class: RailsEngineToolkit::Project
- Inherits:
-
Object
- Object
- RailsEngineToolkit::Project
- Defined in:
- lib/rails_engine_toolkit/project.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #broken_engine_references ⇒ Object
- #config ⇒ Object
- #config_file ⇒ Object
- #engine_exists?(engine_name) ⇒ Boolean
- #engine_path(engine_name) ⇒ Object
- #gemfile ⇒ Object
-
#initialize(root = Pathname.pwd) ⇒ Project
constructor
A new instance of Project.
- #matching_root_migrations_for_engine(engine_name) ⇒ Object
- #remove_broken_engine_references!(engine_names) ⇒ Object
- #root_migrations_dir ⇒ Object
- #route_inspector ⇒ Object
- #routes_file ⇒ Object
- #validate_root! ⇒ Object
Constructor Details
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
5 6 7 |
# File 'lib/rails_engine_toolkit/project.rb', line 5 def root @root end |
Instance Method Details
#broken_engine_references ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rails_engine_toolkit/project.rb', line 34 def broken_engine_references return [] unless gemfile.file? gemfile.read.lines.filter_map do |line| match = line.match(%r{path:\s*["']engines/([^"']+)["']}) next unless match engine_name = match[1] engine_name unless engine_exists?(engine_name) end.uniq end |
#config ⇒ Object
17 18 19 |
# File 'lib/rails_engine_toolkit/project.rb', line 17 def config @config ||= Config.load(root) end |
#config_file ⇒ Object
24 |
# File 'lib/rails_engine_toolkit/project.rb', line 24 def config_file = root.join(Config::DEFAULT_PATH) |
#engine_exists?(engine_name) ⇒ Boolean
30 31 32 |
# File 'lib/rails_engine_toolkit/project.rb', line 30 def engine_exists?(engine_name) engine_path(engine_name).directory? end |
#engine_path(engine_name) ⇒ Object
26 27 28 |
# File 'lib/rails_engine_toolkit/project.rb', line 26 def engine_path(engine_name) root.join("engines/#{engine_name}") end |
#gemfile ⇒ Object
21 |
# File 'lib/rails_engine_toolkit/project.rb', line 21 def gemfile = root.join('Gemfile') |
#matching_root_migrations_for_engine(engine_name) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/rails_engine_toolkit/project.rb', line 62 def matching_root_migrations_for_engine(engine_name) return [] unless root_migrations_dir.directory? engine_class = Utils.classify(engine_name) root_migrations_dir.glob('*.rb').select do |file| file.read.include?(engine_class) || file.read.include?("#{engine_name}_") end end |
#remove_broken_engine_references!(engine_names) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/rails_engine_toolkit/project.rb', line 46 def remove_broken_engine_references!(engine_names) return if engine_names.empty? content = gemfile.read engine_names.each do |name| content = content.lines.grep_v(%r{path:\s*["']engines/#{Regexp.escape(name)}["']}).join end gemfile.write(content) end |
#root_migrations_dir ⇒ Object
23 |
# File 'lib/rails_engine_toolkit/project.rb', line 23 def root_migrations_dir = root.join('db/migrate') |
#route_inspector ⇒ Object
56 57 58 59 60 |
# File 'lib/rails_engine_toolkit/project.rb', line 56 def route_inspector return nil unless routes_file.file? RouteInspector.new(routes_file.read) end |
#routes_file ⇒ Object
22 |
# File 'lib/rails_engine_toolkit/project.rb', line 22 def routes_file = root.join('config/routes.rb') |
#validate_root! ⇒ Object
11 12 13 14 15 |
# File 'lib/rails_engine_toolkit/project.rb', line 11 def validate_root! raise ValidationError, 'You must run this command from the Rails project root.' unless gemfile.file? true end |