object_attorney 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module ObjectAttorney
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
@@ -59,8 +59,6 @@ module ObjectAttorney
59
59
  private #################### PRIVATE METHODS DOWN BELOW ######################
60
60
 
61
61
  def self.included(base)
62
- base.extend(ClassMethods)
63
-
64
62
  base.class_eval do
65
63
  include ActiveModel::Validations
66
64
  include ActiveModel::Conversion
@@ -73,6 +71,8 @@ module ObjectAttorney
73
71
  override_validations? ? true : super
74
72
  end
75
73
  end
74
+
75
+ base.extend(ClassMethods)
76
76
  end
77
77
 
78
78
  def override_validations?
@@ -87,13 +87,17 @@ module ObjectAttorney
87
87
  module ClassMethods
88
88
 
89
89
  def represents(represented_object, represented_object_class = nil)
90
- represented_object_class ||= represented_object.to_s.camelize.constantize
90
+ @represented_object_class = represented_object_class || represented_object.to_s.camelize.constantize
91
91
 
92
92
  define_method(represented_object) do
93
- @represented_object ||= represented_object_class.new
93
+ @represented_object ||= self.class.represented_object_class.new
94
94
  end
95
95
  end
96
96
 
97
+ def represented_object_class
98
+ @represented_object_class
99
+ end
100
+
97
101
  def delegate_properties(*properties, options)
98
102
  properties.each { |property| delegate_propertiy(property, options) }
99
103
  end
@@ -118,6 +122,19 @@ module ObjectAttorney
118
122
  @black_list ||= ["_destroy"]
119
123
  end
120
124
 
125
+ def human_attribute_name(attribute_key_name, options = {})
126
+ defaults = ["#{represented_object_class.name.underscore}.#{attribute_key_name}"]
127
+ defaults << options[:default] if options[:default]
128
+ defaults.flatten!
129
+ defaults << attribute_key_name.to_s.humanize
130
+ options[:count] ||= 1
131
+ I18n.translate(defaults.shift, options.merge(:default => defaults, :scope => [:activerecord, :attributes]))
132
+ end
133
+
134
+ def model_name
135
+ ActiveModel::Name.new represented_object_class
136
+ end
137
+
121
138
  end
122
139
 
123
140
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: object_attorney
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
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: 2013-08-14 00:00:00.000000000 Z
12
+ date: 2013-09-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler