easy-configuration 0.5.1

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
+ SHA256:
3
+ metadata.gz: 8cfb090344f0ee119f47ffaa11bf4fd061394793094ee3b0d61811946df818ed
4
+ data.tar.gz: 02ee4eb7ebc80ff701b8ac7e5fc8020b8362de91529fc86cf5cd9f900d6901ab
5
+ SHA512:
6
+ metadata.gz: c447a81ed756655a68d50d752a877a0a1e596e55fb9190bfac6a5febffd3dd6aded64f1e5059c7984d5de9da2ad186993ba59fe1c95ac9e3033c7a8796e357bd
7
+ data.tar.gz: 14a3f0d61048bca07ae7329665cba96ce4ce80ae0295cb15f882aef50081531a77e52d0194c05760d344aded8e59bd8253b11df867837cd00b999ac0c4679edf
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 petr
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,28 @@
1
+ # Easy::Configuration
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'easy-configuration'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install easy-configuration
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,27 @@
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 = 'Easy::Configuration'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = false
25
+ end
26
+
27
+ task default: :test
@@ -0,0 +1,112 @@
1
+ require "easy/configuration/railtie"
2
+
3
+ module Easy
4
+ module Configuration
5
+ extend ActiveSupport::Autoload
6
+
7
+ autoload :Structure
8
+ autoload :Auth
9
+ autoload :Autocomplete
10
+ autoload :Custom
11
+ autoload :Entity
12
+ autoload :Menu
13
+ autoload :MenuItem
14
+ autoload :MenuTitle
15
+ autoload :MenuEntityLink
16
+ autoload :MenuCustomLink
17
+
18
+ module Patches
19
+ extend ActiveSupport::Autoload
20
+
21
+ autoload :ActiveRecord
22
+ end
23
+
24
+ cattr_accessor :application_name
25
+ self.application_name = 'Easy'
26
+
27
+ cattr_accessor :application_icon
28
+ self.application_icon = 'application_icon'
29
+
30
+ cattr_accessor :email_default_from
31
+ self.email_default_from = 'info@easysoftware.com'
32
+
33
+ cattr_accessor :protocol
34
+ self.protocol = 'https'
35
+
36
+ cattr_accessor :host_name
37
+ self.host_name = 'app.easysoftware.com'
38
+
39
+ cattr_accessor :_entities
40
+ self._entities = {}
41
+
42
+ cattr_accessor :_menu
43
+ self._menu = {}
44
+
45
+ class << self
46
+
47
+ def host
48
+ "#{protocol}://#{host_name}"
49
+ end
50
+
51
+ def entity(klass_or_name, &block)
52
+ k = klass_or_name.is_a?(String) ? klass_or_name : klass_or_name.name.underscore
53
+
54
+ self._entities[k] ||= Entity.new(k)
55
+
56
+ if block_given?
57
+ yield self._entities[k]
58
+ else
59
+ self._entities[k]
60
+ end
61
+ end
62
+
63
+ def menu(section, &block)
64
+ self._menu[section.to_s] ||= Menu.new
65
+
66
+ if block_given?
67
+ yield self._menu[section.to_s]
68
+ else
69
+ self._menu[section.to_s]
70
+ end
71
+ end
72
+
73
+ def auth(&block)
74
+ if block_given?
75
+ yield Auth
76
+ else
77
+ Auth
78
+ end
79
+ end
80
+
81
+ def sites
82
+ @sites ||= begin
83
+ h = ::ActiveSupport::OrderedOptions.new
84
+ h.merge!(secrets.sites || {})
85
+ h
86
+ end
87
+ end
88
+
89
+ def custom
90
+ @custom ||= Custom.new
91
+ end
92
+
93
+ def secrets
94
+ Rails.application.secrets
95
+ end
96
+
97
+ end
98
+
99
+ end
100
+
101
+ class << self
102
+
103
+ def config
104
+ ::Easy::Configuration
105
+ end
106
+
107
+ def configure
108
+ yield config
109
+ end
110
+
111
+ end
112
+ end
@@ -0,0 +1,58 @@
1
+ module Easy
2
+ module Configuration
3
+ module Auth
4
+
5
+ cattr_accessor :required
6
+ self.required = false
7
+
8
+ cattr_accessor :no_password_auth
9
+ self.no_password_auth = false
10
+
11
+ cattr_accessor :only_omniauth
12
+ self.only_omniauth = false
13
+
14
+ cattr_accessor :allow_anonymous_readonly_api
15
+ self.allow_anonymous_readonly_api = false
16
+
17
+ cattr_accessor :token_auth
18
+ self.token_auth = false
19
+
20
+ class << self
21
+
22
+ def required?
23
+ !!self.required
24
+ end
25
+
26
+ def no_password_auth?
27
+ !!self.no_password_auth
28
+ end
29
+
30
+ def token_auth?
31
+ !!self.token_auth
32
+ end
33
+
34
+ def allow_anonymous_readonly_api?
35
+ !!self.allow_anonymous_readonly_api
36
+ end
37
+
38
+ def only_omniauth?
39
+ !!self.only_omniauth
40
+ end
41
+
42
+ def omniauth_providers
43
+ Rails.application.secrets.omniauth_providers || {}
44
+ end
45
+
46
+ def omniauth_providers_keys
47
+ omniauth_providers.keys
48
+ end
49
+
50
+ def social_sign_in?
51
+ (%i(facebook google_oauth2 twitter linkedin) & omniauth_providers_keys).present?
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,35 @@
1
+ module Easy
2
+ module Configuration
3
+ class Custom
4
+
5
+ def method_missing(name, *args)
6
+ name_string = name.to_s
7
+ if name_string.chomp!("=")
8
+ from_file[name_string] = args.first
9
+ else
10
+ bangs = name_string.chomp!("!")
11
+
12
+ if bangs
13
+ from_file[name_string].presence || raise(KeyError.new(":#{name_string} is blank"))
14
+ else
15
+ from_file[name_string]
16
+ end
17
+ end
18
+ end
19
+
20
+ def respond_to_missing?(name, include_private)
21
+ true
22
+ end
23
+
24
+ private
25
+
26
+ def from_file
27
+ @from_file ||= begin
28
+ file_path = Rails.root.join('config/config.yml')
29
+ File.exists?(file_path) ? YAML.load_file(file_path) : {}
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,27 @@
1
+ module Easy
2
+ module Configuration
3
+ class Entity
4
+
5
+ attr_accessor :no_count
6
+
7
+ def initialize(klass_name)
8
+ @klass_name = klass_name
9
+ @no_count = false
10
+ @menu = Hash.new { |hash, key| hash[key.to_s] = Menu.new }
11
+ end
12
+
13
+ def no_count?
14
+ !!no_count
15
+ end
16
+
17
+ def menu(section, &block)
18
+ if block_given?
19
+ yield @menu[section.to_s]
20
+ else
21
+ @menu[section.to_s]
22
+ end
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,69 @@
1
+ module Easy
2
+ module Configuration
3
+ class Menu
4
+
5
+ attr_accessor :visibility
6
+ attr_writer :caption
7
+
8
+ def initialize
9
+ @items = {}
10
+ @caption = nil
11
+ end
12
+
13
+ def visible?(current_user)
14
+ case @visibility
15
+ when Proc
16
+ @visibility.call(current_user)
17
+ when NilClass
18
+ true
19
+ else
20
+ !!@visibility
21
+ end
22
+ end
23
+
24
+ def caption
25
+ case @caption
26
+ when String
27
+ @caption
28
+ when NilClass
29
+ ''
30
+ else
31
+ I18n.t(@caption)
32
+ end
33
+ end
34
+
35
+ def custom_link(key, options = {}, &block)
36
+ parent = options.delete(:parent)
37
+
38
+ add(key, MenuCustomLink.new(options, &block), parent)
39
+ end
40
+
41
+ def entity_link(class_name, options = {}, &block)
42
+ parent = options.delete(:parent)
43
+
44
+ add(class_name, MenuEntityLink.new(class_name, options, &block), parent)
45
+ end
46
+
47
+ def title(key, options = {}, &block)
48
+ parent = options.delete(:parent)
49
+
50
+ add(key, MenuTitle.new(options, &block), parent)
51
+ end
52
+
53
+ def items
54
+ @items.values
55
+ end
56
+
57
+ private
58
+
59
+ def add(key, menu_item, parent = nil)
60
+ if parent && @items[parent.to_s]
61
+ @items[parent.to_s].children[key.to_s] = menu_item
62
+ else
63
+ @items[key.to_s] = menu_item
64
+ end
65
+ end
66
+
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,33 @@
1
+ module Easy
2
+ module Configuration
3
+ class MenuCustomLink < MenuTitle
4
+
5
+ attr_reader :icon
6
+
7
+ def initialize(options = {}, &block)
8
+ @url = options.delete(:url)
9
+ @title = options.delete(:title)
10
+ @icon = options.delete(:icon)
11
+
12
+ super(options, &block)
13
+ end
14
+
15
+ def title
16
+ case @title
17
+ when String
18
+ @title
19
+ else
20
+ I18n.t(@title)
21
+ end
22
+ end
23
+
24
+ def url(view_context, decorator)
25
+ case @url
26
+ when Proc
27
+ @url.call(view_context, decorator)
28
+ end
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,19 @@
1
+ module Easy
2
+ module Configuration
3
+ class MenuEntityLink < MenuCustomLink
4
+
5
+ attr_reader :class_name
6
+
7
+ def initialize(class_name, options = {}, &block)
8
+ @class_name = class_name
9
+
10
+ super(options, &block)
11
+ end
12
+
13
+ def url(view_context, decorator)
14
+ super || decorator.path_to_index
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ module Easy
2
+ module Configuration
3
+ class MenuItem
4
+
5
+ attr_reader :children, :link_setup, :html_options
6
+
7
+ def initialize(options = {}, &block)
8
+ @visibility = options.delete(:visibility)
9
+ @html_options = options.delete(:html) || {}
10
+ @options = options
11
+ @link_setup = block
12
+ @children = {}
13
+ end
14
+
15
+ def children?
16
+ @children.present?
17
+ end
18
+
19
+ def visible?(current_user)
20
+ case @visibility
21
+ when Proc
22
+ @visibility.call(current_user)
23
+ when NilClass
24
+ true
25
+ else
26
+ !!@visibility
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,24 @@
1
+ module Easy
2
+ module Configuration
3
+ class MenuTitle < MenuItem
4
+
5
+ def initialize(options = {}, &block)
6
+ @caption = options.delete(:caption)
7
+
8
+ super(options, &block)
9
+ end
10
+
11
+ def caption
12
+ case @caption
13
+ when String
14
+ @caption
15
+ when NilClass
16
+ ''
17
+ else
18
+ I18n.t(@caption)
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ module Easy
2
+ module Configuration
3
+ module Patches
4
+ module ActiveRecord
5
+ extend ActiveSupport::Concern
6
+
7
+ class_methods do
8
+
9
+ def config
10
+ Easy.config.entity(self)
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ module Easy
2
+ module Configuration
3
+ class Railtie < ::Rails::Railtie
4
+
5
+ config.to_prepare do
6
+ ::ActiveRecord::Base.include Patches::ActiveRecord
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,51 @@
1
+ module Easy
2
+ module Configuration
3
+ class Structure
4
+
5
+ def initialize(default_values = {})
6
+ @values = default_values.dup
7
+ @changed = Hash.new { |hash, key| hash[key] = false }
8
+
9
+ define_instance_methods
10
+ end
11
+
12
+ def merge!(structure, ignore_defaults = true)
13
+ if ignore_defaults
14
+ @values.merge!(structure.values) { |key, v1, v2| structure.changed?(key) ? v2 : v1 }
15
+ else
16
+ @values.merge!(structure.values)
17
+ end
18
+ end
19
+
20
+ protected
21
+
22
+ def values
23
+ @values
24
+ end
25
+
26
+ def changed?(attribute)
27
+ @changed[attribute]
28
+ end
29
+
30
+ private
31
+
32
+ def define_instance_methods
33
+ @values.keys.each do |key|
34
+ self.class.send :define_method, key do
35
+ @values[key]
36
+ end
37
+
38
+ self.class.send :define_method, "#{key}_changed?" do
39
+ @changed[key]
40
+ end
41
+
42
+ self.class.send :define_method, "#{key}=" do |v|
43
+ @changed[key] = true
44
+ @values[key] = v
45
+ end
46
+ end
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,5 @@
1
+ module Easy
2
+ module Configuration
3
+ VERSION = '0.5.1'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easy-configuration
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.1
5
+ platform: ruby
6
+ authors:
7
+ - petr
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.6
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.3.6
69
+ description: Description of Easy::Configuration.
70
+ email:
71
+ - petr@easy.cz
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - MIT-LICENSE
77
+ - README.md
78
+ - Rakefile
79
+ - lib/easy/configuration.rb
80
+ - lib/easy/configuration/auth.rb
81
+ - lib/easy/configuration/custom.rb
82
+ - lib/easy/configuration/entity.rb
83
+ - lib/easy/configuration/menu.rb
84
+ - lib/easy/configuration/menu_custom_link.rb
85
+ - lib/easy/configuration/menu_entity_link.rb
86
+ - lib/easy/configuration/menu_item.rb
87
+ - lib/easy/configuration/menu_title.rb
88
+ - lib/easy/configuration/patches/active_record.rb
89
+ - lib/easy/configuration/railtie.rb
90
+ - lib/easy/configuration/structure.rb
91
+ - lib/easy/configuration/version.rb
92
+ homepage: https://www.easysoftware.com
93
+ licenses:
94
+ - MIT
95
+ metadata:
96
+ allowed_push_host: https://rubygems.org
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.7.7
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Summary of Easy::Configuration.
117
+ test_files: []