Method: Linecook::Recipe#attributes

Defined in:
lib/linecook/recipe.rb

#attributes(source_name = nil, &block) ⇒ Object

Loads the specified attributes file and merges the results into attrs. A block may be given to specify attrs as well; it will be evaluated in the context of an Attributes instance.

Returns a hash representing all attributes loaded thusfar (specifically attrs prior to merging in the package env). The attributes hash should be treated as if it were read-only.



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/linecook/recipe.rb', line 171

def attributes(source_name=nil, &block)
  if source_name || block
    attributes = Attributes.new

    if source_name
      if source_path = _cookbook_.find(:attributes, source_name, attributes.load_attrs_extnames)
        attributes.load_attrs(source_path)
      end
    end

    if block
      attributes.instance_eval(&block)
    end

    @attributes = Utils.deep_merge(@attributes, attributes.to_hash)
    @attrs = nil
  end

  @attributes
end