Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/stroma/hooks/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def initialize(collection = Set.new)
# @return [void]
def initialize_dup(original)
super
@collection = original.instance_variable_get(:@collection).dup
@collection = original.collection.dup
end

# Adds a new hook to the collection.
Expand Down Expand Up @@ -96,6 +96,10 @@ def before(key)
def after(key)
@collection.select { |hook| hook.after? && hook.target_key == key }
end

protected

attr_reader :collection
end
end
end
6 changes: 5 additions & 1 deletion lib/stroma/settings/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def initialize(storage = {})
# @return [void]
def initialize_dup(original)
super
@storage = original.instance_variable_get(:@storage).transform_values(&:dup)
@storage = original.storage.transform_values(&:dup)
end

# Accesses or creates RegistrySettings for a registry key.
Expand All @@ -83,6 +83,10 @@ def [](registry_key)
def to_h
@storage.transform_values(&:to_h)
end

protected

attr_reader :storage
end
end
end
6 changes: 5 additions & 1 deletion lib/stroma/settings/registry_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def initialize(storage = {})
# @return [void]
def initialize_dup(original)
super
@storage = original.instance_variable_get(:@storage).transform_values(&:dup)
@storage = original.storage.transform_values(&:dup)
end

# Accesses or creates a Setting for an extension.
Expand All @@ -81,6 +81,10 @@ def [](extension_name)
def to_h
@storage.transform_values(&:to_h)
end

protected

attr_reader :storage
end
end
end
6 changes: 5 additions & 1 deletion lib/stroma/settings/setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def initialize(data = {})
# @return [void]
def initialize_dup(original)
super
@data = deep_dup(original.instance_variable_get(:@data))
@data = deep_dup(original.data)
end

# Converts to a plain Hash.
Expand All @@ -93,6 +93,10 @@ def fetch(key, *args, &block)
@data.fetch(key.to_sym, *args, &block)
end

protected

attr_reader :data

private

# Recursively duplicates nested Hash and Array structures.
Expand Down
4 changes: 2 additions & 2 deletions lib/stroma/state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def initialize
# @return [void]
def initialize_dup(original)
super
@hooks = original.instance_variable_get(:@hooks).dup
@settings = original.instance_variable_get(:@settings).dup
@hooks = original.hooks.dup
@settings = original.settings.dup
end
end
end
3 changes: 3 additions & 0 deletions sig/lib/stroma/hooks/collection.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ module Stroma
def empty?: () -> bool

def size: () -> Integer

# Protected in Ruby; declared here for Steep visibility in initialize_dup
attr_reader collection: Set[Hook]
end
end
end
3 changes: 3 additions & 0 deletions sig/lib/stroma/settings/collection.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ module Stroma
def empty?: () -> bool

def to_h: () -> Hash[Symbol, Hash[Symbol, Hash[Symbol, untyped]]]

# Protected in Ruby; declared here for Steep visibility in initialize_dup
attr_reader storage: Hash[Symbol, RegistrySettings]
end
end
end
3 changes: 3 additions & 0 deletions sig/lib/stroma/settings/registry_settings.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ module Stroma
def empty?: () -> bool

def to_h: () -> Hash[Symbol, Hash[Symbol, untyped]]

# Protected in Ruby; declared here for Steep visibility in initialize_dup
attr_reader storage: Hash[Symbol, Setting]
end
end
end
3 changes: 3 additions & 0 deletions sig/lib/stroma/settings/setting.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ module Stroma
| (Symbol key, untyped default) -> untyped
| (Symbol key) { (Symbol) -> untyped } -> untyped

# Protected in Ruby; declared here for Steep visibility in initialize_dup
attr_reader data: Hash[Symbol, untyped]

private

def deep_dup: (untyped obj) -> untyped
Expand Down
6 changes: 6 additions & 0 deletions spec/stroma/hooks/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,10 @@
expect(hooks.map(&:itself)).to all(be_a(Stroma::Hooks::Hook))
end
end

describe "protected interface" do
it "does not expose collection publicly" do
expect { hooks.collection }.to raise_error(NoMethodError)
end
end
end
6 changes: 6 additions & 0 deletions spec/stroma/settings/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,10 @@
expect(settings[:actions][:transactional][:class]).to eq("ActiveRecord::Base")
end
end

describe "protected interface" do
it "does not expose storage publicly" do
expect { settings.storage }.to raise_error(NoMethodError)
end
end
end
6 changes: 6 additions & 0 deletions spec/stroma/settings/registry_settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,10 @@
expect(settings[:authorization].key?(:new_key)).to be(false)
end
end

describe "protected interface" do
it "does not expose storage publicly" do
expect { settings.storage }.to raise_error(NoMethodError)
end
end
end
6 changes: 6 additions & 0 deletions spec/stroma/settings/setting_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,10 @@
expect(setting[:list][1][0]).to eq(2)
end
end

describe "protected interface" do
it "does not expose data publicly" do
expect { setting.data }.to raise_error(NoMethodError)
end
end
end