settingify 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +105 -0
- data/Rakefile +18 -0
- data/lib/generators/settingify/install/install_generator.rb +28 -0
- data/lib/generators/settingify/install/templates/create_settingify_setting.rb +10 -0
- data/lib/generators/settingify/install/templates/settingify.rb +4 -0
- data/lib/settingify/active_record_helpers.rb +9 -0
- data/lib/settingify/caster.rb +20 -0
- data/lib/settingify/constants.rb +5 -0
- data/lib/settingify/contract_ext.rb +21 -0
- data/lib/settingify/db_reader.rb +9 -0
- data/lib/settingify/db_syncer.rb +42 -0
- data/lib/settingify/reader.rb +22 -0
- data/lib/settingify/repo.rb +27 -0
- data/lib/settingify/setting.rb +5 -0
- data/lib/settingify/setting_builder.rb +20 -0
- data/lib/settingify/settings_list.rb +4 -0
- data/lib/settingify/version.rb +3 -0
- data/lib/settingify.rb +35 -0
- data/settingify.gemspec +32 -0
- data/spec/db/schema.rb +9 -0
- data/spec/lib/settingify/db_syncer_spec.rb +43 -0
- data/spec/lib/settingify/reader_spec.rb +43 -0
- data/spec/lib/settingify/repo_spec.rb +49 -0
- data/spec/lib/settingify/setting_builder_spec.rb +21 -0
- data/spec/lib/settingify_spec.rb +29 -0
- data/spec/spec_helper.rb +22 -0
- metadata +220 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2434255ad4235e0a52d9668f1ab0b88e58cb2ecb
|
4
|
+
data.tar.gz: 6b2be1e3c5a2d9fed971ff36a46e7e638c3d48e4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 910715d6d7252ab147f78ae77154e68b19b7b3a1662162c9b59a6e671ab4b8f734d6c3414c3210414e0ce40b393747fe000498a8faab23be49a682774bc906cc
|
7
|
+
data.tar.gz: 39e50023a37a292f28987846c7da59d282e7fc7826d99773ea4f8b0d6dc956a9c4435f360bb74a268488a8260fade67cca03675e92a7107580e74470dc492e34
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
.rvmrc
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Sergey Gernyak
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
# Settingify
|
2
|
+
|
3
|
+
This is small global settings system with some features:
|
4
|
+
|
5
|
+
1. Works without table returning default values. Migrating db loaded the whole rails environment
|
6
|
+
and using settings in lazy code blocks (like activeadmin resource
|
7
|
+
files) may cause problems.
|
8
|
+
2. May works with admin systems like simple model. For example,
|
9
|
+
integration with active admin:
|
10
|
+
|
11
|
+
```
|
12
|
+
rails g active_admin:resource Settingify::Setting
|
13
|
+
```
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
gem 'settingify', '0.0.2'
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install settingify -v 0.0.2
|
28
|
+
|
29
|
+
### Post installation
|
30
|
+
|
31
|
+
Run intallation generator for installing migration and initializer:
|
32
|
+
|
33
|
+
```
|
34
|
+
rails g settingify:install
|
35
|
+
```
|
36
|
+
|
37
|
+
Then migrate:
|
38
|
+
|
39
|
+
```
|
40
|
+
rake db:migrate
|
41
|
+
```
|
42
|
+
|
43
|
+
## Usage
|
44
|
+
|
45
|
+
### Defining settings
|
46
|
+
|
47
|
+
It may be done by patching created initializer in
|
48
|
+
`config/initializers/settingify.rb`. There is simple DSL:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
Settingify.prepare_settings do
|
52
|
+
setting :some_name, type: SettingType, default: 'some default value'
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
Supported types are _String_, _Integer_ and _Float_. But you may define own
|
57
|
+
convertors. There are 2 conditions for that:
|
58
|
+
|
59
|
+
1. Convertor must contains class method `ConvertorClass.try_convert`
|
60
|
+
2. This method accepts string value
|
61
|
+
|
62
|
+
Also exists ability for set type as passing class or simple a symbol.
|
63
|
+
For example:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
Settingify.prepare_settings do
|
67
|
+
setting :some_name, type: :string, default: 'some default value'
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
Default type is __string__.
|
72
|
+
|
73
|
+
### Reading settings
|
74
|
+
|
75
|
+
There are two cases:
|
76
|
+
|
77
|
+
1. Setting table is not exists - the default value will be returned.
|
78
|
+
2. Setting table is exists - value from record will be returned.
|
79
|
+
3. Setting table is exists and record not found - the default value will
|
80
|
+
be returned too.
|
81
|
+
|
82
|
+
According to example above to read setting use the next code:
|
83
|
+
|
84
|
+
```
|
85
|
+
Settingify.some_name
|
86
|
+
```
|
87
|
+
|
88
|
+
### Syncing settings
|
89
|
+
|
90
|
+
When you define settings in initializer this is no effect on DB. But in
|
91
|
+
most cases you (as site administator) want to change some settings
|
92
|
+
without redeploy the whole application. For this you may add settings to
|
93
|
+
the DB manually or run built-in rake task:
|
94
|
+
|
95
|
+
```
|
96
|
+
bundle exec rake settingify:sync
|
97
|
+
```
|
98
|
+
|
99
|
+
## Contributing
|
100
|
+
|
101
|
+
1. Fork it ( https://github.com/alterego-labs/settingify/fork )
|
102
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
103
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
104
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
105
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'rubygems/specification'
|
4
|
+
|
5
|
+
task default: :spec
|
6
|
+
desc "Run specs"
|
7
|
+
RSpec::Core::RakeTask.new do |t|
|
8
|
+
t.pattern = FileList['spec/**/*_spec.rb']
|
9
|
+
t.rspec_opts = %w(--color)
|
10
|
+
end
|
11
|
+
|
12
|
+
namespace :settingify do
|
13
|
+
desc 'Syncs defined settings with DB'
|
14
|
+
task sync: :environment do
|
15
|
+
Settingify::DbSyncer.new.call
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
module Settingify
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
desc "Add migration and copy initializer"
|
9
|
+
|
10
|
+
def self.next_migration_number(path)
|
11
|
+
unless @prev_migration_nr
|
12
|
+
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
13
|
+
else
|
14
|
+
@prev_migration_nr += 1
|
15
|
+
end
|
16
|
+
@prev_migration_nr.to_s
|
17
|
+
end
|
18
|
+
|
19
|
+
def copy_migrations
|
20
|
+
migration_template "create_settingify_setting.rb", "db/migrate/create_settingify_setting.rb"
|
21
|
+
end
|
22
|
+
|
23
|
+
def copy_initializer
|
24
|
+
copy_file "settingify.rb", "config/initializers/settingify.rb"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'active_support/core_ext/string/inflections'
|
2
|
+
|
3
|
+
module Settingify
|
4
|
+
class Caster < Struct.new(:type, :value)
|
5
|
+
using ContractExt
|
6
|
+
|
7
|
+
def call
|
8
|
+
type_class.try_convert value
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def type_class
|
14
|
+
type
|
15
|
+
.to_s
|
16
|
+
.classify
|
17
|
+
.constantize
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Settingify
|
2
|
+
module ContractExt
|
3
|
+
refine Integer.singleton_class do
|
4
|
+
def try_convert(value)
|
5
|
+
Integer(value)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
refine Float.singleton_class do
|
10
|
+
def try_convert(value)
|
11
|
+
Float(value)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
refine String.singleton_class do
|
16
|
+
def try_convert(value)
|
17
|
+
value.to_s
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Settingify
|
2
|
+
#
|
3
|
+
# Syncs defined settings with DB.
|
4
|
+
#
|
5
|
+
# Very useful for copying defined settings in initializer
|
6
|
+
# to DB with goal for ability to edit through admin panel.
|
7
|
+
#
|
8
|
+
# You may call this class manually in rails console or use
|
9
|
+
# built-in rake task:
|
10
|
+
# bundle exec rake settingify:sync
|
11
|
+
#
|
12
|
+
# Syncing means adding new DB entries for settings
|
13
|
+
# which not exists yet.
|
14
|
+
#
|
15
|
+
class DbSyncer
|
16
|
+
def call
|
17
|
+
settings_list.each(&method(:process_setting))
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def settings_list
|
23
|
+
Settingify.registered_settings
|
24
|
+
end
|
25
|
+
|
26
|
+
def process_setting(setting)
|
27
|
+
return if exists_in_db?(setting)
|
28
|
+
add_record_for setting
|
29
|
+
end
|
30
|
+
|
31
|
+
def exists_in_db?(setting)
|
32
|
+
Settingify::Setting.where(key: setting.name).any?
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_record_for(setting)
|
36
|
+
Settingify::Setting.create(
|
37
|
+
key: setting.name,
|
38
|
+
value: setting.default
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Settingify
|
2
|
+
class Reader < Struct.new(:key, :type, :default)
|
3
|
+
def call
|
4
|
+
return default unless table_exists?
|
5
|
+
Caster.new(type, db_value).call
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def table_exists?
|
11
|
+
ActiveRecordHelpers.table_exists? Settingify::TABLE_NAME
|
12
|
+
end
|
13
|
+
|
14
|
+
def db_setting
|
15
|
+
DbReader.new(key, default).call
|
16
|
+
end
|
17
|
+
|
18
|
+
def db_value
|
19
|
+
db_setting.value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Settingify
|
4
|
+
class Repo
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
def list
|
8
|
+
@settings_list ||= []
|
9
|
+
@settings_list
|
10
|
+
end
|
11
|
+
|
12
|
+
def add(item)
|
13
|
+
list << item
|
14
|
+
end
|
15
|
+
|
16
|
+
def clear!
|
17
|
+
list.each(&method(:undef_method_for))
|
18
|
+
list.clear
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def undef_method_for(item)
|
24
|
+
Settingify::SettingsList.send :remove_method, item.name
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Settingify
|
2
|
+
module SettingBuilder
|
3
|
+
def setting(name, type: String, default: '')
|
4
|
+
register_setting name, type, default
|
5
|
+
define_setting name, type, default
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def define_setting(name, type, default)
|
11
|
+
SettingsList.send :define_method, name do
|
12
|
+
Reader.new(name, type, default).call
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def register_setting(name, type, default)
|
17
|
+
Settingify::Repo.instance.add OpenStruct.new(name: name, type: type, default: default)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/settingify.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'active_record/version'
|
3
|
+
require 'active_support/core_ext/module'
|
4
|
+
|
5
|
+
require "settingify/version"
|
6
|
+
|
7
|
+
module Settingify
|
8
|
+
extend ActiveSupport::Autoload
|
9
|
+
|
10
|
+
autoload :ContractExt
|
11
|
+
autoload :Setting
|
12
|
+
autoload :SettingBuilder
|
13
|
+
autoload :SettingsList
|
14
|
+
autoload :Reader
|
15
|
+
autoload :Caster
|
16
|
+
autoload :DbReader
|
17
|
+
autoload :ActiveRecordHelpers
|
18
|
+
autoload :Constants
|
19
|
+
autoload :Repo
|
20
|
+
autoload :DbSyncer
|
21
|
+
|
22
|
+
extend SettingBuilder
|
23
|
+
extend SettingsList
|
24
|
+
|
25
|
+
include Constants
|
26
|
+
|
27
|
+
def self.prepare_settings(&block)
|
28
|
+
raise 'Block must be passed!' unless block_given?
|
29
|
+
instance_eval(&block)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.registered_settings
|
33
|
+
Repo.instance.list
|
34
|
+
end
|
35
|
+
end
|
data/settingify.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'settingify/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "settingify"
|
8
|
+
spec.version = Settingify::VERSION
|
9
|
+
spec.authors = ["Sergey Gernyak"]
|
10
|
+
spec.email = ["sergeg1990@gmail.com"]
|
11
|
+
spec.summary = %q{Global setting system for Rails}
|
12
|
+
spec.description = %q{System for managing global settings trough database}
|
13
|
+
spec.homepage = "https://github.com/alterego-labs/settingify"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "activesupport", ">= 4.0.4"
|
22
|
+
spec.add_development_dependency "activerecord", ">= 4.0.4"
|
23
|
+
spec.add_development_dependency "activemodel", ">= 4.0.4"
|
24
|
+
spec.add_development_dependency "rails", ">= 4.0.4"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0.0.beta"
|
29
|
+
spec.add_development_dependency "rspec-its", "1.0.1"
|
30
|
+
spec.add_development_dependency "pry-nav", "0.2.3"
|
31
|
+
spec.add_development_dependency 'sqlite3'
|
32
|
+
end
|
data/spec/db/schema.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module SomeBuilder
|
4
|
+
extend Settingify::SettingBuilder
|
5
|
+
end
|
6
|
+
|
7
|
+
describe Settingify::DbSyncer do
|
8
|
+
subject(:syncer) { described_class.new }
|
9
|
+
|
10
|
+
before do
|
11
|
+
Settingify::Setting.delete_all
|
12
|
+
Settingify::Repo.instance.clear!
|
13
|
+
SomeBuilder.setting :setting1, default: 'value1'
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
Settingify::Repo.instance.clear!
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when setting does not exists in db' do
|
21
|
+
it 'creates new record' do
|
22
|
+
expect{
|
23
|
+
syncer.call
|
24
|
+
}.to change(Settingify::Setting, :count).by(1)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when setting already exists in db' do
|
29
|
+
before do
|
30
|
+
Settingify::Setting.create(key: :setting1)
|
31
|
+
end
|
32
|
+
|
33
|
+
after do
|
34
|
+
Settingify::Setting.delete_all
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'does not creates new record' do
|
38
|
+
expect{
|
39
|
+
syncer.call
|
40
|
+
}.to_not change(Settingify::Setting, :count)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Settingify::Reader do
|
4
|
+
let(:key) { 'reader_setting' }
|
5
|
+
let(:type) { String }
|
6
|
+
let(:default) { 'reader_value' }
|
7
|
+
|
8
|
+
subject(:reader) { described_class.new(key, type, default) }
|
9
|
+
|
10
|
+
context 'when table does not exists' do
|
11
|
+
it 'returns default value' do
|
12
|
+
expect(reader.call).to eq default
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'when table is exists' do
|
17
|
+
let(:db_value) { "#{default} - db" }
|
18
|
+
|
19
|
+
before do
|
20
|
+
expect(reader).to receive(:table_exists?).and_return true
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'and record exists' do
|
24
|
+
before(:each) do
|
25
|
+
Settingify::Setting.create key: key, value: db_value
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns value from db' do
|
29
|
+
expect(reader.call).to eq db_value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'and record not exists' do
|
34
|
+
before(:each) do
|
35
|
+
Settingify::Setting.delete_all
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns default value' do
|
39
|
+
expect(reader.call).to eq default
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module SomeBuilder
|
4
|
+
extend Settingify::SettingBuilder
|
5
|
+
end
|
6
|
+
|
7
|
+
describe Settingify::Repo do
|
8
|
+
subject(:repo) { described_class.send :new }
|
9
|
+
|
10
|
+
describe '#list' do
|
11
|
+
context 'when no item has been added' do
|
12
|
+
it 'returns empty array' do
|
13
|
+
expect(repo.list).to be_empty
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when at least one item has been added' do
|
18
|
+
before do
|
19
|
+
repo.add :item
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns it' do
|
23
|
+
expect(repo.list).to include(:item)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#add' do
|
29
|
+
it 'adds item to list' do
|
30
|
+
expect{
|
31
|
+
repo.add :item
|
32
|
+
}.to change(repo.list, :count).by(1)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#clear' do
|
37
|
+
before do
|
38
|
+
SomeBuilder.setting(:for_clear_setting)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'removes all settings' do
|
42
|
+
expect(Settingify).to respond_to :for_clear_setting
|
43
|
+
expect(Settingify.registered_settings).to_not be_empty
|
44
|
+
Settingify::Repo.instance.clear!
|
45
|
+
expect(Settingify).to_not respond_to :for_clear_setting
|
46
|
+
expect(Settingify.registered_settings).to be_empty
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module SomeBuilder
|
4
|
+
extend Settingify::SettingBuilder
|
5
|
+
end
|
6
|
+
|
7
|
+
describe Settingify::SettingBuilder do
|
8
|
+
describe 'defining settings' do
|
9
|
+
it 'successfully' do
|
10
|
+
SomeBuilder.setting(:some_setting)
|
11
|
+
expect(Settingify.some_setting).to eq ''
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when default is Integer' do
|
15
|
+
it 'returns integer value' do
|
16
|
+
SomeBuilder.setting :some_int_value, type: :integer, default: 12
|
17
|
+
expect(Settingify.some_int_value).to eq 12
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Settingify do
|
4
|
+
describe '.prepare_settings' do
|
5
|
+
context 'when no block passed' do
|
6
|
+
it 'raises exception' do
|
7
|
+
expect{
|
8
|
+
Settingify.prepare_settings
|
9
|
+
}.to raise_exception
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when block passed' do
|
14
|
+
it 'successfully completed' do
|
15
|
+
Settingify.prepare_settings do
|
16
|
+
setting :ssssome, default: 'msg'
|
17
|
+
end
|
18
|
+
expect(Settingify.ssssome).to eq 'msg'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '.registered_settings' do
|
24
|
+
it 'calls list on repo' do
|
25
|
+
expect(Settingify::Repo).to receive_message_chain(:instance, :list)
|
26
|
+
Settingify.registered_settings
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
$TESTING=true
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
3
|
+
|
4
|
+
require 'active_record'
|
5
|
+
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
6
|
+
load 'db/schema.rb'
|
7
|
+
|
8
|
+
require 'rspec/its'
|
9
|
+
require 'settingify'
|
10
|
+
require 'pry-nav'
|
11
|
+
|
12
|
+
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
|
13
|
+
|
14
|
+
RSpec.configure do |config|
|
15
|
+
config.mock_with :rspec
|
16
|
+
|
17
|
+
config.filter_run focus: true
|
18
|
+
config.run_all_when_everything_filtered = true
|
19
|
+
|
20
|
+
config.order = "random"
|
21
|
+
end
|
22
|
+
|
metadata
ADDED
@@ -0,0 +1,220 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: settingify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergey Gernyak
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.4
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.0.4
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.0.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activemodel
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 4.0.4
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.0.4
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 4.0.4
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 4.0.4
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.6'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.6'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.0.0.beta
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 3.0.0.beta
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec-its
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.0.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.0.1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry-nav
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.2.3
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.2.3
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: sqlite3
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: System for managing global settings trough database
|
154
|
+
email:
|
155
|
+
- sergeg1990@gmail.com
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- ".gitignore"
|
161
|
+
- Gemfile
|
162
|
+
- LICENSE.txt
|
163
|
+
- README.md
|
164
|
+
- Rakefile
|
165
|
+
- lib/generators/settingify/install/install_generator.rb
|
166
|
+
- lib/generators/settingify/install/templates/create_settingify_setting.rb
|
167
|
+
- lib/generators/settingify/install/templates/settingify.rb
|
168
|
+
- lib/settingify.rb
|
169
|
+
- lib/settingify/active_record_helpers.rb
|
170
|
+
- lib/settingify/caster.rb
|
171
|
+
- lib/settingify/constants.rb
|
172
|
+
- lib/settingify/contract_ext.rb
|
173
|
+
- lib/settingify/db_reader.rb
|
174
|
+
- lib/settingify/db_syncer.rb
|
175
|
+
- lib/settingify/reader.rb
|
176
|
+
- lib/settingify/repo.rb
|
177
|
+
- lib/settingify/setting.rb
|
178
|
+
- lib/settingify/setting_builder.rb
|
179
|
+
- lib/settingify/settings_list.rb
|
180
|
+
- lib/settingify/version.rb
|
181
|
+
- settingify.gemspec
|
182
|
+
- spec/db/schema.rb
|
183
|
+
- spec/lib/settingify/db_syncer_spec.rb
|
184
|
+
- spec/lib/settingify/reader_spec.rb
|
185
|
+
- spec/lib/settingify/repo_spec.rb
|
186
|
+
- spec/lib/settingify/setting_builder_spec.rb
|
187
|
+
- spec/lib/settingify_spec.rb
|
188
|
+
- spec/spec_helper.rb
|
189
|
+
homepage: https://github.com/alterego-labs/settingify
|
190
|
+
licenses:
|
191
|
+
- MIT
|
192
|
+
metadata: {}
|
193
|
+
post_install_message:
|
194
|
+
rdoc_options: []
|
195
|
+
require_paths:
|
196
|
+
- lib
|
197
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
|
+
requirements:
|
204
|
+
- - ">="
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: '0'
|
207
|
+
requirements: []
|
208
|
+
rubyforge_project:
|
209
|
+
rubygems_version: 2.4.4
|
210
|
+
signing_key:
|
211
|
+
specification_version: 4
|
212
|
+
summary: Global setting system for Rails
|
213
|
+
test_files:
|
214
|
+
- spec/db/schema.rb
|
215
|
+
- spec/lib/settingify/db_syncer_spec.rb
|
216
|
+
- spec/lib/settingify/reader_spec.rb
|
217
|
+
- spec/lib/settingify/repo_spec.rb
|
218
|
+
- spec/lib/settingify/setting_builder_spec.rb
|
219
|
+
- spec/lib/settingify_spec.rb
|
220
|
+
- spec/spec_helper.rb
|