settings_on_rails 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/lib/settings_on_rails/base.rb +8 -1
- data/lib/settings_on_rails/configuration.rb +5 -3
- data/lib/settings_on_rails/has_settings.rb +6 -2
- data/lib/settings_on_rails/key_tree_builder.rb +3 -1
- data/lib/settings_on_rails/settings.rb +17 -1
- data/lib/settings_on_rails/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b83c9ecc5fb868616dcd1708d3f5b1c6efec936
|
4
|
+
data.tar.gz: 8a1e64c5f65a24383fab856200b48d4acc0bdb67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0331b4b06617abc42b1b30bb5ad595bfc3db21b121ff8b795a57e32750c6e29e6b2499a79b7dc41d3d9266befbdca74e0788e7f7eb8d0663578606f3f6e24b29
|
7
|
+
data.tar.gz: c91c95f9240c83ec946573063658cc3137f80b31af6444818dfa1ecdb5eb317f588363fa01589730ff369992193faf77c9e2ca3f94b33cefa45ff025f403f80d
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -10,7 +10,14 @@ module SettingsOnRails
|
|
10
10
|
define_method method_name do |*keys|
|
11
11
|
column = Configuration.check!(self)
|
12
12
|
|
13
|
-
Settings.new(keys, self, column, method_name)
|
13
|
+
settings = Settings.new(keys, self, column, method_name)
|
14
|
+
node = settings._current_node
|
15
|
+
|
16
|
+
if node.nil? || node.is_a?(Hash)
|
17
|
+
settings
|
18
|
+
else
|
19
|
+
node
|
20
|
+
end
|
14
21
|
end
|
15
22
|
|
16
23
|
has_settings(&block)
|
@@ -7,12 +7,14 @@ module SettingsOnRails
|
|
7
7
|
# @param [ActiveRecord] klass, the Model who has settings
|
8
8
|
# @param [Symbol] column, the column to store settings
|
9
9
|
def self.init(klass, column)
|
10
|
-
|
10
|
+
unless column.is_a?(Symbol) || column.is_a?(String)
|
11
|
+
raise ArgumentError.new("has_settings_on: symbol or string expected, but got a #{column.class}")
|
12
|
+
end
|
11
13
|
|
12
14
|
klass.class_eval do
|
13
15
|
class_attribute Configuration::NAME_COLUMN, Configuration::DEFAULTS_COLUMN
|
14
16
|
|
15
|
-
serialize column,
|
17
|
+
serialize column, HashWithIndifferentAccess
|
16
18
|
Configuration::init_defaults_column(self)
|
17
19
|
Configuration::init_name_column(self, column)
|
18
20
|
end
|
@@ -37,7 +39,7 @@ module SettingsOnRails
|
|
37
39
|
# init to Hash {} for data attribute in klass if nil
|
38
40
|
def self.init_defaults_column(klass)
|
39
41
|
defaults = klass.send(Configuration::DEFAULTS_COLUMN)
|
40
|
-
klass.send(Configuration::DEFAULTS_COLUMN.to_s + '=',
|
42
|
+
klass.send(Configuration::DEFAULTS_COLUMN.to_s + '=', ActiveSupport::HashWithIndifferentAccess.new) unless defaults
|
41
43
|
end
|
42
44
|
|
43
45
|
def self.init_name_column(klass, column_name)
|
@@ -25,7 +25,9 @@ module SettingsOnRails
|
|
25
25
|
options = keys.extract_options!
|
26
26
|
raise ArgumentError.new("has_settings: Option :defaults expected, but got #{options.keys.join(', ')}") unless options.blank? || (options.keys == [:defaults])
|
27
27
|
keys.each do |key_name|
|
28
|
-
|
28
|
+
unless key_name.is_a?(Symbol) || key_name.is_a?(String)
|
29
|
+
raise ArgumentError.new("has_settings: symbol or string expected, but got a #{key_name.class}")
|
30
|
+
end
|
29
31
|
end
|
30
32
|
|
31
33
|
options[:defaults].each do |k, v|
|
@@ -38,7 +40,9 @@ module SettingsOnRails
|
|
38
40
|
# @param [Symbol] value
|
39
41
|
# @param [Hash] options, options with a default Hash
|
40
42
|
def attr(value, options = {})
|
41
|
-
|
43
|
+
unless value.is_a?(Symbol) || value.is_a?(String)
|
44
|
+
raise ArgumentError.new("has_settings: symbol expected, but got a #{value.class}")
|
45
|
+
end
|
42
46
|
raise ArgumentError.new("has_settings: Option :default expected, but got #{options.keys.join(', ')}") unless options.blank? || (options.keys == [:default])
|
43
47
|
|
44
48
|
default_value = options[:default]
|
@@ -6,7 +6,9 @@ module SettingsOnRails
|
|
6
6
|
# Thus we can differentiate settings(:key).attr and settings(:key, :attr)
|
7
7
|
def initialize(keys, target_obj, target_column_name, parent)
|
8
8
|
keys.each do |key_name|
|
9
|
-
|
9
|
+
unless (key_name.is_a?(Symbol) || key_name.is_a?(String))
|
10
|
+
raise ArgumentError.new("has_settings: symbol or string expected, but got a #{key_name.class}")
|
11
|
+
end
|
10
12
|
end
|
11
13
|
@keys = keys
|
12
14
|
@target_obj = target_obj
|
@@ -21,6 +21,11 @@ module SettingsOnRails
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def method_missing(method_name, *args, &block)
|
24
|
+
if block_given?
|
25
|
+
node = current_node || {}
|
26
|
+
return node.send(method_name, *args, &block)
|
27
|
+
end
|
28
|
+
|
24
29
|
if method_name.to_s =~ REGEX_SETTER && args.size == 1
|
25
30
|
_set_value($1, args.first)
|
26
31
|
elsif method_name.to_s =~ REGEX_GETTER && args.size == 0
|
@@ -31,12 +36,23 @@ module SettingsOnRails
|
|
31
36
|
end
|
32
37
|
end
|
33
38
|
|
39
|
+
# Just a wrapper of current_node
|
40
|
+
def _current_node
|
41
|
+
current_node
|
42
|
+
end
|
43
|
+
|
34
44
|
private
|
35
45
|
|
36
46
|
def _settings(*keys)
|
37
47
|
raise ArgumentError, 'wrong number of arguments (0 for 1..n)' if keys.size == 0
|
48
|
+
settings = Settings.new(keys, @target_object, @column_name, @method_name, self)
|
49
|
+
node = settings._current_node
|
38
50
|
|
39
|
-
|
51
|
+
if node.nil? || node.is_a?(Hash)
|
52
|
+
settings
|
53
|
+
else
|
54
|
+
node
|
55
|
+
end
|
40
56
|
end
|
41
57
|
|
42
58
|
def _get_value(name)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: settings_on_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ALLEN WANG QIANG
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
127
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.4.
|
128
|
+
rubygems_version: 2.4.5
|
129
129
|
signing_key:
|
130
130
|
specification_version: 4
|
131
131
|
summary: Model specific Hash Preferences/Settings for Rails.
|