Class: Bootprint::Diff

Inherits:
Object
  • Object
show all
Defined in:
lib/bootprint/diff.rb

Defined Under Namespace

Classes: Change

Constant Summary collapse

IGNORED_PATHS =
%w[generated_at bootprint_version environment.name].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(local, target, allowed_paths: []) ⇒ Diff

Returns a new instance of Diff.



15
16
17
18
19
# File 'lib/bootprint/diff.rb', line 15

def initialize(local, target, allowed_paths: [])
  @local = local.is_a?(Snapshot) ? local.data : local
  @target = target.is_a?(Snapshot) ? target.data : target
  @allowed_paths = allowed_paths
end

Instance Attribute Details

#allowed_pathsObject (readonly)

Returns the value of attribute allowed_paths.



13
14
15
# File 'lib/bootprint/diff.rb', line 13

def allowed_paths
  @allowed_paths
end

#localObject (readonly)

Returns the value of attribute local.



13
14
15
# File 'lib/bootprint/diff.rb', line 13

def local
  @local
end

#targetObject (readonly)

Returns the value of attribute target.



13
14
15
# File 'lib/bootprint/diff.rb', line 13

def target
  @target
end

Instance Method Details

#allowed?(path) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/bootprint/diff.rb', line 25

def allowed?(path)
  allowed_paths.any? { |pattern| File.fnmatch?(pattern, path, File::FNM_PATHNAME | File::FNM_EXTGLOB) }
end

#changesObject



21
22
23
# File 'lib/bootprint/diff.rb', line 21

def changes
  @changes ||= compare(local, target).reject { |change| ignored?(change.path) }
end