cushion_defaults 0.5.0 → 0.5.1

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: 725ea185c013e34737b4bf5f46e0fa08fff68428
4
- data.tar.gz: 8414ae7cce652e15c91e654194c435ebe8aa0ed4
3
+ metadata.gz: eb9a0010fb2ee9d019f6fc9552354d422289810f
4
+ data.tar.gz: e34bed7551afc9746f0195766b50d2d17c02f8f5
5
5
  SHA512:
6
- metadata.gz: eaf552d0557b4c07c083fa3db1074f4ddc058b20d8039e35d1f1c772e5f49ce3ba1e1e5a78b92973d7f4565a3ed45ebbbad2f36eee2f2e1a8c2fe3af9bce3f82
7
- data.tar.gz: 68c8e99dd1543ae61ba627678eddaf63e962f276b5ffceb2e38eb812ec67dca281afd9f4157cbf7acae57a10d3e114bc49bb98204d7315fdf850ef9869dc7887
6
+ metadata.gz: a7cfe9bf2ef8919910408925c54ab14ae43b4efe50ebe3212a0e90fd850af8d6d94523d8b512d9093ea5905654d708ccb59ed44e57a3d69cf9c0fab67b84bee7
7
+ data.tar.gz: f6701c502a954b8c3a266366135377119c515053e8342d36ebc124fe503169a40795982b2a07069a0b002d85538713d52ad1848c0ffd784702c9b4c1aabbbbeb
data/CHANGELOG.md CHANGED
@@ -36,7 +36,7 @@
36
36
  - IMPROVEMENT: Testing
37
37
  - `test/` renamed to `spec/`
38
38
  - Add `.rspec` and `spec/spec_helper.rb`
39
- - Improve documentation further.
39
+ - DOCUMENTATION: Numerous expansions
40
40
 
41
41
  ## 0.3.x
42
42
 
@@ -46,7 +46,7 @@
46
46
  - ClassMethods#freeze_default
47
47
  - ClassMethods#deep_freeze_default
48
48
  - ClassMethods#thaw_default
49
- - 0.3.1: Bugfix to #freeze_defaults, #deep_freeze_defaults, and #thaw_defaults
49
+ - 0.3.1: BUGFIX: Corrected fatal error in #freeze_defaults, #deep_freeze_defaults, and #thaw_defaults
50
50
 
51
51
  ## 0.4.x
52
52
 
@@ -64,5 +64,11 @@
64
64
  - NEW OPTION: bang_things_up
65
65
  - If true, bang readers will automatically be set up every time a cushion_reader is created.
66
66
  - Default: true
67
- - Bugfix interaction between procs and #crystallize_defaults
68
- - Expand README.md
67
+ - BUGFIX: fix interaction between procs and #crystallize_defaults
68
+ - DOCUMENTATION: Expand README.md
69
+
70
+ -0.5.1
71
+ - DEPENDENCY: Support now added for Ruby >= 1.9.3
72
+ - CONFIGURATION: Default log level now WARN (was INFO)
73
+ - BUGFIX: Remove unnecessary warning on adding +bang_readers+
74
+ - PERFORMANCE: Moderate performance gains (approx. 20%) on +cushion_reader+
data/README.md CHANGED
@@ -307,7 +307,7 @@ passerby.when_i_noticed_you == Time.now # false—1 sec later
307
307
 
308
308
  ```
309
309
 
310
- Alternatively, you can write a normal proc and call the variable's +bang_reader+ if you're worried the variable may not be set.
310
+ Alternatively, you can write a normal proc and call the variable's `bang_reader` if you're worried the variable may not be set.
311
311
 
312
312
  ```ruby
313
313
  class Person
@@ -422,12 +422,12 @@ weather_judgment: 'is it hot in here or is it just me?'
422
422
 
423
423
  ```yaml
424
424
  # config/cushion_defaults/fal/user.yaml
425
- weather_judgment: "if only it weren\'t for the leaves"
425
+ weather_judgment: "if only it weren't for the leaves"
426
426
  ```
427
427
 
428
428
  ```yaml
429
429
  # config/cushion_defaults/win/user.yaml
430
- weather_judgment: "baby it\'s cold outside"
430
+ weather_judgment: "baby it's cold outside"
431
431
  ```
432
432
 
433
433
  Combine this with the following Ruby, and we can get different defaults depending on the current meteorological season.
@@ -95,21 +95,24 @@ module CushionDefaults
95
95
  def cushion_reader(*syms)
96
96
  syms.each do |sym|
97
97
  sym = sym.to_sym
98
- sym_str = sym.to_s
99
98
  if self_or_parent_instance_method?(sym)
100
99
  CushionDefaults.log("#{self} or a parent class already has what looks like a getter method for #{sym_str}", :warn)
101
100
  end
102
- instance_variable_string = "@#{sym_str}"
101
+ instance_variable_string = "@#{sym}"
102
+
103
+ # significant performance gains from using this rather than #defaults in method below
104
+ defaults_cache = @defaults
105
+
103
106
  define_method(sym) do
104
- if instance_variable_defined?(instance_variable_string) && (CushionDefaults.conf.no_pushies? || defaults.not_pushy?(sym))
107
+ if instance_variable_defined?(instance_variable_string) && (CushionDefaults.conf.no_pushies? || defaults_cache.not_pushy?(sym))
105
108
  instance_variable_get(instance_variable_string)
