Class: Cmsimple::RegionsProxy
- Inherits:
-
Object
- Object
- Cmsimple::RegionsProxy
- Defined in:
- lib/cmsimple/regions_proxy.rb
Instance Attribute Summary collapse
-
#regions_hash ⇒ Object
Returns the value of attribute regions_hash.
Instance Method Summary collapse
- #define_regions ⇒ Object
-
#initialize(regions_hash) ⇒ RegionsProxy
constructor
A new instance of RegionsProxy.
- #method_missing(method, *args, &block) ⇒ Object
- #snippets_hash ⇒ Object
Constructor Details
#initialize(regions_hash) ⇒ RegionsProxy
Returns a new instance of RegionsProxy.
5 6 7 8 9 10 |
# File 'lib/cmsimple/regions_proxy.rb', line 5 def initialize(regions_hash) if regions_hash.is_a?(Hash) @regions_hash = ActiveSupport::HashWithIndifferentAccess.new(regions_hash.dup) define_regions end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
Instance Attribute Details
#regions_hash ⇒ Object
Returns the value of attribute regions_hash.
3 4 5 |
# File 'lib/cmsimple/regions_proxy.rb', line 3 def regions_hash @regions_hash end |
Instance Method Details
#define_regions ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cmsimple/regions_proxy.rb', line 17 def define_regions mod = Module.new extend mod region_methods = @regions_hash.collect do |key, value| %{def #{key}() Cmsimple::Region.new(@regions_hash[:#{key}]); end} end mod.module_eval region_methods.join("\n"), __FILE__, __LINE__ + 1 end |
#snippets_hash ⇒ Object
12 13 14 15 |
# File 'lib/cmsimple/regions_proxy.rb', line 12 def snippets_hash return {} unless @regions_hash.present? @regions_hash.inject(ActiveSupport::HashWithIndifferentAccess.new){|h, (k,v)| h.merge(v[:snippets].presence || {})} end |