smart_settings 0.1.1 → 0.1.2

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
- SHA1:
3
- metadata.gz: 13b9e02e948f0cd9036e96d8a3746eb2bdb3328c
4
- data.tar.gz: f877f01cca18f28ba110b6e3ce4a6a7ffe970ff1
2
+ SHA256:
3
+ metadata.gz: dd6604f5f2ae057b84ae65fe2aab6a9fb6311104ae6e7b32f0502196e350b6ad
4
+ data.tar.gz: eaa68492d6a18f875dc68bc9fcf2831a312cbd4fb8ee45468ff7dd40fc54b6a9
5
5
  SHA512:
6
- metadata.gz: bd1215594e9814a60b5b139f1ccf47761935c866fed1aea7d8717bf91b074b3b56ba616e6fa1b970fc5632e73ceef62b3f445662a52a69517b39535f43bafed5
7
- data.tar.gz: 6d64ba1b64cdfe11b73e7ec988a9beb2afc958e101cf4644d46c107ca4b8917e4d5c4db45b5c5495fc0bc3239c56bf22b0c3b14e7c55775397d7b7d7bf57a71a
6
+ metadata.gz: e36902d73b0e9671d07d9222eba95da95434b2c2c83a7e8f46a18cd3ca4783cb79546a1e3e0aed49bf192d190154e7fd1f400b29f3730ffe42a183a618c882a7
7
+ data.tar.gz: 41468b19beb844c27d677f3fe124f8cea5163bf4cbb7d85711f3f21667b637747e10c3807812bf02b42d79cbf8416cf043f72c717e0ac3fe289827131eabf2e0
data/README.md CHANGED
@@ -125,12 +125,8 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
125
125
 
126
126
  ## Contributing
127
127
 
128
- Bug reports and pull requests are welcome on GitHub at https://github.com/hardpixel/smart-settings. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
128
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hardpixel/smart-settings.
129
129
 
130
130
  ## License
131
131
 
132
132
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
133
-
134
- ## Code of Conduct
135
-
136
- Everyone interacting in the SmartSettings project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hardpixel/smart-settings/blob/master/CODE_OF_CONDUCT.md).
@@ -14,29 +14,29 @@ module SmartSettings
14
14
 
15
15
  private
16
16
 
17
- def setting_class
18
- name.camelize
19
- end
17
+ def setting_class
18
+ name.camelize
19
+ end
20
20
 
21
- def setting_file
22
- "#{name.downcase.underscore}_settings"
23
- end
21
+ def setting_file
22
+ "#{name.downcase.underscore}_settings"
23
+ end
24
24
 
25
- def setting_fields
26
- args.map do |arg|
27
- field, cast_type, default, group = arg.split(':')
25
+ def setting_fields
26
+ args.map do |arg|
27
+ field, cast_type, default, group = arg.split(':')
28
28
 
29
- items = [":#{field.to_sym}", ":#{cast_type.to_sym}"]
30
- items << ["default: #{value_type_cast(cast_type.to_sym, default)}"] if default.present?
31
- items << ["group: :#{group.to_sym}"] if group.present?
29
+ items = [":#{field.to_sym}", ":#{cast_type.to_sym}"]
30
+ items << ["default: #{value_type_cast(cast_type.to_sym, default)}"] if default.present?
31
+ items << ["group: :#{group.to_sym}"] if group.present?
32
32
 
33
- items.join(', ')
34
- end
33
+ items.join(', ')
35
34
  end
35
+ end
36
36
 
37
- def value_type_cast(cast_type, value)
38
- strings = [:string, :date, :datetime, :time]
39
- cast_type.in?(strings) ? "'#{value}'" : value
40
- end
37
+ def value_type_cast(cast_type, value)
38
+ strings = [:string, :date, :datetime, :time]
39
+ cast_type.in?(strings) ? "'#{value}'" : value
40
+ end
41
41
  end
42
42
  end
@@ -11,17 +11,17 @@ module SmartSettings
11
11
  end
12
12
 
13
13
  class_methods do
