settingson 1.2.3 → 1.2.10
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 395f1d5f90055b322bfedc82ae30207741f360f9
|
4
|
+
data.tar.gz: 4496d34d31a2414946a6d9a5bde35c921731aa7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1d6e10072d0e36f4348ee0d9c35b4db498460249f532711993d66a72196b7681331e8f9382152ac3209c10f5a7ae10c95ea1c19d0b6017c3ab67e96be640583
|
7
|
+
data.tar.gz: 013dad12556132fab80b89a89fe8dbfa79b8bb5d1fe358854059e5e3172f60c0340bf5dd974703fb1397a7250cf4df1efd91257726cc59b62cdc276930adb566
|
@@ -19,18 +19,18 @@ module Settingson::Base
|
|
19
19
|
|
20
20
|
@settingson = "#{@settingson}.#{$1}"
|
21
21
|
|
22
|
-
if record = self.class.find_by(
|
22
|
+
if record = self.class.find_by(key: @settingson) and args.first.nil?
|
23
23
|
record.destroy
|
24
24
|
elsif record
|
25
25
|
record.update(value: args.first.to_yaml)
|
26
26
|
else
|
27
|
-
self.class.create(
|
27
|
+
self.class.create(key: @settingson, value: args.first.to_yaml)
|
28
28
|
end
|
29
29
|
|
30
30
|
else # getter
|
31
31
|
|
32
32
|
@settingson += ".#{symbol.to_s}"
|
33
|
-
if record = self.class.find_by(
|
33
|
+
if record = self.class.find_by(key: @settingson)
|
34
34
|
YAML.load(record.value)
|
35
35
|
else
|
36
36
|
self
|
@@ -50,15 +50,15 @@ module Settingson::Base
|
|
50
50
|
|
51
51
|
@settingson = $1
|
52
52
|
|
53
|
-
if record = find_by(
|
53
|
+
if record = find_by(key: @settingson)
|
54
54
|
record.update(value: args.first.to_yaml)
|
55
55
|
else
|
56
|
-
create(
|
56
|
+
create(key: @settingson, value: args.first.to_yaml, settingson: @settingson)
|
57
57
|
end
|
58
58
|
|
59
59
|
else # getter
|
60
60
|
|
61
|
-
if record = find_by(
|
61
|
+
if record = find_by(key: symbol.to_s)
|
62
62
|
YAML.load record.value
|
63
63
|
else
|
64
64
|
new(settingson: symbol.to_s)
|
@@ -1,7 +1,35 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
1
2
|
class SettingsonGenerator < Rails::Generators::NamedBase
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
include Rails::Generators::Migration
|
4
|
+
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
desc "This generator creates a model and its migration"
|
8
|
+
def settingson_migration
|
9
|
+
klass = name.camelize
|
10
|
+
say "Searching for #{klass.constantize.inspect}"
|
11
|
+
if Object.const_defined?(klass)
|
12
|
+
|
13
|
+
settingson_inject_lines(name)
|
14
|
+
|
15
|
+
if klass.constantize.column_names.include?('name')
|
16
|
+
migration_template 'migrations/rename_name_to_key_on_settings.rb', 'db/migrate/rename_name_to_key_on_settings.rb'
|
17
|
+
end
|
18
|
+
|
19
|
+
else
|
20
|
+
generate(:model, "#{klass} key:string value:text")
|
21
|
+
settingson_inject_lines(name)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.next_migration_number dirname
|
26
|
+
ActiveRecord::Generators::Base.next_migration_number dirname
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def settingson_inject_lines(name)
|
31
|
+
if File.readlines("app/models/#{name.downcase}.rb").grep(/\A\s*include Settingson::Base\z/).blank?
|
32
|
+
inject_into_class "app/models/#{name.downcase}.rb", name.camelize, "\tinclude Settingson::Base\n"
|
33
|
+
end
|
6
34
|
end
|
7
35
|
end
|
data/lib/settingson/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: settingson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- Rakefile
|
53
53
|
- app/models/concerns/settingson/base.rb
|
54
54
|
- lib/generators/settingson/settingson_generator.rb
|
55
|
+
- lib/generators/settingson/templates/migrations/rename_name_to_key_on_settings.rb
|
55
56
|
- lib/settingson.rb
|
56
57
|
- lib/settingson/engine.rb
|
57
58
|
- lib/settingson/store.rb
|