Created
April 28, 2016 11:42
-
-
Save neocturne/f5f273a50d59ccabed88a9ca52775af1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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