settingify 0.0.4 → 0.0.5

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: 94d92a3f44c051e69e85ffaec7d69028ec7ed1f8
4
- data.tar.gz: 0ef9c8d16d8c5fc549fc30ac0867db0b4f6f3339
3
+ metadata.gz: 78917b39693aa3208f0b77624d23c7d516fb05f4
4
+ data.tar.gz: 61fc063e16226665cac720deec8892c47c5c773b
5
5
  SHA512:
6
- metadata.gz: 59aae6e64a0de758d4c6b9ce48793ee44ff16bbea0e79fe422c68d310c540f2517ba5202ec331410178d90d2e91bab3e7f6123134e07ba412d1f0fd2482f2a31
7
- data.tar.gz: 266e0dde7325e20dc718b49107048e86e3cca96201a51d38c8613d7c410bd88e74273777e7766bc765b362e829555d56e003a6face19b9b0fa4eb83b46a5407f
6
+ metadata.gz: 483dd18811eaa3a63c23bc641a2e01c9619afbecfb62ceb94bd7e3d07054163af91fb33219ea289b890c6f2ca0560ee34ce5016261b2f066f6e984264354362d
7
+ data.tar.gz: 58f61a3f792544c114b4adf814c282ea570aa2498f615366bcf14f72751ef6ee489f1e5345e1686964cc924aa7d699e41c174783991b85935e00be6828d0aa27
data/.gitignore CHANGED
@@ -21,3 +21,5 @@ tmp
21
21
  *.a
22
22
  mkmf.log
23
23
  .rvmrc
24
+ tmp
25
+ spec/tmp
data/README.md CHANGED
@@ -16,7 +16,7 @@ rails g active_admin:resource Settingify::Setting
16
16
 
17
17
  Add this line to your application's Gemfile:
18
18
 
19
- gem 'settingify', '0.0.4'
19
+ gem 'settingify', '0.0.5'
20
20
 
21
21
  And then execute:
22
22
 
@@ -24,7 +24,7 @@ And then execute:
24
24
 
25
25
  Or install it yourself as:
26
26
 
27
- $ gem install settingify -v 0.0.4
27
+ $ gem install settingify -v 0.0.5
28
28
 
29
29
  ### Post installation
30
30
 
@@ -133,6 +133,31 @@ settingify.groups.{KEY}.title
133
133
  Grouping was coming mainly for to be able to more clear render settings
134
134
  in admin panel but also with keeping in mind about next enhancements.
135
135
 
