rails_easy_settings 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8cd6728ab5323aff8c5bc935e30c353152e162ab
4
+ data.tar.gz: 7bc9910d087962659d63346566097af569a3cf70
5
+ SHA512:
6
+ metadata.gz: aecc0fe00bc7a8a24ac9b53d14ba5b74b2dcb313fe5f31b758e324b406ad1a13995705ab8812d62d891a54132249086e0a5ffa1cc5657154b08d1b5acfa6985a
7
+ data.tar.gz: d4346ef5c96e261bc1b95a59a0dad936690c2a9917fffd26a45b9759b9ce24493c1e9efe9d0fc1ebb2f57bf1f9e1e9283582945e86236318c24f9777f08403e0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Leihb
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # EasySettings
2
+ A very easy gem to do global settings using with rails
3
+
4
+ ## Installation
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'easy_settings'
9
+ ```
10
+
11
+ And then execute:
12
+ ```bash
13
+ rails g easy_settings:install
14
+ rake db:migrate
15
+ ```
16
+
17
+ ## Usage
18
+ ```bash
19
+ Settings.favorate_fruit = 'apple'
20
+ ```
21
+ ## Contributing
22
+ Contribution directions go here.
23
+
24
+ ## License
25
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'EasySettings'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+
33
+ task default: :test
@@ -0,0 +1,5 @@
1
+ require_relative 'easy_settings/base'
2
+ require_relative 'easy_settings/version'
3
+
4
+ module EasySettings
5
+ end
@@ -0,0 +1,33 @@
1
+ module EasySettings
2
+ class Base < ActiveRecord::Base
3
+ self.table_name = table_name_prefix + 'settings'
4
+
5
+ serialize :value
6
+
7
+ class << self
8
+ def method_missing(method, *args)
9
+ method_name = method.to_s
10
+ if method_name[-1] == '='
11
+ key = method_name[0...-1]
12
+ value = args.first
13
+ self[key]=value
14
+ else
15
+ self[method_name]
16
+ end
17
+ end
18
+
19
+ def [](key)
20
+ self.where(key: key).first.try(:value)
21
+ end
22
+
23
+ def []=(key, value)
24
+ record = self.where(key: key).first
25
+ if record
26
+ record.update(value: value)
27
+ else
28
+ self.create(key: key, value: value)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module EasySettings
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,26 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ module EasySettings
5
+ module Generators
6
+ class InstallGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+
9
+ desc "Create a EasySettings migration file"
10
+ source_root File.expand_path("../templates", __FILE__)
11
+
12
+ def install_settings
13
+ migration_template 'migration.rb', 'db/migrate/easy_settings_migration.rb'
14
+ template 'model.rb', File.join('app/models', "settings.rb")
15
+ end
16
+
17
+ def self.next_migration_number(dirname)
18
+ if ActiveRecord::Base.timestamped_migrations
19
+ Time.now.utc.strftime('%Y%m%d%H%M%S')
20
+ else
21
+ '%.3d' % (current_migration_number(dirname) + 1)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ class EasySettingsMigration < ActiveRecord::Migration[5.1]
2
+ def self.up
3
+ create_table :settings do |t|
4
+ t.string :key, :null => false
5
+ t.text :value
6
+ t.timestamps :null => true
7
+ end
8
+ add_index :settings, [:key], :unique => true
9
+ end
10
+
11
+ def self.down
12
+ drop_table :settings
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ class Settings < EasySettings::Base
2
+
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :easy_settings do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_easy_settings
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Leihb
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Description of EasySettings.
42
+ email:
43
+ - leihaibo1992@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - lib/easy_settings.rb
52
+ - lib/easy_settings/base.rb
53
+ - lib/easy_settings/version.rb
54
+ - lib/generators/easy_settings/install_generator.rb
55
+ - lib/generators/easy_settings/templates/migration.rb
56
+ - lib/generators/easy_settings/templates/model.rb
57
+ - lib/tasks/easy_settings_tasks.rake
58
+ homepage: http://github.com/Leihb/easy_settings
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.6.14
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Summary of EasySettings.
82
+ test_files: []