class Webspicy::Support::World
Attributes
config[R]
folder[R]
Public Class Methods
new(folder, config = nil)
click to toggle source
Calls superclass method
# File lib/webspicy/support/world.rb, line 5 def initialize(folder, config = nil) super({}) @folder = folder @config = config end
Public Instance Methods
method_missing(name, *args, &bl)
click to toggle source
Calls superclass method
# File lib/webspicy/support/world.rb, line 12 def method_missing(name, *args, &bl) return super if name =~ /=$/ file = ['json', 'yml', 'yaml', 'rb'] .map{|e| folder/"#{name}.#{e}" } .find{|f| f.file? } data = case file && file.ext when /json/ JSON.parse(file.read, object_class: OpenStruct) when /ya?ml/ JSON.parse(file.load.to_json, object_class: OpenStruct) when /rb/ ::Kernel.eval(file.read).tap{|x| x.config = self.config if x.is_a?(Item) } end self.send(:"#{name}=", data) end
to_data(which)
click to toggle source
# File lib/webspicy/support/world.rb, line 30 def to_data(which) case which when Hash OpenStruct.new(which) when Array which.map{|x| to_data(x) } else which end end