Sha256: 0d5873f01e3f6c7536ca1ec2ec8e8d6e974df55340718edd39ac7dabe61ec6f8
Contents?: true
Size: 1.34 KB
Versions: 3
Compression:
Stored size: 1.34 KB
Contents
class Tynn # Public: It provides a settings API for applications. This plugin is # included by default. # # Examples # # require "tynn" # # module AppName # def self.setup(app, app_name) # app.settings[:app_name] = app_name # end # # module ClassMethods # def app_name # return settings[:app_name] # end # end # end # # Tynn.plugin(AppName, "MyApp") # # Tynn.app_name # # => "MyApp" # module Settings # Internal: Returns a deep copy of a Hash. def self.deepclone(hash) default_proc, hash.default_proc = hash.default_proc, nil return Marshal.load(Marshal.dump(hash)) ensure hash.default_proc = default_proc end module ClassMethods # Internal: Copies settings into the subclass. # If a setting is not found, checks parent's settings. def inherited(subclass) subclass.settings.replace(Tynn::Settings.deepclone(settings)) subclass.settings.default_proc = proc { |h, k| h[k] = settings[k] } end # Returns a Hash with the application settings. # # Examples # # Tynn.set(:environment, :development) # # Tynn.settings # # => { :environment => :development } # def settings return @settings ||= {} end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
tynn-1.3.0 | lib/tynn/settings.rb |
tynn-1.2.0 | lib/tynn/settings.rb |
tynn-1.1.0 | lib/tynn/settings.rb |