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: 6fe0caf6d8d6ed272cbe66d2b7abf35a01bba4d6
4
- data.tar.gz: f01a17198a3faae4721ea9d826bd89401f9badfa
3
+ metadata.gz: 395f1d5f90055b322bfedc82ae30207741f360f9
4
+ data.tar.gz: 4496d34d31a2414946a6d9a5bde35c921731aa7c
5
5
  SHA512:
6
- metadata.gz: 138e45ed8347cbde1251efef6bb7dee52443e236c6ccaaca36f6c42908e1ab08622286c69289db9a041ae639d34df13aad602004ebf27670675c7244b0c0c342
7
- data.tar.gz: 4fc0b4e9fdaf0dd3055e5c4046e60d3a287a2c8d2ee3b7ba8335363957a7dcbd06f60262ad4b85926b73eeadfbc84f196eadbef3ca14d4e0bc7f439e3b7783e0
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(name: @settingson) and args.first.nil?
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(name: @settingson, value: args.first.to_yaml)
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(name: @settingson)
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(name: @settingson)
53
+ if record = find_by(key: @settingson)
54
54
  record.update(value: args.first.to_yaml)
55
55
  else
56
- create(name: @settingson, value: args.first.to_yaml, settingson: @settingson)
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(name: symbol.to_s)
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
- desc "This generator creates a model and his migration"
3
- def create_migration
4
- generate(:model, "#{name.camelize} name:string value:text")
5
- inject_into_class "app/models/#{name.downcase}.rb", name.camelize, "\tinclude Settingson::Base\n"
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
@@ -0,0 +1,5 @@
1
+ class RenameNameToKeyOnSettings < ActiveRecord::Migration
2
+ def change
3
+ rename_column :settings, :name, :key
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Settingson
2
- VERSION = "1.2.3"
2
+ VERSION = "1.2.10"
3
3
  end
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.3
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-04 00:00:00.000000000 Z
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