casting_attr_accessor 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,7 +30,7 @@ module CastingAttrAccessor
30
30
  private
31
31
  def parser_for_attributes(*args)
32
32
  options = args.extract_options!
33
- parser_class = get_parser(options.delete(:as) || :string)
33
+ parser_class = get_parser_class(options.delete(:as) || :string)
34
34
  args.each do |attr|
35
35
  yield parser_class.new(self, attr, options)
36
36
  end
@@ -40,7 +40,7 @@ module CastingAttrAccessor
40
40
  parser.readers.each do |reader|
41
41
  define_method reader do
42
42
  unless instance_variable_defined?(parser.storage_var)
43
- instance_variable_set(parser.storage_var, parser.default_value)
43
+ instance_variable_set(parser.storage_var, parser.default_value(self))
44
44
  end
45
45
  instance_variable_get(parser.storage_var)
46
46
  end
@@ -55,7 +55,7 @@ module CastingAttrAccessor
55
55
  end
56
56
  end
57
57
 
58
- def get_parser(name)
58
+ def get_parser_class(name)
59
59
  case name
60
60
  when Class
61
61
  unless type_name < CastingAttrAccessor::Parser::Base
@@ -10,10 +10,10 @@ module CastingAttrAccessor
10
10
  @options = options || {}
11
11
  end
12
12
 
13
- def default_value
13
+ def default_value(object)
14
14
  default = options[:default]
15
15
  case default
16
- when Proc then default.call(model)
16
+ when Proc then default.call(object)
17
17
  else default
18
18
  end
19
19
  end
@@ -6,8 +6,8 @@ module CastingAttrAccessor
6
6
  super.to_s.gsub('?', '').to_sym
7
7
  end
8
8
 
9
- def default_value
10
- super || false
9
+ def default_value(object)
10
+ super(object) || false
11
11
  end
12
12
 
13
13
  def readers
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: casting_attr_accessor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-23 00:00:00.000000000 Z
12
+ date: 2012-11-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -35,20 +35,20 @@ extensions: []
35
35
  extra_rdoc_files: []
36
36
  files:
37
37
  - lib/casting_attr_accessor.rb
38
- - lib/casting_attr_accessor/parser/string.rb
39
- - lib/casting_attr_accessor/parser/ids.rb
40
- - lib/casting_attr_accessor/parser/array.rb
38
+ - lib/casting_attr_accessor/parser.rb
39
+ - lib/casting_attr_accessor/parser/base.rb
40
+ - lib/casting_attr_accessor/parser/flags.rb
41
41
  - lib/casting_attr_accessor/parser/date.rb
42
- - lib/casting_attr_accessor/parser/float.rb
43
- - lib/casting_attr_accessor/parser/fixnum.rb
44
42
  - lib/casting_attr_accessor/parser/enum.rb
45
- - lib/casting_attr_accessor/parser/base.rb
46
- - lib/casting_attr_accessor/parser/boolean.rb
43
+ - lib/casting_attr_accessor/parser/float.rb
47
44
  - lib/casting_attr_accessor/parser/symbol.rb
48
- - lib/casting_attr_accessor/parser/flags.rb
45
+ - lib/casting_attr_accessor/parser/boolean.rb
46
+ - lib/casting_attr_accessor/parser/ids.rb
47
+ - lib/casting_attr_accessor/parser/array.rb
48
+ - lib/casting_attr_accessor/parser/fixnum.rb
49
+ - lib/casting_attr_accessor/parser/string.rb
49
50
  - lib/casting_attr_accessor/parser/date_time.rb
50
- - lib/casting_attr_accessor/parser.rb
51
- homepage: https://github.com/tlux/casting_attr_accessor
51
+ homepage: http://rubygems.org/gems/casting_attr_accessor
52
52
  licenses: []
53
53
  post_install_message:
54
54
  rdoc_options: []
@@ -73,3 +73,4 @@ signing_key:
73
73
  specification_version: 3
74
74
  summary: Strongly typed, casting, non-persistent model attributes for ActiveModel.
75
75
  test_files: []
76
+ has_rdoc: