Module: Krakow::Utils::Lazy::ClassMethods
- Included in:
- Distribution, FrameType, Producer::Http
- Defined in:
- lib/krakow/utils/lazy.rb
Overview
Class methods for laziness
Instance Method Summary collapse
-
#attribute(name, type, options = {}) ⇒ nil
Add new attributes to class.
-
#attributes(*args) ⇒ Array<Hash>
Return attributes.
-
#set_attributes(attrs) ⇒ TrueClass
Directly set attribute hash.
Instance Method Details
#attribute(name, type, options = {}) ⇒ nil
Add new attributes to class
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/krakow/utils/lazy.rb', line 62 def attribute(name, type, ={}) name = name.to_sym attributes[name] = {:type => type}.merge() define_method(name) do arguments[name.to_sym] end define_method("#{name}?") do !!arguments[name.to_sym] end nil end |
#attributes(*args) ⇒ Array<Hash>
Return attributes
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/krakow/utils/lazy.rb', line 78 def attributes(*args) @attributes ||= {} if(args.include?(:required)) Hash[@attributes.find_all{|k,v| v[:required]}] elsif(args.include?(:optional)) Hash[@attributes.find_all{|k,v| !v[:required]}] else @attributes end end |
#set_attributes(attrs) ⇒ TrueClass
TODO:
need deep dup here
Directly set attribute hash
94 95 96 97 |
# File 'lib/krakow/utils/lazy.rb', line 94 def set_attributes(attrs) @attributes = attrs.dup true end |