class Schoolkeep::Fixture
Constants
- GEM_FIXTURE_PATH
- KEY_MAPPING
- MAPPING
Attributes
default_path[RW]
fixture_path[RW]
Public Class Methods
new(fixture_path)
click to toggle source
# File lib/schoolkeep/fixture.rb, line 48 def initialize(fixture_path) @fixture_path = fixture_path end
Private Class Methods
for(name, overrides: {})
click to toggle source
# File lib/schoolkeep/fixture.rb, line 121 def for(name, overrides: {}) new(default_path).for(name, overrides: overrides) end
globals()
click to toggle source
# File lib/schoolkeep/fixture.rb, line 125 def globals new(default_path).globals end
Public Instance Methods
for(name, overrides: {})
click to toggle source
# File lib/schoolkeep/fixture.rb, line 52 def for(name, overrides: {}) fixtures = uncasted_globals.merge(gem_fixtures["templates"][name] || {}) if dev_fixtures["templates"] fixtures.merge!(dev_fixtures["templates"][name] || {}) end fixtures.merge!(overrides) cast(fixtures).merge(template_name: File.basename(name, ".html.sktl")) end
globals()
click to toggle source
# File lib/schoolkeep/fixture.rb, line 64 def globals cast(uncasted_globals) end
Private Instance Methods
cast(values, key = nil)
click to toggle source
# File lib/schoolkeep/fixture.rb, line 90 def cast(values, key = nil) key &&= key.to_sym if values.is_a?(Symbol) values = uncasted_models[values.to_s] end if values.is_a? Array values = values.map do |value| cast(value, key) end else if values.is_a? Hash values = values.each_with_object({}) do |(child_key, value), hash| child_key &&= child_key.to_sym hash[KEY_MAPPING[child_key] || child_key] = cast(value, child_key) end end if MAPPING[key] values = MAPPING[key].new(values) end end values end
dev_fixtures()
click to toggle source
# File lib/schoolkeep/fixture.rb, line 78 def dev_fixtures @dev_fixtures ||= if File.exist?(fixture_path.to_s) YAML.load_file(fixture_path.to_s) else {} end end
gem_fixtures()
click to toggle source
# File lib/schoolkeep/fixture.rb, line 86 def gem_fixtures @gem_fixtures ||= YAML.load_file(GEM_FIXTURE_PATH) end
uncasted_globals()
click to toggle source
# File lib/schoolkeep/fixture.rb, line 70 def uncasted_globals gem_fixtures["globals"].merge(dev_fixtures["globals"] || {}) end
uncasted_models()
click to toggle source
# File lib/schoolkeep/fixture.rb, line 74 def uncasted_models gem_fixtures["models"].merge(dev_fixtures["models"] || {}) end