Class: Yuzu::Core::Config

Inherits:
Object show all
Includes:
Helpers
Defined in:
lib/yuzu/core/config.rb

Constant Summary collapse

OPTIONAL_GEMS =
['compass']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_hash, service_override = nil, parsed_options = []) ⇒ Config

Returns a new instance of Config.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/yuzu/core/config.rb', line 12

def initialize(config_hash, service_override=nil, parsed_options=[])
  @config_hash = config_hash
  @service = service_override || config_hash['connection']
  @options = parsed_options

  # Create a method for every top-level key in the configuration dictionary.
  (class << self; self; end).class_eval do
    config_hash.each_pair do |key, value|
      instance_variable = "@#{key}".to_sym

      define_method key do
        if instance_variable_get(instance_variable).nil?
          instance_variable_set(instance_variable, value)
        end
        instance_variable_get(instance_variable)
      end

      define_method "set_#{key}" do |other|
        instance_variable_set(instance_variable, other)
      end

    end
  end

  check_for_gems
end

Instance Attribute Details

#config_hashObject (readonly)

Returns the value of attribute config_hash.



10
11
12
# File 'lib/yuzu/core/config.rb', line 10

def config_hash
  @config_hash
end

#serviceObject (readonly)

Returns the value of attribute service.



10
11
12
# File 'lib/yuzu/core/config.rb', line 10

def service
  @service
end

Instance Method Details

#asset?(path) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/yuzu/core/config.rb', line 84

def asset?(path)
  check_extension(path.extension, asset_extensions)
end

#can_index_folder?(path) ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
96
97
98
99
100
101
# File 'lib/yuzu/core/config.rb', line 93

def can_index_folder?(path)
  absolute_no_index_paths = (no_index_folders + folder_blacklist + system_folders).collect {|p| Path.new(p)}

  tr = false
  absolute_no_index_paths.each do |folder|
    tr ||= folder.contains?(path)
  end
  not tr
end

#check_extension(extension, extensions) ⇒ Object



88
89
90
91
# File 'lib/yuzu/core/config.rb', line 88

def check_extension(extension, extensions)
  return false if extension_blacklist.include?(extension)
  return extensions.include?(extension)
end

#check_for_gemsObject

Provides information about installed gems for optional features, like Compass integration, git integration,



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/yuzu/core/config.rb', line 43

def check_for_gems

  OPTIONAL_GEMS.each do |gem_name|
    method_name = "has_#{gem_name.underline}?".to_sym

    (class << self; self; end).class_eval do
      instance_variable_name = "@has_#{gem_name.underline}".to_sym

      define_method method_name do
        if instance_variable_get(instance_variable_name).nil?
          gem_installed = SystemChecks.gem_available?(gem_name)
          instance_variable_set(instance_variable_name, gem_installed)
        end
        instance_variable_get(instance_variable_name)
      end # define_method

    end # class_eval

  end # OPTIONAL_GEMS
end

#domainObject



119
120
121
# File 'lib/yuzu/core/config.rb', line 119

def domain
  domain_for_service @service
end

#domain_for_service(service) ⇒ Object



123
124
125
# File 'lib/yuzu/core/config.rb', line 123

def domain_for_service service
  @config_hash[service]['domain'].to_s
end

#image?(path) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/yuzu/core/config.rb', line 80

def image?(path)
  check_extension(path.extension, image_extensions)
end

#is_blacklisted?(path) ⇒ Boolean

Returns:

  • (Boolean)


149
150
151
# File 'lib/yuzu/core/config.rb', line 149

def is_blacklisted?(path)
  path.includes_one_of?(folder_blacklist)
end

#is_hidden?(path) ⇒ Boolean

Checks to see whether file should be considered hidden. By default, all filenames and folders starting with an underscore are hidden.

Returns:

  • (Boolean)


141
142
143
144
145
146
147
# File 'lib/yuzu/core/config.rb', line 141

def is_hidden?(path)
  parts = path.split(File::SEPARATOR)
  hidden = parts.collect do |f|
    f[0].chr == "_"
  end
  hidden.any?
end


111
112
113
# File 'lib/yuzu/core/config.rb', line 111

def link_root
  link_root_for_service(@service)
end


107
108
109
# File 'lib/yuzu/core/config.rb', line 107

def link_root_for_service(service)
  @config_hash['services'][service]['link_root'].to_s
end

#linkrootObject



115
116
117
# File 'lib/yuzu/core/config.rb', line 115

def linkroot
  link_root
end

#possible_indicesObject



127
128
129
# File 'lib/yuzu/core/config.rb', line 127

def possible_indices
  @processable_indices ||= processable_extensions.collect {|e| "index#{e}"}
end

#preview?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/yuzu/core/config.rb', line 131

def preview?
  @service == 'preview'
end

#processable?(path) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/yuzu/core/config.rb', line 72

def processable?(path)
  check_extension(path.extension, processable_extensions)
end

#pwdObject



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

def pwd
  Path.new
end

#resource?(path) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/yuzu/core/config.rb', line 76

def resource?(path)
  check_extension(path.extension, resource_extensions)
end

#stage?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/yuzu/core/config.rb', line 135

def stage?
  @service == 'stage'
end

#system_foldersObject



103
104
105
# File 'lib/yuzu/core/config.rb', line 103

def system_folders
  ["config", ".git"]
end

#verbose?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/yuzu/core/config.rb', line 64

def verbose?
  @options.output == :verbose
end