Module: Clientside::Accessible

Defined in:
lib/clientside.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.cur_osObject

Returns the value of attribute cur_os.



13
14
15
# File 'lib/clientside.rb', line 13

def cur_os
  @cur_os
end

Class Method Details

.included(base) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/clientside.rb', line 15

def included(base)
  base.singleton_class.class_eval do
    attr_reader :js_allowed

    def js_allow(*args)
      (@js_allowed ||= []).concat args
    end
  end
end

.reinflate(json, os) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/clientside.rb', line 25

def reinflate(json, os)
  case json
  when Hash
    if json[:__clientside__]
      os.fetch json[:__clientside_id__]
    else
      Hash[json.map {|k, v| [k, reinflate(v, os)]}]
    end
  when Array
    json.map {|v| reinflate(v, os)}
  else
    json
  end
end

Instance Method Details

#to_json(*args) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/clientside.rb', line 41

def to_json(*args)
  name = self.class.name
  methods = self.class.js_allowed
  h = {__clientside__: true, __clientside_id__: object_id,
       methods: methods}
  h.to_json *args
end