Class: Fortitude::Support::AssignsProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/fortitude/support/assigns_proxy.rb

Instance Method Summary collapse

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(widget, keys)
  @widget = 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

Returns:

  • (Boolean)


20
21
22
# File 'lib/fortitude/support/assigns_proxy.rb', line 20

def has_key?(x)
  !! @keys[x.to_sym]
end

#inspectObject



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

Returns:

  • (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

#keysObject



16
17
18
# File 'lib/fortitude/support/assigns_proxy.rb', line 16

def keys
  @keys.keys
end

#lengthObject



48
49
50
# File 'lib/fortitude/support/assigns_proxy.rb', line 48

def length
  @keys.length
end

#member?(x) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/fortitude/support/assigns_proxy.rb', line 64

def member?(x)
  has_key?(x)
end

#sizeObject



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_hObject



44
45
46
# File 'lib/fortitude/support/assigns_proxy.rb', line 44

def to_h
  to_hash
end

#to_hashObject



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_sObject



56
57
58
# File 'lib/fortitude/support/assigns_proxy.rb', line 56

def to_s
  "<Assigns for #{@widget}: #{to_hash}>"
end