Class: AwesomeXmlDsl::OptionsParser
- Inherits:
-
Object
- Object
- AwesomeXmlDsl::OptionsParser
- Defined in:
- lib/awesome_xml_dsl/options_parser.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #can_read?(object, key) ⇒ Boolean
- #delete_options(*keys) ⇒ Object
- #each ⇒ Object
-
#initialize(original_options, parent_options = {}) ⇒ OptionsParser
constructor
A new instance of OptionsParser.
- #read(object, key) ⇒ Object
Constructor Details
#initialize(original_options, parent_options = {}) ⇒ OptionsParser
Returns a new instance of OptionsParser.
7 8 9 10 11 12 13 14 |
# File 'lib/awesome_xml_dsl/options_parser.rb', line 7 def initialize(, = {}) self. = .clone [:locals] ||= {} return unless .key?(:locals) [:locals] = [:locals].deep_merge([:locals]) end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/awesome_xml_dsl/options_parser.rb', line 5 def @options end |
Class Method Details
.parse(options, parent_options = {}) ⇒ Object
16 17 18 |
# File 'lib/awesome_xml_dsl/options_parser.rb', line 16 def self.parse(, = {}) new , end |
Instance Method Details
#can_read?(object, key) ⇒ Boolean
61 62 63 64 65 |
# File 'lib/awesome_xml_dsl/options_parser.rb', line 61 def can_read?(object, key) return object.key?(key) if object.respond_to?(:key?) object.respond_to?(key) end |
#delete_options(*keys) ⇒ Object
55 56 57 58 59 |
# File 'lib/awesome_xml_dsl/options_parser.rb', line 55 def (*keys) keys.each do |key| .delete key end end |
#each ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/awesome_xml_dsl/options_parser.rb', line 20 def each return if .key?(:if) && ![:if] if .key?(:collection) && .key?(:as) return unless [:collection].respond_to? :each as = [:as] collection = [:collection] :collection, :as collection.each do |element| [:locals][as] = element yield end elsif (.key?(:if) || .key?(:require)) && .key?(:of) return if .key?(:if) && !(can_read? [:of], [:if]) if .key?(:require) && !can_read?([:of], [:require]) raise RequiredValueNotPresent, "Can't read required key #{[:require]} of #{[:of]}" end accessor = [:require] || [:if] of = [:of] as = [:as] || accessor :if, :of, :as, :require [:locals][as] = read of, accessor yield else yield end end |
#read(object, key) ⇒ Object
67 68 69 70 71 |
# File 'lib/awesome_xml_dsl/options_parser.rb', line 67 def read(object, key) return object[key] if object.is_a? Hash object.send key end |