class Constantinopolis::Fort

Public Class Methods

build!() click to toggle source
# File lib/constantinopolis.rb, line 23
def build!
  instance.build_methods!
  instance.build_js!
end
js_code() click to toggle source
# File lib/constantinopolis.rb, line 33
def js_code
  instance.js_code
end
namespace(namespace = nil) click to toggle source
# File lib/constantinopolis.rb, line 19
def namespace(namespace = nil)
  @namespace ||= namespace
end
new() click to toggle source
# File lib/constantinopolis.rb, line 63
def initialize
  raise "Must locate yaml file!" unless self.class.yml
  file = open(self.class.yml).read
  hash = set_accessor(YAML.unsafe_load(ERB.new(file).result))
  @constants = self.class.namespace ? hash[self.class.namespace.to_s] : hash
end
reload!() click to toggle source
# File lib/constantinopolis.rb, line 28
def reload!
  @instance = nil
  build!
end
yml(path = nil) click to toggle source
# File lib/constantinopolis.rb, line 13
def yml(path = nil)
  return @yml unless path
  Constantinopolis::RailsReloader.register(self, path) if defined? Rails
  @yml = path
end

Private Class Methods

instance() click to toggle source
# File lib/constantinopolis.rb, line 39
def instance
  return @instance if @instance
  @instance = new
end

Public Instance Methods

build_js!() click to toggle source
# File lib/constantinopolis.rb, line 53
def build_js!
  @js_code = "#{self.class.name}=#{JSON.generate(@constants)};"
end
build_methods!() click to toggle source

— Instance methods

# File lib/constantinopolis.rb, line 47
def build_methods!
  @constants.each do |key, value|
    self.class.define_singleton_method key, ->() { value }
  end
end
js_code() click to toggle source
# File lib/constantinopolis.rb, line 57
def js_code
  @js_code
end

Private Instance Methods

set_accessor(hash) click to toggle source
# File lib/constantinopolis.rb, line 70
def set_accessor(hash)
  hash.each do |key, value|
    if value.is_a? Hash
      value.extend AccessableHash
      set_accessor value
    end
  end
end