Module: DataProvider::Base::InstanceMethods
- Defined in:
- lib/data_provider/base.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #add(_module) ⇒ Object
- #add!(_module) ⇒ Object
- #add_scoped(_module, options = {}) ⇒ Object
- #add_scoped!(_module, options = {}) ⇒ Object
- #data_provider_container ⇒ Object (also: #dpc)
- #give(*args) ⇒ Object (also: #add_scope, #add_data)
- #initialize(opts = {}) ⇒ Object
- #logger ⇒ Object
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
154 155 156 |
# File 'lib/data_provider/base.rb', line 154 def @options end |
Instance Method Details
#add(_module) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/data_provider/base.rb', line 176 def add _module if _module.is_a?(DataProvider::Container) _dpc = _module else _dpc = _module.dpc self.class.class_eval do include _module # todo: make optional? end end self.class.new(.merge({ :data => nil, :dpc => dpc.add(_dpc) })) end |
#add!(_module) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/data_provider/base.rb', line 215 def add! _module if _module.is_a?(DataProvider::Container) dpc.add!(_module) else dpc.add!(_module.dpc) self.class.class_eval do include _module end end return self end |
#add_scoped(_module, options = {}) ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/data_provider/base.rb', line 192 def add_scoped _module, = {} if _module.is_a?(DataProvider::Container) _dpc = _module else _dpc = _module.dpc self.class.class_eval do include _module # todo: make optional? end end self.class.new(.merge({ :data => nil, :dpc => dpc.add_scoped(_dpc, :scope => [:scope]) })) end |
#add_scoped!(_module, options = {}) ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/data_provider/base.rb', line 228 def add_scoped! _module, = {} if _module.is_a?(DataProvider::Container) dpc.add_scoped!(_module, ) else dpc.add_scoped! _module.dpc, self.class.class_eval do include _module end end return self end |
#data_provider_container ⇒ Object Also known as: dpc
167 168 169 170 171 172 |
# File 'lib/data_provider/base.rb', line 167 def data_provider_container @data_provider_container ||= [:dpc] || DataProvider::Container.new.tap do |c| # automatically adopt all class-level providers/provides/data c.add! self.class.dpc end end |
#give(*args) ⇒ Object Also known as: add_scope, add_data
208 209 210 |
# File 'lib/data_provider/base.rb', line 208 def give *args self.class.new(.merge(:data => nil, :dpc => self.dpc.give(*args))) end |
#initialize(opts = {}) ⇒ Object
156 157 158 159 |
# File 'lib/data_provider/base.rb', line 156 def initialize(opts = {}) @options = opts.is_a?(Hash) ? opts : {} dpc.give!([:data]) if [:data].is_a?(Hash) end |
#logger ⇒ Object
161 162 163 164 165 |
# File 'lib/data_provider/base.rb', line 161 def logger @logger ||= [:logger] || Logger.new(STDOUT).tap do |lger| lger.level = Logger::WARN end end |