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
# File 'lib/chino/config.rb', line 8

def initialize(file: nil, install: false)
  path = File.basename(file || '')
  file ||= 'Chinofile'
  @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



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

def bundle_author
  @chinofile.information[:author]
end

#bundle_author_emailObject



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

def bundle_author_email
  @chinofile.information[:author_email]
end

#bundle_company_nameObject



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

def bundle_company_name
  @chinofile.information[:company_name]
end

#bundle_created_atObject



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

def bundle_created_at
  @chinofile.information[:created_at]
end

#bundle_exportsObject



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

def bundle_exports
  @chinofile.information[:exports]
end

#bundle_identifierObject



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

def bundle_identifier
  @chinofile.information[:identifier]
end

#bundle_nameObject



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

def bundle_name
  @chinofile.information[:name]
end

#bundle_versionObject



25
26
27
# File 'lib/chino/config.rb', line 25

def bundle_version
  @chinofile.information[:version]
end

#common_pathObject



57
58
59
# File 'lib/chino/config.rb', line 57

def common_path
  "#{data_path}/common"
end

#data_pathObject



53
54
55
# File 'lib/chino/config.rb', line 53

def data_path
  "#{Gem.loaded_specs['chino'].full_gem_path}/data/chino"
end

#dependency_has_file?(file) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/chino/config.rb', line 70

def dependency_has_file?(file)
  @dep_puller.dependency_has_file?(file)
end

#erb(file) ⇒ Object



82
83
84
85
86
87
# File 'lib/chino/config.rb', line 82

def erb(file)
  renderer = ERB.new(File.read(erb_name(file)))
  {
    string: renderer.result(binding)
  }
end

#erb_name(file) ⇒ Object



78
79
80
# File 'lib/chino/config.rb', line 78

def erb_name(file)
  "#{common_path}/#{file}.erb"
end

#get_file(file) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/chino/config.rb', line 61

def get_file(file)
  return { filename: file.to_s } if File.exist?(file.to_s)
  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)

  {}
end

#get_from_dependency(file) ⇒ Object



74
75
76
# File 'lib/chino/config.rb', line 74

def get_from_dependency(file)
  @dep_puller.get_from_dependency(file)
end