Skip to content

Instantly share code, notes, and snippets.

@neocturne
Created April 28, 2016 11:42
Show Gist options
  • Save neocturne/f5f273a50d59ccabed88a9ca52775af1 to your computer and use it in GitHub Desktop.
Save neocturne/f5f273a50d59ccabed88a9ca52775af1 to your computer and use it in GitHub Desktop.
require 'digest/md5'
module Static
@values = {}
def self.hashify(attr, parent = nil)
parent_id = if parent then parent.id else '' end
h = Hash[((parent || Settings)[attr] || {}).map do |name, entry|
entry = entry.clone
entry.name = name.to_s
entry.id = Digest::MD5.hexdigest(parent_id + entry.name)
entry.parent = parent_id
yield entry if block_given?
[entry.id, entry]
end]
@values[attr] ||= {}
@values[attr].merge! h
parent[attr] = h.values if parent
end
def self.method_missing(m, *args, &block)
if @values[m] then
@values[m]
else
super
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment