attribute_struct 0.2.24 → 0.2.26

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: 1851f044804aa76edf2e80c3b6544b947c9f2b0a
4
- data.tar.gz: 4034992ed7b20c3bee4f817b3cc3bdceeb8eade1
3
+ metadata.gz: ffc1b51f9ac3efde6741c990da79571eb312b3a1
4
+ data.tar.gz: 94ce77d6090d14cbd7ed7d6a214fb0cc6629c22a
5
5
  SHA512:
6
- metadata.gz: 6402258e7f98e8c8918397441c6aced1e842214a4c1b97ad76b27de92c95b6c3449b42992619d4166e8cc82ff83c4bce36472c4c637079313590083acb1a4744
7
- data.tar.gz: 9036ca42dc57baa17bb8489016e0f2f1e630c87ab3aafe697e3086d485afce76ac8045ea45941fdd2e0890fac1849a2ba7d92e5edc9aa35c0c33e90a409b9f87
6
+ metadata.gz: da6542c56f2cafbe72464d14928e77b7cc1833c1b112a31914605f9d5a6af51c464886e8a3cbe5e702cf57e6d5b50d2bee41d8a1e27de23dd8490abe8fff32a0
7
+ data.tar.gz: e3830ada5e826def4c2663264f2a2e578f88f2b72f4ae9b41247320f4bb88d3d2b2264280c267ecbcd96eb0202f8aff0cef3d8d7e006935a1cd1b830fd3cd895
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## v0.2.26
2
+ * Add support for lowercase leading camel casing
3
+
1
4
  ## v0.2.24
2
5
  * Fix `#_root` helper to properly check for parent
3
6
  * Always use the `#_klass_new` helper
@@ -10,5 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.homepage = 'http://github.com/chrisroberts/attribute_struct'
11
11
  s.description = 'Attribute structures'
12
12
  s.require_path = 'lib'
13
+ s.add_runtime_dependency 'bogo', '>= 0.1.31', '< 0.3.0'
14
+ s.add_development_dependency 'minitest'
13
15
  s.files = Dir['lib/**/*'] + %w(attribute_struct.gemspec README.md CHANGELOG.md CONTRIBUTING.md LICENSE)
14
16
  end
@@ -1,5 +1,6 @@
1
+ require 'bogo'
2
+ require 'attribute_struct/attribute_struct'
1
3
 
2
- autoload :AttributeStruct, 'attribute_struct/attribute_struct'
3
4
  autoload :MonkeyCamels, 'attribute_struct/monkey_camels'
4
5
  autoload :CamelString, 'attribute_struct/monkey_camels'
5
6
  autoload :IrbCompat, 'attribute_struct/irb_compat'
@@ -6,8 +6,20 @@ class AttributeStruct < BasicObject
6
6
 
7
7
  class << self
8
8
 
9
+ # @return [Hash] valid styles and mapped value
10
+ VALID_CAMEL_STYLES = {
11
+ :bactrain => :no_leading,
12
+ :no_leading_hump => :no_leading,
13
+ :no_leading => :no_leading,
14
+ :dromedary => :leading,
15
+ :leading_hump => :leading,
16
+ :leading => :leading
17
+ }
18
+
9
19
  # @return [Truthy, Falsey] global flag for camel keys
10
20
  attr_reader :camel_keys
21
+ # @return [Symbol] camel key style
22
+ attr_reader :camel_style
11
23
 
12
24
  # Automatically converts keys to camel case
13
25
  #
@@ -18,6 +30,28 @@ class AttributeStruct < BasicObject
18
30
  @camel_keys = !!val
19
31
  end
20
32
 
33
+ # Set default style of camel keys
34
+ #
35
+ # @param val [Symbol]
36
+ # @return [Symbol]
37
+ def camel_style=(val)
38
+ @camel_style = validate_camel_style(val)
39
+ end
40
+
41
+ # Validate requested camel style and return mapped value used
42
+ # internally
43
+ #
44
+ # @param style [Symbol]
45
+ # @return [Symbol]
46
+ # @raises [ArgumentError]
47
+ def validate_camel_style(style)
48
+ if(VALID_CAMEL_STYLES.has_key?(style))
49
+ VALID_CAMEL_STYLES[style]
50
+ else
51
+ raise ArgumentError.new "Unsupported camel style provided `#{style.inspect}`! (Allowed: #{VALID_CAMEL_STYLES.keys(&:inspect).join(', ')})"
52
+ end
53
+ end
54
+
21
55
  # Loads helpers for camel casing
22
56
  def load_the_camels
23
57
  unless(@camels_loaded)
@@ -53,6 +87,8 @@ class AttributeStruct < BasicObject
53
87
 
54
88
  # @return [Truthy, Falsey] current camelizing setting
55
89
  attr_reader :_camel_keys
90
+ # @return [Symbol] current camel style
91
+ attr_reader :_camel_style
56
92
  # @return [AtributeStruct::AttributeHash, Mash] holding space for state
57
93
  attr_reader :_arg_state
58
94
 
@@ -115,6 +151,14 @@ class AttributeStruct < BasicObject
115
151
  @_camel_keys = !!val
116
152
  end
117
153
 
154
+ # Set style of camel keys
155
+ #
156
+ # @param val [Symbol]
157
+ # @return [Symbol]
158
+ def _camel_style=(val)
159
+ @_camel_style = ::AttributeStruct.validate_camel_style(val)
160
+ end
161
+
118
162
  # Direct data access
119
163
  #
120
164
  # @param key [String, Symbol]
@@ -408,9 +452,13 @@ class AttributeStruct < BasicObject
408
452
  end
409
453
  end
410
454
  if((_camel_keys && key._camel?) || args.include?(:force))
411
- key.to_s.split('_').map do |part|
412
- "#{part[0,1].upcase}#{part[1,part.size]}"
413
- end.join.to_sym
455
+ camel_args = [key]
456
+ if(key._hump_style || _camel_style == :no_leading)
457
+ unless(key._hump_style == :leading_hump)
458
+ camel_args << false
459
+ end
460
+ end
461
+ ::Bogo::Utility.camel(*camel_args)
414
462
  else
415
463
  key
416
464
  end
@@ -433,6 +481,7 @@ class AttributeStruct < BasicObject
433
481
  n._camel_keys_set(_camel_keys_action)
434
482
  end
435
483
  n._camel_keys = _camel_keys
484
+ n._camel_style = _camel_style if _camel_style
436
485
  n._parent(self)
437
486
  n
438
487
  end
@@ -64,6 +64,34 @@ unless(defined?(MonkeyCamels))
64
64
  end
65
65
  alias_method :camel!, :_hump
66
66
 
67
+ # @return [Symbol, NilClass] style of hump
68
+ def _hump_style
69
+ @__hump_style
70
+ end
71
+ alias_method :hump_style!, :_hump_style
72
+
73
+ # Set hump style to non-leading upcase
74
+ #
75
+ # @return [self]
76
+ def _bactrain
77
+ @__not_camel = false
78
+ @__hump_style = :no_leading_hump
79
+ self
80
+ end
81
+ alias_method :bactrain!, :_bactrain
82
+ alias_method :no_leading_hump!, :_bactrain
83
+
84
+ # Set hump style to leading upcase
85
+ #
86
+ # @return [self]
87
+ def _dromedary
88
+ @__not_camel = false
89
+ @__hump_style = :leading_hump
90
+ self
91
+ end
92
+ alias_method :dromedary!, :_dromedary
93
+ alias_method :leading_hump!, :_dromedary
94
+
67
95
  end
68
96
 
69
97
  end
@@ -78,6 +106,7 @@ unless(defined?(MonkeyCamels))
78
106
  super
79
107
  if(val.respond_to?(:_camel?))
80
108
  _no_hump unless val._camel?
109
+ @__hump_style = val._hump_style
81
110
  end
82
111
  end
83
112
  end
@@ -1,6 +1,4 @@
1
- require 'attribute_struct/attribute_struct'
2
-
3
- class AttributeStruct
1
+ class AttributeStruct < BasicObject
4
2
  # Current library version
5
- VERSION = ::Gem::Version.new('0.2.24')
3
+ VERSION = ::Gem::Version.new('0.2.26')
6
4
  end
metadata CHANGED
@@ -1,15 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attribute_struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.24
4
+ version: 0.2.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-09 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2015-12-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bogo
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.31
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 0.3.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.1.31
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 0.3.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: minitest
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
13
47
  description: Attribute structures
14
48
  email: chrisroberts.code@gmail.com
15
49
  executables: []