14
- def setting(name, type_cast=:string, options={})
14
+ def setting(name, type_cast = :string, options = {})
15
15
  gname = options.delete(:group)
16
16
  sname = gname.nil? ? name : :"#{gname}_#{name}"
17
17
 
18
18
  attribute sname, type_cast, options
19
19
  self.setting_names += [sname]
20
20
 
21
- unless gname.nil?
22
- group = setting_groups.fetch(gname, []) + [sname]
23
- self.setting_groups = setting_groups.merge(gname => group)
24
- end
21
+ return if gname.nil?
22
+
23
+ group = setting_groups.fetch(gname, []) + [sname]
24
+ self.setting_groups = setting_groups.merge(gname => group)
25
25
  end
26
26
 
27
27
  def method_missing(method, *args, &block)
@@ -38,16 +38,16 @@ module SmartSettings
38
38
  end
39
39
 
40
40
  def group_exists?(name)
41
- setting_groups.keys.include? name
41
+ setting_groups.key? name
42
42
  end
43
43
 
44
44
  def group(name)
45
- if group_exists?(name)
46
- keys = setting_groups[name]
47
- data = attributes.symbolize_keys.select { |k, _v| k.in? keys }
45
+ return unless group_exists?(name)
48
46
 
49
- Hash[data.map { |k, v| [k.to_s.sub("#{name}_", '').to_sym, v] }]
50
- end
47
+ keys = setting_groups[name]
48
+ data = attributes.symbolize_keys.select { |k, _v| k.in? keys }
49
+
50
+ Hash[data.map { |k, v| [k.to_s.sub("#{name}_", '').to_sym, v] }]
51
51
  end
52
52
 
53
53
  def method_missing(method, *args, &block)
@@ -17,11 +17,11 @@ module SmartSettings
17
17
  end
18
18
 
19
19
  def var
20
- "#{self.class.name}".demodulize.sub('Settings', '')
20
+ self.class.name.to_s.demodulize.sub('Settings', '')
21
21
  end
22
22
 
23
23
  def to_param
24
- "#{var}".parameterize
24
+ var.to_s.parameterize
25
25
  end
26
26
 
27
27
  def permitted_attributes
@@ -30,37 +30,37 @@ module SmartSettings
30
30
  end
31
31
 
32
32
  def settings
33
- if settings_table_exists?
34
- valid = self.attribute_names.reject { |i| i == 'var' }
35
- Setting.where(settable_type: self.class.name, settable_id: id, var: valid)
36
- end
33
+ return unless settings_table_exists?
34
+
35
+ valid = self.attribute_names.reject { |i| i == 'var' }
36
+ Setting.where(settable_type: self.class.name, settable_id: id, var: valid)
37
37
  end
38
38
 
39
39
  private
40
40
 
41
- def cast_setting_value(var, value)
42
- self.class.attribute_types[var].cast(value)
43
- end
41
+ def cast_setting_value(var, value)
42
+ self.class.attribute_types[var].cast(value)
43
+ end
44
44
 
45
- def create_setting(var, value)
46
- parameters = { var: var, value: cast_setting_value(var, value) }
47
- Setting.create(parameters.merge(settable_type: self.class.name, settable_id: id))
48
- end
45
+ def create_setting(var, value)
46
+ parameters = { var: var, value: cast_setting_value(var, value) }
47
+ Setting.create(parameters.merge(settable_type: self.class.name, settable_id: id))
48
+ end
49
49
 
50
- def update_setting(var, value)
51
- settings.where(var: var).update(value: cast_setting_value(var, value))
52
- end
50
+ def update_setting(var, value)
51
+ settings.where(var: var).update(value: cast_setting_value(var, value))
52
+ end
53
53
 
54
- def create_or_update_setting(var, value)
55
- if settings.where(var: var).exists?
56
- update_setting(var, value)
57
- else
58
- create_setting(var, value)
59
- end
54
+ def create_or_update_setting(var, value)
55
+ if settings.where(var: var).exists?
56
+ update_setting(var, value)
57
+ else
58
+ create_setting(var, value)
60
59
  end
