Class: TrustyCms::ResourceResponses::Response
- Inherits:
-
Object
- Object
- TrustyCms::ResourceResponses::Response
- Defined in:
- lib/trusty_cms/resource_responses.rb
Instance Attribute Summary collapse
-
#block_order ⇒ Object
readonly
Returns the value of attribute block_order.
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
-
#publish_block ⇒ Object
readonly
Returns the value of attribute publish_block.
-
#publish_formats ⇒ Object
readonly
Returns the value of attribute publish_formats.
Instance Method Summary collapse
- #default(&block) ⇒ Object
- #each_format ⇒ Object
- #each_published ⇒ Object
-
#initialize ⇒ Response
constructor
A new instance of Response.
- #initialize_copy(orig) ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
- #publish(*formats, &block) ⇒ Object
Constructor Details
#initialize ⇒ Response
Returns a new instance of Response.
68 69 70 71 72 |
# File 'lib/trusty_cms/resource_responses.rb', line 68 def initialize @publish_formats = [] @blocks = {} @block_order = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/trusty_cms/resource_responses.rb', line 110 def method_missing(method, *args, &block) if block_given? @blocks[method] = block @block_order << method unless @block_order.include?(method) elsif args.empty? @block_order << method else super end end |
Instance Attribute Details
#block_order ⇒ Object (readonly)
Returns the value of attribute block_order.
66 67 68 |
# File 'lib/trusty_cms/resource_responses.rb', line 66 def block_order @block_order end |
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
66 67 68 |
# File 'lib/trusty_cms/resource_responses.rb', line 66 def blocks @blocks end |
#publish_block ⇒ Object (readonly)
Returns the value of attribute publish_block.
66 67 68 |
# File 'lib/trusty_cms/resource_responses.rb', line 66 def publish_block @publish_block end |
#publish_formats ⇒ Object (readonly)
Returns the value of attribute publish_formats.
66 67 68 |
# File 'lib/trusty_cms/resource_responses.rb', line 66 def publish_formats @publish_formats end |
Instance Method Details
#default(&block) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/trusty_cms/resource_responses.rb', line 82 def default(&block) if block_given? @default = block end @default end |
#each_format ⇒ Object
104 105 106 107 108 |
# File 'lib/trusty_cms/resource_responses.rb', line 104 def each_format @block_order.each do |format| yield format, @blocks[format] if block_given? end end |
#each_published ⇒ Object
98 99 100 101 102 |
# File 'lib/trusty_cms/resource_responses.rb', line 98 def each_published publish_formats.each do |format| yield format, publish_block if block_given? end end |
#initialize_copy(orig) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/trusty_cms/resource_responses.rb', line 74 def initialize_copy(orig) @publish_formats = orig.publish_formats.dup @blocks = orig.blocks.dup @block_order = orig.block_order.dup @publish_block = orig.publish_block.dup if orig.publish_block @default = orig.default.dup if orig.default end |
#publish(*formats, &block) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/trusty_cms/resource_responses.rb', line 89 def publish(*formats, &block) @publish_formats.concat(formats) if block_given? @publish_block = block else raise ArgumentError, 'Block required to publish' unless @publish_block end end |