106
- elsif defaults[sym].respond_to? :call
107
- defaults[sym].call(self, sym)
108
109
  else
109
- defaults[sym]
110
+ # much faster to save as var
111
+ da_default = defaults_cache[sym]
112
+ da_default.respond_to?(:call) ? da_default.call(self, sym) : da_default
110
113
  end
111
114
  end
112
- CushionDefaults.log("cushion_reader #{sym_str} established for #{self}")
115
+ CushionDefaults.log("cushion_reader #{sym} established for #{self}")
113
116
  end
114
117
  bang_reader *syms if CushionDefaults.conf.bang_things_up
115
118
  end
@@ -163,14 +166,14 @@ module CushionDefaults
163
166
  def bang_reader(*syms)
164
167
  syms.each do |sym|
165
168
  sym = sym.to_sym
166
- sym_str = "#{sym}!"
167
- if self_or_parent_instance_method?(sym)
168
- CushionDefaults.log("#{self} or a parent class already has a bang method #{sym_str}", :warn)
169
+ bang_sym = "#{sym}!".to_sym
170
+ if self_or_parent_instance_method?(bang_sym)
171
+ CushionDefaults.log("#{self} or a parent class already has a bang method #{bang_sym}", :warn)
169
172
  end
170
- define_method(sym_str.to_sym) do
173
+ define_method(bang_sym) do
171
174
  crystallize_default(sym)
172
175
  end
173
- CushionDefaults.log("bang_reader #{sym_str} established for #{self}")
176
+ CushionDefaults.log("bang_reader #{bang_sym} established for #{self}")
174
177
  end
175
178
  end
176
179
 
@@ -203,6 +206,8 @@ module CushionDefaults
203
206
 
204
207
  instance_variable_string = "@#{sym}"
205
208
 
209
+ defaults_cache = @defaults
210
+
206
211
  define_method(method_name) do |y|
207
212
  if CushionDefaults.nilish? y
208
213
  if CushionDefaults.conf.whiny_ignores
@@ -210,7 +215,7 @@ module CushionDefaults
210
215
  end
211
216
  remove_instance_variable(instance_variable_string) if instance_variable_defined?(instance_variable_string)
212
217
  else
213
- if CushionDefaults.conf.we_have_a_pushy? && defaults.pushy?(sym)
218
+ if CushionDefaults.conf.we_have_a_pushy? && defaults_cache.pushy?(sym)
214
219
  CushionDefaults.log("You are setting a value for #{sym}, but this is a pushy default and this value will not be returned by any cushion_readers.", :warn)
215
220
  end
216
221
  instance_variable_set(instance_variable_string, y)
@@ -134,7 +134,7 @@ module CushionDefaults
134
134
  self.bang_things_up = true
135
135
  self.record_in_log = true
136
136
  self.logger = Logger.new $stdout
137
- self.log_lvl = Logger::INFO
137
+ self.log_lvl = Logger::WARN
138
138
  self.whiny_yaml = false
139
139
  self.whiny_ignores = false
140
140
  self.ignore_attempts_to_set_nil = true
@@ -210,8 +210,8 @@ module CushionDefaults
210
210
  # Specifies the formatter for logger. Will not be called if a logger is assigned with +should_assign_formatter+ set to
211
211
  # false.
212
212
  def assign_formatter_to_logger
213
- logger.formatter = proc do |severity, time, progname, msg|
214
- "\nCUSHIONDEFAULTS: #{severity}\n\t\##{progname ? "#{progname} at" : "At"} #{time.strftime('%d %b %Y, %H:%M:%S%p')}\n\t#{msg}\n"
213
+ logger.formatter = proc do |severity, _time, progname, msg|
214
+ "\nCUSHIONDEFAULTS: #{severity}\n\t\##{progname if progname}\n\t#{msg}\n"
215
215
  end
216
216
  end
217
217
  end
@@ -28,7 +28,7 @@ require 'cushion_defaults/errors'
28
28
  module CushionDefaults
29
29
 
30
30
  # Version constant
31
- VERSION = '0.5.0'
31
+ VERSION = '0.5.1'
32
32
 
33
33
  # The path of the first file that +includes+ CushionDefaults.
34
34
  CALLING_PATH = File.expand_path(File.dirname($0)) + '/'
@@ -62,7 +62,7 @@ module CushionDefaults
62
62
  return unless conf.record_in_log
63
63
 
64
64
  # If caller_method_name is nil, magically get the name of the calling method
65
- caller_method_name ||= caller_locations(1,1)[0].label.to_s
65
+ caller_method_name ||= caller[0].to_s
66
66
  conf.logger.progname = caller_method_name unless caller_method_name == ''
67
67
 
68
68
  case level
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cushion_defaults
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Mitchell
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.11'
27
- - !ruby/object:Gem::Dependency
28
- name: yard
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '0.8'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '0.8'
41
27
  description: Cushion your instance variables. Get a default if a variable isn’t defined.
42
28
  DRY off your code.
43
29
  email: posgarou@gmail.com
@@ -70,7 +56,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
56
  requirements:
71
57
  - - ">="
72
58
  - !ruby/object:Gem::Version
73
- version: 2.0.0
59
+ version: 1.9.3
74
60
  required_rubygems_version: !ruby/object:Gem::Requirement
75
61
  requirements:
76
62
  - - ">="