Class: Pears::Subject
- Inherits:
-
Object
- Object
- Pears::Subject
- Includes:
- Enumerable, Testing::Subject
- Defined in:
- lib/pears/subject.rb,
lib/pears/testing.rb
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
#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
#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
#[](key) ⇒ Object
18 19 20 |
# File 'lib/pears/subject.rb', line 18 def [](key) project[key] end |
#dig(*args) ⇒ Object
30 31 32 |
# File 'lib/pears/subject.rb', line 30 def dig(*args) project.dig(*args) end |
#each(&block) ⇒ Object
49 50 51 |
# File 'lib/pears/subject.rb', line 49 def each(&block) project.each(&block) end |
#has_key?(key) ⇒ Boolean
26 27 28 |
# File 'lib/pears/subject.rb', line 26 def has_key?(key) project.has_key? key end |
#keys ⇒ Object
22 23 24 |
# File 'lib/pears/subject.rb', line 22 def keys project.keys end |
#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 |
#purge ⇒ Object
34 35 36 |
# File 'lib/pears/subject.rb', line 34 def purge @layers.each.each(&:purge) end |
#push_layer(layer) ⇒ Object
38 39 40 |
# File 'lib/pears/subject.rb', line 38 def push_layer(layer) @layers << layer end |
#reboot ⇒ Object
53 54 55 56 57 |
# File 'lib/pears/subject.rb', line 53 def reboot purge @layers = [] boot end |