Class: FirefoxJson::Session::Base
- Inherits:
-
Object
- Object
- FirefoxJson::Session::Base
show all
- Defined in:
- lib/firefox-json/session.rb
Constant Summary
collapse
- @@inherited =
[]
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(data, path: nil) ⇒ Base
Returns a new instance of Base.
9
10
11
12
|
# File 'lib/firefox-json/session.rb', line 9
def initialize data, path: nil
setup data
@path = path
end
|
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
6
7
8
|
# File 'lib/firefox-json/session.rb', line 6
def path
@path
end
|
Class Method Details
.children ⇒ Object
49
50
51
|
# File 'lib/firefox-json/session.rb', line 49
def self.children
@@inherited
end
|
.choose_for(data) ⇒ Object
53
54
55
|
# File 'lib/firefox-json/session.rb', line 53
def self.choose_for data
children.find { |klass| data.key? klass.required_key }
end
|
.inherited(klass) ⇒ Object
45
46
47
|
# File 'lib/firefox-json/session.rb', line 45
def self.inherited klass
@@inherited << klass
end
|
.mattr_accessor(name) ⇒ Object
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/firefox-json/session.rb', line 57
def self.mattr_accessor name
class_eval <<-CODE, __FILE__, __LINE__ + 1
def self.#{name}
@#{name}
end
def #{name}
self.class.#{name}
end
CODE
end
|
.required_key=(key) ⇒ Object
68
69
70
|
# File 'lib/firefox-json/session.rb', line 68
def self.required_key= key
@required_key = key.freeze
end
|
.set_collection(item_class, index_key, with_closed = false) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/firefox-json/session.rb', line 73
def self.set_collection item_class, index_key, with_closed = false
include Collection
@index_key = index_key
@item_class = item_class
base_key_name = item_class.name.split('::')[-1].sub(/y$/, 'ie') + 's'
self.required_key = base_key_name.downcase
define_method @required_key do
@collection
end
if with_closed
@closed_key = "_closed#{base_key_name}"
define_method "closed_#{required_key}" do
@closed_collection
end
end
end
|
Instance Method Details
#dump ⇒ Object
35
36
37
|
# File 'lib/firefox-json/session.rb', line 35
def dump
@data
end
|
#eql?(object) ⇒ Boolean
18
19
20
|
# File 'lib/firefox-json/session.rb', line 18
def eql? object
object.is_a?(self.class) && hash == object.hash
end
|
#inspect ⇒ Object
14
15
16
|
# File 'lib/firefox-json/session.rb', line 14
def inspect
to_s
end
|
#reload ⇒ Object
30
31
32
33
|
# File 'lib/firefox-json/session.rb', line 30
def reload
raise ArgumentError, 'Path not given' unless @path
@data = JsFile.load_file(@path)
end
|
#save(path = nil) ⇒ Object
39
40
41
42
43
|
# File 'lib/firefox-json/session.rb', line 39
def save path=nil
path ||= @path
raise ArgumentError, 'Path not given' unless path
JsFile.save(path, dump)
end
|