Class: Phony::Config
- Inherits:
-
Object
- Object
- Phony::Config
- Defined in:
- lib/phony/config.rb
Overview
The Config class is only used to configure Phony and to load specific subsets of CCs.
Instance Attribute Summary collapse
-
#excluded_ccs ⇒ Object
readonly
Returns the value of attribute excluded_ccs.
-
#included_ccs ⇒ Object
readonly
Returns the value of attribute included_ccs.
Class Method Summary collapse
-
.load(*options) ⇒ Object
Use as follows:.
Instance Method Summary collapse
- #has_excluded? ⇒ Boolean
- #has_included? ⇒ Boolean
-
#initialize(included_ccs, excluded_ccs) ⇒ Config
constructor
A new instance of Config.
- #load?(cc) ⇒ Boolean
Constructor Details
#initialize(included_ccs, excluded_ccs) ⇒ Config
Returns a new instance of Config.
20 21 22 23 |
# File 'lib/phony/config.rb', line 20 def initialize(included_ccs, excluded_ccs) @included_ccs = included_ccs || [] @excluded_ccs = excluded_ccs || [] end |
Instance Attribute Details
#excluded_ccs ⇒ Object (readonly)
Returns the value of attribute excluded_ccs.
18 19 20 |
# File 'lib/phony/config.rb', line 18 def excluded_ccs @excluded_ccs end |
#included_ccs ⇒ Object (readonly)
Returns the value of attribute included_ccs.
18 19 20 |
# File 'lib/phony/config.rb', line 18 def included_ccs @included_ccs end |
Class Method Details
.load(*options) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/phony/config.rb', line 60 def self.load * # Extract options. last = .last only, except = if last.respond_to?(:to_hash) # We have the explicit form. [last[:only], last[:except]] elsif .respond_to?(:to_ary) # We have the convenience short forms. [, []] end # Set defaults. only, except = [only || [], except || []] # Convert to expected format if possible. only, except = [only.map(&:to_s), except.map(&:to_s)] # Check params. raise "Params given to Phony::Config.load must be Array-like. The one given was: #{only}" unless only.respond_to?(:to_ary) raise "Params given to Phony::Config.load must be Array-like. The one given was: #{except}" unless except.respond_to?(:to_ary) # Configure Phony. Phony.config = new(only, except) # Load phony. Kernel.load File.('../phony.rb', __dir__) # Return the stored config data. Phony.config end |
Instance Method Details
#has_excluded? ⇒ Boolean
43 44 45 |
# File 'lib/phony/config.rb', line 43 def has_excluded? !excluded_ccs.empty? end |
#has_included? ⇒ Boolean
39 40 41 |
# File 'lib/phony/config.rb', line 39 def has_included? !included_ccs.empty? end |
#load?(cc) ⇒ Boolean
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/phony/config.rb', line 25 def load?(cc) return false if has_excluded? && excluded_ccs.include?(cc) if has_included? # We have to check the included_ccs, otherwise false. return true if included_ccs.include?(cc) false else # It's not in excluded and no included was given. true end end |