Module: PostJson::SettingsMethods::ClassMethods
- Defined in:
- lib/post_json/concerns/settings_methods.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_symbol, *args, &block) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/post_json/concerns/settings_methods.rb', line 127
def method_missing(method_symbol, *args, &block)
method = method_symbol.to_s
if method.start_with?("meta_") && method.end_with?("=") && args.length == 1
attribute_name = method[5..-2]
self.meta = self.meta.merge(attribute_name => args[0])
args[0]
elsif method.start_with?("meta_") && args.length == 0
attribute_name = method[5..-1]
self.meta[attribute_name]
else
super
end
end
|
Instance Method Details
#create_dynamic_index_milliseconds_threshold ⇒ Object
119
120
121
|
# File 'lib/post_json/concerns/settings_methods.rb', line 119
def create_dynamic_index_milliseconds_threshold
read_settings_attribute('create_dynamic_index_milliseconds_threshold')
end
|
#create_dynamic_index_milliseconds_threshold=(millisecs) ⇒ Object
123
124
125
|
# File 'lib/post_json/concerns/settings_methods.rb', line 123
def create_dynamic_index_milliseconds_threshold=(millisecs)
write_settings_attribute('create_dynamic_index_milliseconds_threshold', millisecs)
end
|
#created_at_attribute_name ⇒ Object
79
80
81
|
# File 'lib/post_json/concerns/settings_methods.rb', line 79
def created_at_attribute_name
read_settings_attribute('created_at_attribute_name')
end
|
#created_at_attribute_name=(attribute_name) ⇒ Object
83
84
85
|
# File 'lib/post_json/concerns/settings_methods.rb', line 83
def created_at_attribute_name=(attribute_name)
write_settings_attribute('created_at_attribute_name', attribute_name)
end
|
#destroy! ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/post_json/concerns/settings_methods.rb', line 37
def destroy!
if persisted?
settings.destroy
reload_settings!
else
settings
end
end
|
#include_version_number ⇒ Object
95
96
97
|
# File 'lib/post_json/concerns/settings_methods.rb', line 95
def include_version_number
read_settings_attribute('include_version_number')
end
|
#include_version_number=(value) ⇒ Object
99
100
101
|
# File 'lib/post_json/concerns/settings_methods.rb', line 99
def include_version_number=(value)
write_settings_attribute('include_version_number', value)
end
|
60
61
62
|
# File 'lib/post_json/concerns/settings_methods.rb', line 60
def meta
HashWithIndifferentAccess.new(read_settings_attribute('meta'))
end
|
64
65
66
|
# File 'lib/post_json/concerns/settings_methods.rb', line 64
def meta=(hash)
write_settings_attribute('meta', HashWithIndifferentAccess.new(hash))
end
|
#new? ⇒ Boolean
24
25
26
|
# File 'lib/post_json/concerns/settings_methods.rb', line 24
def new?
settings.new_record?
end
|
#persisted? ⇒ Boolean
28
29
30
|
# File 'lib/post_json/concerns/settings_methods.rb', line 28
def persisted?
settings.persisted?
end
|
#persisted_settings ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/post_json/concerns/settings_methods.rb', line 10
def persisted_settings
if settings.new_record?
existing = ModelSettings.by_collection(collection_name).first
if existing
updates = settings.changes.inject({}) {|result, (k,v)| result[k] = v[1]; result}
existing.update_attributes(updates)
@settings = existing
else
settings.save!
end
end
settings
end
|
#read_settings_attribute(attribute_name) ⇒ Object
46
47
48
49
|
# File 'lib/post_json/concerns/settings_methods.rb', line 46
def read_settings_attribute(attribute_name)
attribute_name = attribute_name.to_s
settings[attribute_name]
end
|
#reload_settings! ⇒ Object
32
33
34
35
|
# File 'lib/post_json/concerns/settings_methods.rb', line 32
def reload_settings!
@settings = nil
settings
end
|
#settings ⇒ Object
6
7
8
|
# File 'lib/post_json/concerns/settings_methods.rb', line 6
def settings
@settings ||= ModelSettings.by_collection(collection_name).first_or_initialize(collection_name: collection_name)
end
|
#updated_at_attribute_name ⇒ Object
87
88
89
|
# File 'lib/post_json/concerns/settings_methods.rb', line 87
def updated_at_attribute_name
read_settings_attribute('updated_at_attribute_name')
end
|
#updated_at_attribute_name=(attribute_name) ⇒ Object
91
92
93
|
# File 'lib/post_json/concerns/settings_methods.rb', line 91
def updated_at_attribute_name=(attribute_name)
write_settings_attribute('updated_at_attribute_name', attribute_name)
end
|
#use_dynamic_index ⇒ Object
111
112
113
|
# File 'lib/post_json/concerns/settings_methods.rb', line 111
def use_dynamic_index
read_settings_attribute('use_dynamic_index')
end
|
#use_dynamic_index=(value) ⇒ Object
115
116
117
|
# File 'lib/post_json/concerns/settings_methods.rb', line 115
def use_dynamic_index=(value)
write_settings_attribute('use_dynamic_index', value)
end
|
#use_timestamps ⇒ Object
Also known as:
record_timestamps
68
69
70
|
# File 'lib/post_json/concerns/settings_methods.rb', line 68
def use_timestamps
read_settings_attribute('use_timestamps')
end
|
#use_timestamps=(value) ⇒ Object
Also known as:
record_timestamps=
72
73
74
|
# File 'lib/post_json/concerns/settings_methods.rb', line 72
def use_timestamps=(value)
write_settings_attribute('use_timestamps', value)
end
|
#version_attribute_name ⇒ Object
103
104
105
|
# File 'lib/post_json/concerns/settings_methods.rb', line 103
def version_attribute_name
read_settings_attribute('version_attribute_name')
end
|
#version_attribute_name=(attribute_name) ⇒ Object
107
108
109
|
# File 'lib/post_json/concerns/settings_methods.rb', line 107
def version_attribute_name=(attribute_name)
write_settings_attribute('version_attribute_name', attribute_name)
end
|
#write_settings_attribute(attribute_name, value) ⇒ Object
51
52
53
54
55
56
57
58
|
# File 'lib/post_json/concerns/settings_methods.rb', line 51
def write_settings_attribute(attribute_name, value)
attribute_name = attribute_name.to_s
if settings[attribute_name] != value
settings[attribute_name] = value
settings.save!
end
value
end
|