Class: Goat::ComponentSkeleton
Class Method Summary collapse
Instance Method Summary collapse
-
#cls ⇒ Object
in which we fail at DRY:.
- #dom ⇒ Object
- #dom=(d) ⇒ Object
- #ensure_keys(h, spec) ⇒ Object
- #id ⇒ Object
-
#initialize(h = {}) ⇒ ComponentSkeleton
constructor
A new instance of ComponentSkeleton.
- #live_spec ⇒ Object
- #live_state ⇒ Object
- #live_state=(s) ⇒ Object
- #pgid ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(h = {}) ⇒ ComponentSkeleton
Returns a new instance of ComponentSkeleton.
25 26 27 28 29 30 |
# File 'lib/goat/common.rb', line 25 def initialize(h={}) ensure_keys(h, :required => %w{pgid class id live_spec live_state dom}, :optional => [] ) @hash = h end |
Class Method Details
.from_hash(h) ⇒ Object
43 44 45 46 47 |
# File 'lib/goat/common.rb', line 43 def self.from_hash(h) hash = h.clone hash['dom'] = Marshal.load(h['dom']) self.new(hash) end |
Instance Method Details
#cls ⇒ Object
in which we fail at DRY:
33 |
# File 'lib/goat/common.rb', line 33 def cls; @hash['class']; end |
#dom ⇒ Object
38 |
# File 'lib/goat/common.rb', line 38 def dom; @hash['dom']; end |
#dom=(d) ⇒ Object
40 |
# File 'lib/goat/common.rb', line 40 def dom=(d); @hash['dom'] = d; end |
#ensure_keys(h, spec) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/goat/common.rb', line 14 def ensure_keys(h, spec) hash = h.clone spec[:required].each do |k| raise "#{k} not present" unless h.include?(k) hash.delete(k) end spec[:optional].each {|k| hash.delete(k)} raise "Unknown keys supplied: #{hash.keys.join(', ')}" unless hash.keys.empty? end |
#id ⇒ Object
35 |
# File 'lib/goat/common.rb', line 35 def id; @hash['id']; end |
#live_spec ⇒ Object
36 |
# File 'lib/goat/common.rb', line 36 def live_spec; @hash['live_spec']; end |
#live_state ⇒ Object
37 |
# File 'lib/goat/common.rb', line 37 def live_state; @hash['live_state']; end |
#live_state=(s) ⇒ Object
41 |
# File 'lib/goat/common.rb', line 41 def live_state=(s); @hash['live_state'] = s; end |
#pgid ⇒ Object
34 |
# File 'lib/goat/common.rb', line 34 def pgid; @hash['pgid']; end |
#to_hash ⇒ Object
49 50 51 52 53 |
# File 'lib/goat/common.rb', line 49 def to_hash hash = @hash.clone hash['dom'] = Marshal.dump(@hash['dom']) hash end |