Module: Flatito

Defined in:
lib/flatito.rb,
lib/flatito/utils.rb,
lib/flatito/config.rb,
lib/flatito/finder.rb,
lib/flatito/version.rb,
lib/flatito/renderer.rb,
lib/flatito/diff_parser.rb,
lib/flatito/diff_source.rb,
lib/flatito/print_items.rb,
lib/flatito/flatten_yaml.rb,
lib/flatito/json_scanner.rb,
lib/flatito/tree_iterator.rb,
lib/flatito/regex_from_search.rb,
lib/flatito/yaml_with_line_number.rb

Defined Under Namespace

Modules: Config, DiffSource, RegexFromSearch, Utils, YAMLWithLineNumber Classes: Base, DiffParser, Finder, FlattenYaml, JsonScanner, PrintItems, Renderer, TreeIterator

Constant Summary collapse

DEFAULT_DIFF_EXTENSIONS =
%w[.json .yml .yaml].freeze
VERSION =
"0.1.5"

Class Method Summary collapse

Class Method Details

.flat_content(content, options = {}) ⇒ Object



29
30
31
32
# File 'lib/flatito.rb', line 29

def flat_content(content, options = {})
  items = FlattenYaml.items_from_content(content)
  PrintItems.new(options[:search], options[:search_value], case_sensitive: options[:case_sensitive]).print(items) || false
end

.from_diff(diff_content, options = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/flatito.rb', line 34

def from_diff(diff_content, options = {})
  side = (options[:side] || :both).to_sym
  extensions = normalize_extensions(options[:extensions])
  printer = PrintItems.new(options[:search], options[:search_value],
                           case_sensitive: options[:case_sensitive])

  matched = false
  DiffParser.parse(diff_content).each do |file|
    next unless extension_match?(file.path, extensions)

    before, after = DiffSource.contents_for(file)
    items = collect_items(file, before, after, side)
    next if items.empty?

    matched = true if printer.print(items, file.path)
  end
  matched
rescue Interrupt
  warn "\nInterrupted"
  nil
end

.search(paths, options = {}) ⇒ Object



22
23
24
25
26
27
# File 'lib/flatito.rb', line 22

def search(paths, options = {})
  Finder.new(paths, options).call
rescue Interrupt
  warn "\nInterrupted"
  nil
end