Class: SchemaToRxYaml::Settings::Core

Inherits:
Object
  • Object
show all
Defined in:
lib/restfulx/schema_to_rx_yaml.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name_or_hash = Config.settings_file) ⇒ Core

Returns a new instance of Core.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/restfulx/schema_to_rx_yaml.rb', line 43

def initialize(name_or_hash = Config.settings_file)
  case name_or_hash
  when Hash
    self._settings = name_or_hash
  when String, Symbol
    root_path = defined?(RestfulX::Configuration::APP_ROOT) ? "#{RestfulX::Configuration::APP_ROOT}/config/" : ""
    file_path = name_or_hash.is_a?(Symbol) ? "#{root_path}#{name_or_hash}.yml" : name_or_hash
    self._settings = YAML.load(ERB.new(File.read(file_path)).result)
    self._settings = _settings[RAILS_ENV] if defined?(RAILS_ENV)
  else
    raise ArgumentError.new("Your settings must be a hash, 
      a symbol representing the name of the .yml file in your config directory,
      or a string representing the abosolute path to your settings file.")
  end
  define_settings!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (private)

Raises:

  • (NoMethodError)


61
62
63
# File 'lib/restfulx/schema_to_rx_yaml.rb', line 61

def method_missing(name, *args, &block)
  raise NoMethodError.new("no configuration was specified for #{name}")
end

Instance Attribute Details

#_settingsObject

Returns the value of attribute _settings.



41
42
43
# File 'lib/restfulx/schema_to_rx_yaml.rb', line 41

def _settings
  @_settings
end

Class Method Details

.nameObject



23
24
25
# File 'lib/restfulx/schema_to_rx_yaml.rb', line 23

def name
  instance._settings.key?("name") ? instance.name : super
end

.reset!Object



27
28
29
# File 'lib/restfulx/schema_to_rx_yaml.rb', line 27

def reset!
  @instance = nil
end