Class: PryRailsDiffRoutes::RoutesDiffProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/pry_rails_diff_routes/routes_diff_processor.rb

Instance Method Summary collapse

Constructor Details

#initialize(previous_routes, current_routes, display_mode) ⇒ RoutesDiffProcessor

Returns a new instance of RoutesDiffProcessor.



7
8
9
10
11
12
13
# File 'lib/pry_rails_diff_routes/routes_diff_processor.rb', line 7

def initialize(previous_routes, current_routes, display_mode)
  @previous = previous_routes
  @current = current_routes
  @mode = display_mode.zero? ? DiffRoutes::A_MODE : display_mode

  @removed, @modified, @new = process_diff if changed?
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/pry_rails_diff_routes/routes_diff_processor.rb', line 15

def changed?
  @previous != @current
end

#display_modifiedObject



56
57
58
# File 'lib/pry_rails_diff_routes/routes_diff_processor.rb', line 56

def display_modified
  ModifiedRoutesFormatter.new(@modified) if show_modified?
end

#display_newObject



64
65
66
# File 'lib/pry_rails_diff_routes/routes_diff_processor.rb', line 64

def display_new
  NewRoutesFormatter.new(@new) if show_new?
end

#display_removedObject



48
49
50
# File 'lib/pry_rails_diff_routes/routes_diff_processor.rb', line 48

def display_removed
  RemovedRoutesFormatter.new(@removed) if show_removed?
end

#process_diffObject



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

def process_diff
  inner_join = @previous & @current
  removed_routes = @previous - inner_join
  new_routes = @current - inner_join

  modified_routes = {}

  removed_routes.reject! do |r_route|
    catch :modified do
      new_routes.each do |n_route|
        if n_route.verb == r_route.verb && n_route.path == r_route.path
          modified_routes[r_route] = n_route
          new_routes.reject!{|route| route == n_route }

          throw :modified, true
        end
      end

      false
    end
  end

  [removed_routes, modified_routes, new_routes]
end

#show_modified?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/pry_rails_diff_routes/routes_diff_processor.rb', line 52

def show_modified?
  (@mode & DiffRoutes::M_MODE == DiffRoutes::M_MODE) && @modified.any?
end

#show_new?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/pry_rails_diff_routes/routes_diff_processor.rb', line 60

def show_new?
  (@mode & DiffRoutes::N_MODE == DiffRoutes::N_MODE) && @new.any?
end

#show_removed?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/pry_rails_diff_routes/routes_diff_processor.rb', line 44

def show_removed?
  (@mode & DiffRoutes::R_MODE == DiffRoutes::R_MODE) && @removed.any?
end

#to_sObject



68
69
70
# File 'lib/pry_rails_diff_routes/routes_diff_processor.rb', line 68

def to_s
  "#{display_removed}#{display_modified}#{display_new}"
end