Class: Pears::Subject
- Inherits:
-
Object
- Object
- Pears::Subject
- Includes:
- Enumerable, Testing::Subject
- Defined in:
- lib/pears/subject.rb,
lib/pears/testing.rb more...
Overview
A subject is a collection of settings. You could different Pears::Subjects in your application for different parts of its domain. for instance: application_settings, theming or translaions.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #dig(*args) ⇒ Object
- #each(&block) ⇒ Object
- #has_key?(key) ⇒ Boolean
-
#initialize(name, *layers, loader: ->(builder){}) ⇒ Subject
constructor
A new instance of Subject.
- #keys ⇒ Object
-
#project ⇒ Object
Projects the layers to a hash that van be used as a single source of truth.
- #purge ⇒ Object
- #push_layer(layer) ⇒ Object
- #reboot ⇒ Object
Methods included from Testing::Subject
Constructor Details
permalink #initialize(name, *layers, loader: ->(builder){}) ⇒ Subject
Returns a new instance of Subject.
11 12 13 14 15 16 |
# File 'lib/pears/subject.rb', line 11 def initialize(name, *layers, loader: ->(builder){} ) @name = name @layers = layers @loader = loader boot end |
Instance Attribute Details
permalink #name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/pears/subject.rb', line 9 def name @name end |
Instance Method Details
permalink #[](key) ⇒ Object
[View source]
18 19 20 |
# File 'lib/pears/subject.rb', line 18 def [](key) project[key] end |
permalink #dig(*args) ⇒ Object
[View source]
30 31 32 |
# File 'lib/pears/subject.rb', line 30 def dig(*args) project.dig(*args) end |
permalink #each(&block) ⇒ Object
[View source]
49 50 51 |
# File 'lib/pears/subject.rb', line 49 def each(&block) project.each(&block) end |
permalink #has_key?(key) ⇒ Boolean
26 27 28 |
# File 'lib/pears/subject.rb', line 26 def has_key?(key) project.has_key? key end |
permalink #keys ⇒ Object
[View source]
22 23 24 |
# File 'lib/pears/subject.rb', line 22 def keys project.keys end |
permalink #project ⇒ Object
Projects the layers to a hash that van be used as a single source of truth.
43 44 45 46 47 |
# File 'lib/pears/subject.rb', line 43 def project layers.reverse.reduce(Hash.new) do |hash, layer| hash.deep_merge(layer.data) end.with_indifferent_access end |
permalink #purge ⇒ Object
[View source]
34 35 36 |
# File 'lib/pears/subject.rb', line 34 def purge @layers.each.each(&:purge) end |
permalink #push_layer(layer) ⇒ Object
[View source]
38 39 40 |
# File 'lib/pears/subject.rb', line 38 def push_layer(layer) @layers << layer end |
permalink #reboot ⇒ Object
[View source]
53 54 55 56 57 |
# File 'lib/pears/subject.rb', line 53 def reboot purge @layers = [] boot end |