Class: Chino::Config
- Inherits:
-
Object
- Object
- Chino::Config
- Defined in:
- lib/chino/config.rb
Instance Method Summary collapse
- #bundle_author ⇒ Object
- #bundle_author_email ⇒ Object
- #bundle_company_name ⇒ Object
- #bundle_created_at ⇒ Object
- #bundle_exports ⇒ Object
- #bundle_identifier ⇒ Object
- #bundle_name ⇒ Object
- #bundle_version ⇒ Object
- #common_erb(file) ⇒ Object
- #common_erb_name(file) ⇒ Object
- #common_path ⇒ Object
- #convert_export_names ⇒ Object
- #data_path ⇒ Object
- #dependency_has_file?(file) ⇒ Boolean
- #erb(file) ⇒ Object
- #erb_name(file) ⇒ Object
- #get_file(file) ⇒ Object
- #get_from_dependency(file) ⇒ Object
-
#initialize(file: nil, _install: false) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(file: nil, _install: false) ⇒ Config
Returns a new instance of Config.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/chino/config.rb', line 8 def initialize(file: nil, _install: false) @path = File.basename(file || '') file ||= 'Chinofile' @dir = file.sub(%r{/?#{@path}$}, '') @chinofile = Chinofile.new(path: @path) do instance_eval File.read(file), file end @dep_puller = DepPuller.new @chinofile.information[:dependencies].each do |dep| @dep_puller.load_dependency!(dep) end end |
Instance Method Details
#bundle_author ⇒ Object
30 31 32 |
# File 'lib/chino/config.rb', line 30 def @chinofile.information[:author] end |
#bundle_author_email ⇒ Object
34 35 36 |
# File 'lib/chino/config.rb', line 34 def @chinofile.information[:author_email] end |
#bundle_company_name ⇒ Object
38 39 40 |
# File 'lib/chino/config.rb', line 38 def bundle_company_name @chinofile.information[:company_name] end |
#bundle_created_at ⇒ Object
46 47 48 |
# File 'lib/chino/config.rb', line 46 def bundle_created_at @chinofile.information[:created_at] end |
#bundle_exports ⇒ Object
50 51 52 |
# File 'lib/chino/config.rb', line 50 def bundle_exports @bundle_exports ||= convert_export_names end |
#bundle_identifier ⇒ Object
42 43 44 |
# File 'lib/chino/config.rb', line 42 def bundle_identifier @chinofile.information[:identifier] end |
#bundle_name ⇒ Object
22 23 24 |
# File 'lib/chino/config.rb', line 22 def bundle_name @chinofile.information[:name] end |
#bundle_version ⇒ Object
26 27 28 |
# File 'lib/chino/config.rb', line 26 def bundle_version @chinofile.information[:version] end |
#common_erb(file) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/chino/config.rb', line 103 def common_erb(file) renderer = ERB.new(File.read(common_erb_name(file))) { string: renderer.result(binding) } end |
#common_erb_name(file) ⇒ Object
95 96 97 |
# File 'lib/chino/config.rb', line 95 def common_erb_name(file) "#{common_path}/#{file}.erb" end |
#common_path ⇒ Object
68 69 70 |
# File 'lib/chino/config.rb', line 68 def common_path "#{data_path}/common" end |
#convert_export_names ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/chino/config.rb', line 54 def convert_export_names result = {} @chinofile.information[:exports].each do |file, file_path| result[file] = file_path.sub(@path, @dir) end result end |
#data_path ⇒ Object
64 65 66 |
# File 'lib/chino/config.rb', line 64 def data_path "#{Gem.loaded_specs['chino'].full_gem_path}/data/chino" end |
#dependency_has_file?(file) ⇒ Boolean
87 88 89 |
# File 'lib/chino/config.rb', line 87 def dependency_has_file?(file) @dep_puller.dependency_has_file?(file) end |
#erb(file) ⇒ Object
110 111 112 113 114 115 |
# File 'lib/chino/config.rb', line 110 def erb(file) renderer = ERB.new(File.read(erb_name(file))) { string: renderer.result(binding) } end |
#erb_name(file) ⇒ Object
99 100 101 |
# File 'lib/chino/config.rb', line 99 def erb_name(file) "#{file}.erb" end |
#get_file(file) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/chino/config.rb', line 72 def get_file(file) return { filename: file.to_s } if File.exist?(file.to_s) return common_erb(file) if File.exist?(common_erb_name(file)) return erb(file) if File.exist?(erb_name(file)) return { filename: "#{common_path}/#{file}" } if File.exist?("#{common_path}/#{file}") return get_from_dependency(file) if dependency_has_file?(file) splits = file.split('/', 2) list = Dir[[splits[0], '**', splits[1]].join('/')] log_list_length(list, splits) return { filename: list.last } unless list.empty? {} end |
#get_from_dependency(file) ⇒ Object
91 92 93 |
# File 'lib/chino/config.rb', line 91 def get_from_dependency(file) @dep_puller.get_from_dependency(file) end |