Class: DiningTable::Presenters::HTMLPresenterConfiguration::TagConfiguration
- Inherits:
-
Object
- Object
- DiningTable::Presenters::HTMLPresenterConfiguration::TagConfiguration
- Defined in:
- lib/dining-table/presenters/html_presenter_configuration.rb
Overview
configuration classes that allow us to avoid implementing a deep-merge for the config hash, and are more user friendly for use in config blocks in the table definition
Instance Attribute Summary collapse
-
#__data_hash ⇒ Object
Returns the value of attribute __data_hash.
Class Method Summary collapse
Instance Method Summary collapse
-
#class ⇒ Object
override class method (since it is a very common html attribute), and the method missing approach doesn’t work here, as it returns the Ruby class by default.
-
#initialize ⇒ TagConfiguration
constructor
A new instance of TagConfiguration.
-
#initialize_copy(source) ⇒ Object
for deep dup.
- #merge_hash(hash) ⇒ Object
- #method_missing(name, *args, &block) ⇒ Object
- #respond_to_missing?(method_name, *args) ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ TagConfiguration
Returns a new instance of TagConfiguration.
13 14 15 |
# File 'lib/dining-table/presenters/html_presenter_configuration.rb', line 13 def initialize self.__data_hash = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/dining-table/presenters/html_presenter_configuration.rb', line 17 def method_missing(name, *args, &block) if name.to_s[-1] == '=' key = name.to_s[0..-2] # strip away '=' __data_hash[ key.to_sym ] = args.first else __data_hash.key?( name ) ? __data_hash[ name ] : super end end |
Instance Attribute Details
#__data_hash ⇒ Object
Returns the value of attribute __data_hash.
11 12 13 |
# File 'lib/dining-table/presenters/html_presenter_configuration.rb', line 11 def __data_hash @__data_hash end |
Class Method Details
.from_hash(hash) ⇒ Object
49 50 51 |
# File 'lib/dining-table/presenters/html_presenter_configuration.rb', line 49 def self.from_hash( hash ) new.merge_hash( hash ) end |
Instance Method Details
#class ⇒ Object
override class method (since it is a very common html attribute), and the method missing approach doesn’t work here, as it returns the Ruby class by default.
33 34 35 |
# File 'lib/dining-table/presenters/html_presenter_configuration.rb', line 33 def class __data_hash.key?( :class ) ? __data_hash[ :class ] : super end |
#initialize_copy(source) ⇒ Object
for deep dup
54 55 56 |
# File 'lib/dining-table/presenters/html_presenter_configuration.rb', line 54 def initialize_copy( source ) self.__data_hash = source.__data_hash.dup end |
#merge_hash(hash) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/dining-table/presenters/html_presenter_configuration.rb', line 41 def merge_hash( hash ) return self if !hash hash.each do |key, value| self.send("#{ key }=", value) end self end |
#respond_to_missing?(method_name, *args) ⇒ Boolean
26 27 28 29 |
# File 'lib/dining-table/presenters/html_presenter_configuration.rb', line 26 def respond_to_missing?(method_name, *args) return true if method_name.to_s[-1] == '=' __data_hash.key?( method_name ) ? true : super end |
#to_h ⇒ Object
37 38 39 |
# File 'lib/dining-table/presenters/html_presenter_configuration.rb', line 37 def to_h __data_hash end |