Class: Chino::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/chino/config.rb

Instance Method Summary collapse

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_authorObject



30
31
32
# File 'lib/chino/config.rb', line 30

def bundle_author
  @chinofile.information[:author]
end

#bundle_author_emailObject



34
35
36
# File 'lib/chino/config.rb', line 34

def bundle_author_email
  @chinofile.information[:author_email]
end

#bundle_company_nameObject



38
39
40
# File 'lib/chino/config.rb', line 38

def bundle_company_name
  @chinofile.information[:company_name]
end

#bundle_created_atObject



46
47
48
# File 'lib/chino/config.rb', line 46

def bundle_created_at
  @chinofile.information[:created_at]
end

#bundle_exportsObject



50
51
52
# File 'lib/chino/config.rb', line 50

def bundle_exports
  @bundle_exports ||= convert_export_names
end

#bundle_identifierObject



42
43
44
# File 'lib/chino/config.rb', line 42

def bundle_identifier
  @chinofile.information[:identifier]
end

#bundle_nameObject



22
23
24
# File 'lib/chino/config.rb', line 22

def bundle_name
  @chinofile.information[:name]
end

#bundle_versionObject



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_pathObject



68
69
70
# File 'lib/chino/config.rb', line 68

def common_path
  "#{data_path}/common"
end

#convert_export_namesObject



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_pathObject



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

Returns:

  • (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