Class: RStore::Configuration
Constant Summary collapse
- Validations =
Validations for RStore::CSV specific options
Hash.new { |h,k| lambda { |value| true }}. merge!({recursive: lambda { |value| value.boolean_or_nil? }, has_headers: lambda { |value| value.boolean_or_nil? }, selector: lambda { |value| value.is_a?(String) }})
Class Attribute Summary collapse
-
.default_file_options ⇒ Object
readonly
Returns the value of attribute default_file_options.
-
.default_options ⇒ Object
readonly
Returns the value of attribute default_options.
-
.default_parse_options ⇒ Object
readonly
Returns the value of attribute default_parse_options.
Instance Attribute Summary collapse
-
#file_options ⇒ Object
readonly
Returns the value of attribute file_options.
-
#options ⇒ Object
Returns the value of attribute options.
-
#parse_options ⇒ Object
readonly
Returns the value of attribute parse_options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
- .change_default_options(options) ⇒ Object
- .reset_default_options ⇒ Object
- .valid_value?(option, value) ⇒ Boolean
Instance Method Summary collapse
- #[](key) ⇒ Object
- #arg_error_message(path, new_options) ⇒ Object
- #extract_with(options) ⇒ Object
-
#initialize(path, options) ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize(path, options) ⇒ Configuration
Returns a new instance of Configuration.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rstore/configuration.rb', line 34 def initialize path, = .dup @path = path self. = # options= deletes all valid options already processed from new_options, # leaving only options that are not valid. # Therefore, new_options.size > 0 indicates that options not recognized where passed. raise ArgumentError, (@path, ) if .size > 0 @file_options = extract_with(Configuration.) @parse_options = extract_with(Configuration.) end |
Class Attribute Details
.default_file_options ⇒ Object (readonly)
Returns the value of attribute default_file_options.
8 9 10 |
# File 'lib/rstore/configuration.rb', line 8 def @default_file_options end |
.default_options ⇒ Object (readonly)
Returns the value of attribute default_options.
10 11 12 |
# File 'lib/rstore/configuration.rb', line 10 def @default_options end |
.default_parse_options ⇒ Object (readonly)
Returns the value of attribute default_parse_options.
9 10 11 |
# File 'lib/rstore/configuration.rb', line 9 def @default_parse_options end |
Instance Attribute Details
#file_options ⇒ Object (readonly)
Returns the value of attribute file_options.
29 30 31 |
# File 'lib/rstore/configuration.rb', line 29 def @file_options end |
#options ⇒ Object
Returns the value of attribute options.
28 29 30 |
# File 'lib/rstore/configuration.rb', line 28 def @options end |
#parse_options ⇒ Object (readonly)
Returns the value of attribute parse_options.
30 31 32 |
# File 'lib/rstore/configuration.rb', line 30 def @parse_options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
31 32 33 |
# File 'lib/rstore/configuration.rb', line 31 def path @path end |
Class Method Details
.change_default_options(options) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/rstore/configuration.rb', line 81 def self. raise ArgumentError, "#{} must be an instance of Hash" unless .is_a?(Hash) = Configuration..merge() raise ArgumentError, "#{} contains unknown option key" if .size > Configuration..size .each do |option, value| = "'#{value}' (#{value.class}) is not a valid value for option #{option.inspect}" raise ArgumentError, unless valid_value?(option, value) end @default_options = end |
.reset_default_options ⇒ Object
94 95 96 |
# File 'lib/rstore/configuration.rb', line 94 def self. @default_options = @default_file_options.merge(@default_parse_options) end |
.valid_value?(option, value) ⇒ Boolean
115 116 117 |
# File 'lib/rstore/configuration.rb', line 115 def self.valid_value? option, value Validations[option][value] end |
Instance Method Details
#[](key) ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/rstore/configuration.rb', line 99 def [] key target = instance_variables.find do |var| var.to_s.gsub(/@/,'').to_sym == key end if target instance_variable_get(target) else raise ArgumentError, "'#{key}' is not an instance variable" end end |
#arg_error_message(path, new_options) ⇒ Object
120 121 122 123 |
# File 'lib/rstore/configuration.rb', line 120 def path, keys = .keys.join(', ') "Unsupported options: #{keys} for path '#{path}'" end |
#extract_with(options) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/rstore/configuration.rb', line 69 def extract_with keys = .keys @options.inject({}) do |acc, (option, value)| if keys.include?(option) acc[option] = value end acc end end |