Module: Peony::Configure
- Defined in:
- lib/peony/configure.rb
Instance Method Summary collapse
- #find_in_directories(paths, name, file_only) ⇒ Object
- #find_recipes(name, file_only = true) ⇒ Object
- #find_templates(name, file_only = true) ⇒ Object
-
#method_missing(method, *args, &blk) ⇒ Object
### method_missing Hook to get settings.
- #recipes_paths ⇒ Object
- #scope(name) ⇒ Object
-
#set(key, *args, &block) ⇒ Object
### set Sets settings.
-
#set_default(key, *args, &block) ⇒ Object
### set_default Sets default settings.
-
#settings ⇒ Object
### settings Accesses the settings hash.
- #template_paths ⇒ Object
- #travel(scope, &block) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &blk) ⇒ Object
### method_missing Hook to get settings. See #settings for an explanation.
Returns things.
89 90 91 92 93 94 95 |
# File 'lib/peony/configure.rb', line 89 def method_missing(method, *args, &blk) if settings.respond_to? method, true settings.__send__(method, *args, &blk) else super end end |
Instance Method Details
#find_in_directories(paths, name, file_only) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/peony/configure.rb', line 75 def find_in_directories(paths, name, file_only) templates = [] paths.each do|path| templates += Dir[File.(name, path)].reject{|filename| file_only && File.directory?(filename)} end templates end |
#find_recipes(name, file_only = true) ⇒ Object
71 72 73 |
# File 'lib/peony/configure.rb', line 71 def find_recipes(name, file_only=true) find_in_directories(recipes_paths, name, file_only) end |
#find_templates(name, file_only = true) ⇒ Object
63 64 65 |
# File 'lib/peony/configure.rb', line 63 def find_templates(name, file_only=true) find_in_directories(template_paths, name, file_only) end |
#recipes_paths ⇒ Object
67 68 69 |
# File 'lib/peony/configure.rb', line 67 def recipes_paths ["#{Dir.pwd}/recipes", File.('../../recipes', __dir__)] end |
#scope(name) ⇒ Object
43 44 45 46 47 |
# File 'lib/peony/configure.rb', line 43 def scope(name) settings.with_scope(name.to_sym) do yield end end |
#set(key, *args, &block) ⇒ Object
### set Sets settings. Sets given symbol ‘key` to value in `value`.
Returns the value.
set :domain, 'kickflip.me'
11 12 13 |
# File 'lib/peony/configure.rb', line 11 def set(key, *args, &block) settings.send :"#{key}=", *args, &block end |
#set_default(key, *args, &block) ⇒ Object
### set_default Sets default settings. Sets given symbol ‘key` to value in `value` only if the key isn’t set yet.
Returns the value.
set_default :term_mode, :pretty
set :term_mode, :system
settings.term_mode.should == :system
set :term_mode, :system
set_default :term_mode, :pretty
settings.term_mode.should == :system
28 29 30 |
# File 'lib/peony/configure.rb', line 28 def set_default(key, *args, &block) set(key, *args, block) unless settings.send(:local?, key.to_sym) end |
#settings ⇒ Object
### settings Accesses the settings hash.
set :domain, 'kickflip.me'
settings.domain #=> 'kickflip.me'
domain #=> 'kickflip.me'
39 40 41 |
# File 'lib/peony/configure.rb', line 39 def settings @settings ||= Settings.new end |
#template_paths ⇒ Object
59 60 61 |
# File 'lib/peony/configure.rb', line 59 def template_paths ["#{Dir.pwd}/templates", File.('../../templates', __dir__)] end |