Class: Fortitude::Support::AssignsProxy
- Inherits:
-
Object
- Object
- Fortitude::Support::AssignsProxy
- Defined in:
- lib/fortitude/support/assigns_proxy.rb
Instance Method Summary collapse
- #[](x) ⇒ Object
- #[]=(x, y) ⇒ Object
- #has_key?(x) ⇒ Boolean
-
#initialize(widget, keys) ⇒ AssignsProxy
constructor
A new instance of AssignsProxy.
- #inspect ⇒ Object
- #is_default?(x) ⇒ Boolean
- #keys ⇒ Object
- #length ⇒ Object
- #member?(x) ⇒ Boolean
- #size ⇒ Object
- #store(key, value) ⇒ Object
- #to_h ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(widget, keys) ⇒ AssignsProxy
Returns a new instance of AssignsProxy.
6 7 8 9 10 |
# File 'lib/fortitude/support/assigns_proxy.rb', line 6 def initialize(, keys) @widget = @keys = { } keys.each { |k| @keys[k] = true } end |
Instance Method Details
#[](x) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/fortitude/support/assigns_proxy.rb', line 24 def [](x) if has_key?(x) ivar_name = @widget.class.instance_variable_name_for_need(x) @widget.instance_variable_get(ivar_name) end end |
#[]=(x, y) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/fortitude/support/assigns_proxy.rb', line 31 def []=(x, y) if has_key?(x) ivar_name = @widget.class.instance_variable_name_for_need(x) @widget.instance_variable_set(ivar_name, y) end end |
#has_key?(x) ⇒ Boolean
20 21 22 |
# File 'lib/fortitude/support/assigns_proxy.rb', line 20 def has_key?(x) !! @keys[x.to_sym] end |
#inspect ⇒ Object
60 61 62 |
# File 'lib/fortitude/support/assigns_proxy.rb', line 60 def inspect "<Assigns for #{@widget}: #{to_hash.inspect}>" end |
#is_default?(x) ⇒ Boolean
12 13 14 |
# File 'lib/fortitude/support/assigns_proxy.rb', line 12 def is_default?(x) !! @widget._fortitude_default_assigns[x.to_sym] end |
#keys ⇒ Object
16 17 18 |
# File 'lib/fortitude/support/assigns_proxy.rb', line 16 def keys @keys.keys end |
#length ⇒ Object
48 49 50 |
# File 'lib/fortitude/support/assigns_proxy.rb', line 48 def length @keys.length end |
#member?(x) ⇒ Boolean
64 65 66 |
# File 'lib/fortitude/support/assigns_proxy.rb', line 64 def member?(x) has_key?(x) end |
#size ⇒ Object
52 53 54 |
# File 'lib/fortitude/support/assigns_proxy.rb', line 52 def size @keys.size end |
#store(key, value) ⇒ Object
68 69 70 |
# File 'lib/fortitude/support/assigns_proxy.rb', line 68 def store(key, value) self[key] = value end |
#to_h ⇒ Object
44 45 46 |
# File 'lib/fortitude/support/assigns_proxy.rb', line 44 def to_h to_hash end |
#to_hash ⇒ Object
38 39 40 41 42 |
# File 'lib/fortitude/support/assigns_proxy.rb', line 38 def to_hash out = { } keys.each { |k| out[k] = self[k] } out end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/fortitude/support/assigns_proxy.rb', line 56 def to_s "<Assigns for #{@widget}: #{to_hash}>" end |