Class: Xipai::Arrangement::Base
- Inherits:
-
Object
- Object
- Xipai::Arrangement::Base
show all
- Defined in:
- lib/xipai/arrangement/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(_params) ⇒ Base
Returns a new instance of Base.
39
40
41
|
# File 'lib/xipai/arrangement/base.rb', line 39
def initialize(_params)
@params = _params
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
43
44
45
46
47
48
49
50
51
|
# File 'lib/xipai/arrangement/base.rb', line 43
def method_missing(method, *args)
before, result = method_missing_hook(method, *args)
if before
return result
elsif params.has_key?(:"#{method}")
return params[:"#{method}"]
end
super
end
|
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
10
11
12
|
# File 'lib/xipai/arrangement/base.rb', line 10
def params
@params
end
|
Class Method Details
.attributes(*attrs) ⇒ Object
13
14
15
16
|
# File 'lib/xipai/arrangement/base.rb', line 13
def attributes(*attrs)
define_method(:"__attributes__") {attrs}
private :"__attributes__"
end
|
.require_attributes(*attrs) ⇒ Object
18
19
20
21
|
# File 'lib/xipai/arrangement/base.rb', line 18
def require_attributes(*attrs)
define_method(:"__require_attributes__") {attrs}
private :"__require_attributes__"
end
|
Instance Method Details
#__attributes__ ⇒ Object
28
29
30
|
# File 'lib/xipai/arrangement/base.rb', line 28
def __attributes__
end
|
#__require_attributes__ ⇒ Object
24
25
26
|
# File 'lib/xipai/arrangement/base.rb', line 24
def __require_attributes__
end
|
#dump_replay_yaml(path) ⇒ Object
63
64
65
66
67
|
# File 'lib/xipai/arrangement/base.rb', line 63
def dump_replay_yaml(path)
raise "Error: replay_yaml path is nil." if path.nil?
FileUtils.mkdir_p(File.dirname(path))
YAML.dump(self.to_replay_data, File.open(path, "w"))
end
|
#method_missing_hook(method, *args) ⇒ Object
53
54
55
|
# File 'lib/xipai/arrangement/base.rb', line 53
def method_missing_hook(method, *args)
return false, nil
end
|
#to_replay_data ⇒ Object
57
58
59
60
61
|
# File 'lib/xipai/arrangement/base.rb', line 57
def to_replay_data
return __attributes__.inject({}) do |memo, attribute_name|
memo[attribute_name] = params[attribute_name]
end
end
|
#valid! ⇒ Object
32
33
34
35
36
37
|
# File 'lib/xipai/arrangement/base.rb', line 32
def valid!()
__require_attributes__.each do |key|
raise "Error: params-#{key} is null value." if [[],{},"",nil].include?(params[key])
end
return true
end
|