136
+ ## Localization feature
137
+
138
+ [Read there](https://github.com/alterego-labs/settingify/wiki/Localization-feature)
139
+
140
+ ## Testing
141
+
142
+ Because localization feature affects on Setting class by unchangable
143
+ traco logic includance to run all specs you must run several commands:
144
+
145
+ ```
146
+ rspec spec/lib
147
+ ```
148
+
149
+ and
150
+
151
+ ```
152
+ rspec spec/localized_settingify_spec.rb
153
+ ```
154
+
155
+ Or you can run they by single command:
156
+
157
+ ```
158
+ rake spec
159
+ ```
160
+
136
161
  ## Contributing
137
162
 
138
163
  1. Fork it ( https://github.com/alterego-labs/settingify/fork )
data/Rakefile CHANGED
@@ -2,9 +2,14 @@ require "rubygems"
2
2
  require 'rspec/core/rake_task'
3
3
  require 'rubygems/specification'
4
4
 
5
- task default: :spec
6
5
  desc "Run specs"
7
- RSpec::Core::RakeTask.new do |t|
8
- t.pattern = FileList['spec/**/*_spec.rb']
9
- t.rspec_opts = %w(--color)
6
+ task :spec do
7
+ RSpec::Core::RakeTask.new do |t|
8
+ t.pattern = FileList['spec/lib/**/*_spec.rb']
9
+ t.rspec_opts = %w(--colour)
10
+ end
11
+ RSpec::Core::RakeTask.new do |t|
12
+ t.pattern = FileList['spec/localized_settingify_spec.rb']
13
+ t.rspec_opts = %w(--colour)
14
+ end
10
15
  end
@@ -7,6 +7,9 @@ module Settingify
7
7
  source_root File.expand_path('../templates', __FILE__)
8
8
  desc "Add migration and copy initializer"
9
9
 
10
+ class_option :localization, type: :boolean, default: false, desc: 'Enable or disable localization feature.'
11
+ class_option :locales, type: :string, default: '', desc: 'List of available locales. Separated by comma'
12
+
10
13
  def self.next_migration_number(path)
11
14
  unless @prev_migration_nr
12
15
  @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
@@ -16,8 +19,19 @@ module Settingify
16
19
  @prev_migration_nr.to_s
17
20
  end
18
21
 
22
+ def setup_localization
23
+ if options[:localization]
24
+ Settingify.config do |config|
25
+ config.localization do |localization|
26
+ localization.active = options[:localization]
27
+ localization.available_locales = options[:locales].split(',').map(&:to_sym)
28
+ end
29
+ end
30
+ end
31
+ end
32
+
19
33
  def copy_migrations
20
- migration_template "create_settingify_setting.rb", "db/migrate/create_settingify_setting.rb"
34
+ migration_template "create_settingify_setting.rb.erb", "db/migrate/create_settingify_setting.rb"
21
35
  end
22
36
 
23
37
  def copy_initializer
@@ -0,0 +1,16 @@
1
+ class CreateSettingifySetting < ActiveRecord::Migration
2
+ def change
3
+ create_table Settingify::TABLE_NAME do |t|
4
+ t.string :key
5
+ t.string :description
6
+ <% if Settingify.config.localization.active %>
7
+ <% Settingify.config.localization.available_locales.each do |locale| %>
8
+ <%= "t.string :value_#{locale}" %>
9
+ <% end %>
10
+ <% else %>
11
+ t.string :value
12
+ <% end %>
13
+ t.timestamps
14
+ end
15
+ end
16
+ end
@@ -1,4 +1,19 @@
1
+ Settingify.config do |config|
2
+ # Uncomment if you want to use localization feature.
3
+ # For more information visit `lib/settingify/configs/localization.rb`
4
+ #
5
+ #config.localization do |localization|
6
+ #localization.active = false
7
+ #localization.available_locales = []
8
+ #end
9
+ end
10
+
1
11
  Settingify.prepare_settings do
2
- # Your settings will be here
12
+ # # Your settings will be here:
3
13
  # setting :my_setting, type: String, default: 'msg'
14
+ #
15
+ # # or you may to define grouped settings:
16
+ # group :general do
17
+ # setting :grouped_setting, default: 'grouped_setting_value'
18
+ # end
4
19
  end
@@ -0,0 +1,32 @@
1
+ module Settingify
2
+ module Configs
3
+ class Localization
4
+ #
5
+ # Specifies if localization feature either is active or not.
6
+ #
7
+ # Values:
8
+ # true/false
9
+ #
10
+ # Default:
11
+ # false
12
+ #
13
+ attr_accessor :active
14
+
15
+ #
16
+ # Contains locales array for that settingify must provides localized settings.
17
+ #
18
+ # Values:
19
+ # array of symbols
20
+ #
21
+ # Default:
22
+ # empty array
23
+ #
24
+ attr_accessor :available_locales
25
+
26
+ def initialize
27
+ @active = false
28
+ @available_locales = []
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,10 @@
1
+ module Settingify
2
+ module Configs
3
+ class Main
4
+ def localization(&block)
5
+ @_localization_config ||= Configs::Localization.new
6
+ block_given? ? yield(@_localization_config) : @_localization_config
7
+ end
8
+ end
9
+ end
10
+ end
@@ -2,6 +2,10 @@ module Settingify
2
2
  class Setting < ActiveRecord::Base
3
3
  self.table_name_prefix = 'settingify_'
4
4
 
5
+ if Settingify.config.localization.active
6
+ translates :value, fallback: false
7
+ end
8
+
5
9
  def title
6
10
  I18n.t("settingify.settings.#{self.key}.title", self.key.to_s.humanize)
7
11
  end
@@ -1,3 +1,3 @@
1
1
  module Settingify
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/settingify.rb CHANGED
@@ -7,6 +7,8 @@ require "settingify/version"
7
7
  require 'settingify/railtie' if defined?(Rails)
8
8
  require 'settingify/errors'
9
9
 
10
+ require 'traco'
11
+
10
12
  module Settingify
11
13
  extend ActiveSupport::Autoload
12
14
 
@@ -36,10 +38,22 @@ module Settingify
36
38
  autoload :Settings
37
39
  end
38
40
 
41
+ module Configs
42
+ extend ActiveSupport::Autoload
43
+
44
+ autoload :Main
45
+ autoload :Localization
46
+ end
47
+
39
48
  extend SettingsPreparable
40
49
 
41
50
  include Constants
42
51
 
52
+ def self.config(&block)
53
+ @_main_config ||= Configs::Main.new
54
+ block_given? ? yield(@_main_config) : @_main_config
55
+ end
56
+
43
57
  def self.registered_settings
44
58
  Repos::Settings.instance.list
45
59
  end
data/settingify.gemspec CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_dependency "traco", "3.1.6"
22
+
21
23
  spec.add_development_dependency "activesupport", ">= 4.0.4"
22
24
  spec.add_development_dependency "activerecord", ">= 4.0.4"
23
25
  spec.add_development_dependency "activemodel", ">= 4.0.4"
@@ -29,5 +31,7 @@ Gem::Specification.new do |spec|
29
31
  spec.add_development_dependency "rspec-its", "1.2.0"
30
32
  spec.add_development_dependency "pry-nav", "0.2.3"
31
33
  spec.add_development_dependency 'sqlite3'
34
+ spec.add_development_dependency 'generator_spec', '0.9.3'
35
+
32
36
  spec.add_development_dependency 'json', '1.8.3'
33
37
  end
@@ -0,0 +1,10 @@
1
+ ActiveRecord::Schema.define do
2
+ create_table "settingify_settings", force: true do |t|
3
+ t.string "key"
4
+ t.string "value_fr"
5
+ t.string "value_nl"
6
+ t.string "description"
7
+ t.datetime "created_at"
8
+ t.datetime "updated_at"
9
+ end
10
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ require File.join(Dir.pwd, 'lib/generators/settingify/install/install_generator.rb')
4
+
5
+ describe Settingify::Generators::InstallGenerator, type: :generator do
6
+ destination File.expand_path("../../../../../tmp", __FILE__)
7
+
8
+ context 'when localization is disabled' do
9
+ before do
10
+ prepare_destination
11
+ run_generator
12
+ end
13
+
14
+ specify do
15
+ expect(destination_root).to have_structure {
16
+ directory 'config' do
17
+ directory 'initializers' do
18
+ file 'settingify.rb' do
19
+ contains "Settingify.config"
20
+ contains "Settingify.prepare_settings"
21
+ end
22
+ end
23
+ end
24
+ directory 'db' do
25
+ directory 'migrate' do
26
+ migration 'create_settingify_setting' do
27
+ contains "t.string :value"
28
+ end
29
+ end
30
+ end
31
+ }
32
+ end
33
+ end
34
+
35
+ context 'when localization is enabled' do
36
+ before do
37
+ Settingify.config.localization.available_locales = [:fr, :nl]
38
+ Settingify.config.localization.active = true
39
+ prepare_destination
40
+ run_generator
41
+ end
42
+
43
+ after do
44
+ Settingify.config.localization.available_locales = []
45
+ Settingify.config.localization.active = false
46
+ end
47
+
48
+ specify do
49
+ expect(destination_root).to have_structure {
50
+ directory 'config' do
51
+ directory 'initializers' do
52
+ file 'settingify.rb' do
53
+ contains "Settingify.config"
54
+ contains "Settingify.prepare_settings"
55
+ end
56
+ end
57
+ end
58
+ directory 'db' do
59
+ directory 'migrate' do
60
+ migration 'create_settingify_setting' do
61
+ contains "t.string :value_fr"
62
+ contains "t.string :value_nl"
63
+ end
64
+ end
65
+ end
66
+ }
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Settingify::Configs::Localization do
4
+ describe 'default values' do
5
+ subject { described_class.new }
6
+
7
+ its(:active) { is_expected.to be_falsey }
8
+ its(:available_locales) { is_expected.to be_empty }
9
+ end
10
+
11
+ describe 'available attributes' do
12
+ it { is_expected.to respond_to :active= }
13
+ it { is_expected.to respond_to :available_locales= }
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Settingify::Configs::Main do
4
+ it { is_expected.to respond_to :localization }
5
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ class Settingify::Setting
4
+ translates :value, fallback: false
5
+ end
6
+
7
+ describe Settingify do
8
+ context 'localized feature' do
9
+ before do
10
+ load 'spec/db/localized_schema.rb'
11
+ Settingify.config do |config|
12
+ config.localization do |localization|
13
+ localization.active = true
14
+ localization.available_locales = [:fr, :nl]
15
+ end
16
+ end
17
+ Settingify::Repos::Settings.instance.clear!
18
+ I18n.locale = :fr
19
+ Settingify::Setting.create(key: :localized, value: :fr_localized)
20
+ Settingify.prepare_settings do
21
+ setting :localized, default: :unlocalized
22
+ end
23
+ end
24
+
25
+ after do
26
+ Settingify.config do |config|
27
+ config.localization do |localization|
28
+ localization.active = false
29
+ end
30
+ end
31
+ end
32
+
33
+ context 'when current locale is nl' do
34
+ it 'returns blank string' do
35
+ I18n.locale = :nl
36
+ expect(Settingify.localized).to be_blank
37
+ end
38
+ end
39
+ end
40
+ end
data/spec/spec_helper.rb CHANGED
@@ -6,6 +6,7 @@ ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
6
6
  load 'db/schema.rb'
7
7
 
8
8
  require 'rspec/its'
9
+ require 'generator_spec'
9
10
  require 'settingify'
10
11
  require 'pry-nav'
11
12
 
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: settingify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Gernyak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-14 00:00:00.000000000 Z
11
+ date: 2016-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: traco
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.6
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: activesupport
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +164,20 @@ dependencies:
150
164
  - - ">="
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: generator_spec
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '='
172
+ - !ruby/object:Gem::Version
173
+ version: 0.9.3
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '='
179
+ - !ruby/object:Gem::Version
180
+ version: 0.9.3
153
181
  - !ruby/object:Gem::Dependency
154
182
  name: json
155
183
  requirement: !ruby/object:Gem::Requirement
@@ -177,12 +205,14 @@ files:
177
205
  - README.md
178
206
  - Rakefile
179
207
  - lib/generators/settingify/install/install_generator.rb
180
- - lib/generators/settingify/install/templates/create_settingify_setting.rb
208
+ - lib/generators/settingify/install/templates/create_settingify_setting.rb.erb
181
209
  - lib/generators/settingify/install/templates/settingify.rb
182
210
  - lib/settingify.rb
183
211
  - lib/settingify/active_record_helpers.rb
184
212
  - lib/settingify/builders/group.rb
185
213
  - lib/settingify/caster.rb
214
+ - lib/settingify/configs/localization.rb
215
+ - lib/settingify/configs/main.rb
186
216
  - lib/settingify/constants.rb
187
217
  - lib/settingify/contract_ext.rb
188
218
  - lib/settingify/db_reader.rb
@@ -199,7 +229,11 @@ files:
199
229
  - lib/settingify/tasks/settingify.rake
200
230
  - lib/settingify/version.rb
201
231
  - settingify.gemspec
232
+ - spec/db/localized_schema.rb
202
233
  - spec/db/schema.rb
234
+ - spec/lib/generators/settingify/install/install_generator_spec.rb
235
+ - spec/lib/settingify/configs/localization_spec.rb
236
+ - spec/lib/settingify/configs/main_spec.rb
203
237
  - spec/lib/settingify/db_syncer_spec.rb
204
238
  - spec/lib/settingify/group_spec.rb
205
239
  - spec/lib/settingify/reader_spec.rb
@@ -208,6 +242,7 @@ files:
208
242
  - spec/lib/settingify/setting_builder_spec.rb
209
243
  - spec/lib/settingify/setting_spec.rb
210
244
  - spec/lib/settingify_spec.rb
245
+ - spec/localized_settingify_spec.rb
211
246
  - spec/spec_helper.rb
212
247
  homepage: https://github.com/alterego-labs/settingify
213
248
  licenses:
@@ -234,7 +269,11 @@ signing_key:
234
269
  specification_version: 4
235
270
  summary: Global setting system for Rails
236
271
  test_files:
272
+ - spec/db/localized_schema.rb
237
273
  - spec/db/schema.rb
274
+ - spec/lib/generators/settingify/install/install_generator_spec.rb
275
+ - spec/lib/settingify/configs/localization_spec.rb
276
+ - spec/lib/settingify/configs/main_spec.rb
238
277
  - spec/lib/settingify/db_syncer_spec.rb
239
278
  - spec/lib/settingify/group_spec.rb
240
279
  - spec/lib/settingify/reader_spec.rb
@@ -243,4 +282,5 @@ test_files:
243
282
  - spec/lib/settingify/setting_builder_spec.rb
244
283
  - spec/lib/settingify/setting_spec.rb
245
284
  - spec/lib/settingify_spec.rb
285
+ - spec/localized_settingify_spec.rb
246
286
  - spec/spec_helper.rb
@@ -1,10 +0,0 @@
1
- class CreateSettingifySetting < ActiveRecord::Migration
2
- def change
3
- create_table Settingify::TABLE_NAME do |t|
4
- t.string :key
5
- t.string :value
6
- t.string :description
7
- t.timestamps
8
- end
9
- end
10
- end