Class: InspectorGadget::ModulePreferences
- Inherits:
-
Object
- Object
- InspectorGadget::ModulePreferences
- Includes:
- StickyAttributes
- Defined in:
- lib/inspectorgadget/module_preferences.rb
Instance Attribute Summary collapse
-
#may_be_required ⇒ Object
readonly
Returns the value of attribute may_be_required.
-
#required_features ⇒ Object
readonly
Returns the value of attribute required_features.
-
#supported_locales ⇒ Object
readonly
Returns the value of attribute supported_locales.
Instance Method Summary collapse
-
#initialize(properties = {}) ⇒ ModulePreferences
constructor
A new instance of ModulePreferences.
- #may_require(type, value, optional_params = {}) ⇒ Object
- #require_features(*features) ⇒ Object
- #supports_locale(options = nil) ⇒ Object
- #to_xml(xml) ⇒ Object
Methods included from StickyAttributes
#method_missing, #sticky_attributes
Constructor Details
#initialize(properties = {}) ⇒ ModulePreferences
Returns a new instance of ModulePreferences.
7 8 9 10 |
# File 'lib/inspectorgadget/module_preferences.rb', line 7 def initialize(properties = {}) properties.each { |name, value| send name, value } if properties.is_a? Hash @required_features, @may_be_required, @supported_locales = [], [], [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class InspectorGadget::StickyAttributes
Instance Attribute Details
#may_be_required ⇒ Object (readonly)
Returns the value of attribute may_be_required.
5 6 7 |
# File 'lib/inspectorgadget/module_preferences.rb', line 5 def may_be_required @may_be_required end |
#required_features ⇒ Object (readonly)
Returns the value of attribute required_features.
5 6 7 |
# File 'lib/inspectorgadget/module_preferences.rb', line 5 def required_features @required_features end |
#supported_locales ⇒ Object (readonly)
Returns the value of attribute supported_locales.
5 6 7 |
# File 'lib/inspectorgadget/module_preferences.rb', line 5 def supported_locales @supported_locales end |
Instance Method Details
#may_require(type, value, optional_params = {}) ⇒ Object
16 17 18 |
# File 'lib/inspectorgadget/module_preferences.rb', line 16 def may_require(type, value, optional_params = {}) @may_be_required << optional_params.update(:type => type, :value => value) end |
#require_features(*features) ⇒ Object
12 13 14 |
# File 'lib/inspectorgadget/module_preferences.rb', line 12 def require_features(*features) @required_features.concat features end |
#supports_locale(options = nil) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/inspectorgadget/module_preferences.rb', line 20 def supports_locale( = nil) if .is_a? Hash raise ArgumentError.new("You must provide the lang and/or country when using supports_locale") unless .key?(:lang) || .key?(:country) @supported_locales << end end |
#to_xml(xml) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/inspectorgadget/module_preferences.rb', line 27 def to_xml(xml) xml.ModulePrefs(sticky_attributes) do @required_features.each { |feature| xml.Require :feature => feature } @may_be_required.each { |may_require| xml.MayRequire may_require } @supported_locales.each { |locale| xml.Locale locale } end end |