60
+ end
61
61
 
62
- def settings_table_exists?
63
- ActiveRecord::Base.connection.table_exists? Setting.table_name
64
- end
62
+ def settings_table_exists?
63
+ ActiveRecord::Base.connection.table_exists? Setting.table_name
64
+ end
65
65
  end
66
66
  end
@@ -8,12 +8,10 @@ module SmartSettings
8
8
  end
9
9
 
10
10
  def find(*var)
11
- if var.size > 1
12
- results = where(var: var)
13
- raise_record_not_found_exception!(var) if results.blank?
14
- else
15
- find_by_var!(var.first)
16
- end
11
+ return find_by_var!(var.first) unless var.size > 1
12
+
13
+ results = where(var: var)
14
+ raise_record_not_found_exception!(var) if results.blank?
17
15
  end
18
16
 
19
17
  def find_by_var(var)
@@ -26,7 +24,7 @@ module SmartSettings
26
24
  setting.nil? ? raise_record_not_found_exception!(var) : setting
27
25
  end
28
26
 
29
- def where(options={})
27
+ def where(options = {})
30
28
  vars = Hash[options][:var]
31
29
  return all if vars.nil?
32
30
 
@@ -35,14 +33,12 @@ module SmartSettings
35
33
  end
36
34
 
37
35
  def all
38
- if setting_names.empty?
39
- files = Dir.glob(Rails.root.join('app', 'settings', '*.rb'))
40
- files = files.map { |file| file.to_s.split('/').last.sub('_settings.rb', '') }
36
+ return new.all if setting_names.any?
37
+
38
+ files = Dir.glob(Rails.root.join('app', 'settings', '*.rb'))
39
+ files = files.map { |file| file.to_s.split('/').last.sub('_settings.rb', '') }
41
40
 
42
- where(var: files)
43
- else
44
- new.all
45
- end
41
+ where(var: files)
46
42
  end
47
43
 
48
44
  def method_missing(method, *args, &block)
@@ -52,12 +48,12 @@ module SmartSettings
52
48
 
53
49
  private
54
50
 
55
- def raise_record_not_found_exception!(ids)
56
- vars = ids.is_a?(Array) ? "(#{ids.join(', ')})" : ids
57
- error = "Couldn't find Settings with var: #{vars}"
51
+ def raise_record_not_found_exception!(ids)
52
+ vars = ids.is_a?(Array) ? "(#{ids.join(', ')})" : ids
53
+ error = "Couldn't find Settings with var: #{vars}"
58
54
 
59
- raise ActiveRecord::RecordNotFound.new(error, 'Settings', 'var')
60
- end
55
+ raise ActiveRecord::RecordNotFound.new(error, 'Settings', 'var')
56
+ end
61
57
  end
62
58
  end
63
59
  end
@@ -1,3 +1,3 @@
1
1
  module SmartSettings
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonian Guveli
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-28 00:00:00.000000000 Z
11
+ date: 2019-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '5.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: tableless
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +50,14 @@ dependencies:
44
50
  requirements:
45
51
  - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '1.14'
53
+ version: '2.0'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
58
  - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: '1.14'
60
+ version: '2.0'
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: rake
57
63
  requirement: !ruby/object:Gem::Requirement
@@ -88,7 +94,6 @@ executables: []
88
94
  extensions: []
89
95
  extra_rdoc_files: []
90
96
  files:
91
- - CODE_OF_CONDUCT.md
92
97
  - Gemfile
93
98
  - LICENSE.txt
94
99
  - README.md
@@ -125,8 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
130
  - !ruby/object:Gem::Version
126
131
  version: '0'
127
132
  requirements: []
128
- rubyforge_project:
129
- rubygems_version: 2.6.14
133
+ rubygems_version: 3.0.3
130
134
  signing_key:
131
135
  specification_version: 4
132
136
  summary: Persist application or record settings on ActiveRecord
data/CODE_OF_CONDUCT.md DELETED
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at info@hardpixel.eu. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/