Create yaml class and add class methods. Move specs to appropriate folder. Fix method calls. Move flags spec to appropriate folder for rubocop

This commit is contained in:
Alex 2017-11-01 20:12:47 -04:00
parent 7aec4fda94
commit 1cd2029126
8 changed files with 28 additions and 37 deletions

View file

@ -12,14 +12,6 @@ AllCops:
# Preferred codebase style ---------------------------------------------
RSpec/DescribeClass:
Exclude:
- 'spec/yaml_spec.rb'
RSpec/FilePath:
Exclude:
- 'spec/flags_spec.rb'
Layout/ExtraSpacing:
AllowForAlignment: true

View file

@ -5,6 +5,6 @@ require 'rainbow/ext/string'
require 'colorls/core'
require 'colorls/flags'
require 'colorls/load_from_yaml'
require 'colorls/yaml'
require 'colorls/monkeys'
require 'colorls/git'

View file

@ -134,10 +134,10 @@ module ColorLS
end
def init_icons
@files = ColorLS.load_from_yaml('files.yaml')
@file_aliases = ColorLS.load_from_yaml('file_aliases.yaml', true)
@folders = ColorLS.load_from_yaml('folders.yaml')
@folder_aliases = ColorLS.load_from_yaml('folder_aliases.yaml', true)
@files = ColorLS::Yaml.load_from_yaml('files.yaml')
@file_aliases = ColorLS::Yaml.load_from_yaml('file_aliases.yaml', true)
@folders = ColorLS::Yaml.load_from_yaml('folders.yaml')
@folder_aliases = ColorLS::Yaml.load_from_yaml('folder_aliases.yaml', true)
@file_keys = @files.keys
@file_aliase_keys = @file_aliases.keys

View file

@ -142,7 +142,7 @@ EXAMPLES
def set_color_opts
color_scheme_file = @light_colors ? 'light_colors.yaml' : 'dark_colors.yaml'
@opts[:colors] = ColorLS.load_from_yaml(color_scheme_file, true)
@opts[:colors] = ColorLS::Yaml.load_from_yaml(color_scheme_file, true)
end
end
end

View file

@ -1,22 +0,0 @@
module ColorLS
def self.load_from_yaml(filename, aliase=false)
user_config_filepath = File.join(Dir.home, ".config/colorls/#{filename}")
filepath = File.join(File.dirname(__FILE__),"../yaml/#{filename}")
yaml = read_file(filepath)
if File.exist?(user_config_filepath)
user_config_yaml = read_file(user_config_filepath)
yaml = yaml.merge(user_config_yaml)
end
return yaml unless aliase
yaml
.to_a
.map! { |k, v| [k, v.to_sym] }
.to_h
end
def self.read_file(filepath)
YAML.safe_load(File.read(filepath)).symbolize_keys
end
end

21
lib/colorls/yaml.rb Normal file
View file

@ -0,0 +1,21 @@
module ColorLS
class Yaml
def self.load_from_yaml(filename, aliase=false)
user_config_filepath = File.join(Dir.home, ".config/colorls/#{filename}")
filepath = File.join(File.dirname(__FILE__),"../yaml/#{filename}")
yaml = read_file(filepath)
if File.exist?(user_config_filepath)
user_config_yaml = read_file(user_config_filepath)
yaml = yaml.merge(user_config_yaml)
end
return yaml unless aliase
yaml.to_a.map! { |k, v| [k, v.to_sym] }.to_h
end
def self.read_file(filepath)
YAML.safe_load(File.read(filepath)).symbolize_keys
end
end
end

View file

@ -1,6 +1,6 @@
require 'spec_helper'
RSpec.describe 'Yaml files' do
RSpec.describe ColorLS::Yaml do
::FILENAMES = {
file_aliases: :value,
folder_aliases: :value,