easy_attributes 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -37,7 +37,7 @@ Declaration:
37
37
 
38
38
  will define:
39
39
  field() # => value ### if orm == :attr, attr_accessor will be installed for the attribute
40
- field=(value) # => value
40
+ field=(value) # => value ### for active_model classes
41
41
  field_sym() # => :name
42
42
  field_sym=(symbol) # => value
43
43
  field_values() # => {:name=>value, ...}
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{easy_attributes}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Allen Fair"]
12
- s.date = %q{2010-04-28}
12
+ s.date = %q{2010-07-29}
13
13
  s.description = %q{Easy Attributes is a Ruby DSL to give more control to attributes.}
14
14
  s.email = %q{allen.fair@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
31
31
  s.homepage = %q{http://github.com/afair/easy_attributes}
32
32
  s.rdoc_options = ["--charset=UTF-8"]
33
33
  s.require_paths = ["lib"]
34
- s.rubygems_version = %q{1.3.6}
34
+ s.rubygems_version = %q{1.3.7}
35
35
  s.summary = %q{Easy Attributes for Ruby}
36
36
  s.test_files = [
37
37
  "test/helper.rb",
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
42
42
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
43
  s.specification_version = 3
44
44
 
45
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
46
  else
47
47
  end
48
48
  else
@@ -3,8 +3,6 @@ module EasyAttributes
3
3
 
4
4
  def self.included(base) #:nodoc:
5
5
  base.extend( ClassMethods )
6
- #EasyAttributes::Config
7
- #puts "easy_attributes included into #{base}"
8
6
  end
9
7
 
10
8
  # Configuration class for EasyAttributes, set at load time.
@@ -91,6 +89,8 @@ module EasyAttributes
91
89
  code = ''
92
90
  if EasyAttributes::Config.orm == :active_model
93
91
  validates_inclusion_of attribute, :in=>hash.values
92
+ # Add named_scope (scope) for each value
93
+ hash.each { |k,v| code += "named_scope :#{k}, :conditions=>{:#{attribute}=>#{v.inspect}}\n" }
94
94
  else
95
95
  attr_accessor attribute
96
96
  end
@@ -105,9 +105,16 @@ module EasyAttributes
105
105
  EasyAttributes::Config.attributes["#{name}"]
106
106
  end
107
107
  def #{attribute}_is?(*args)
108
- EasyAttributes.value_is?("#{name}", attribute, *args)
108
+ EasyAttributes.value_is?("#{name}", #{attribute}, *args)
109
109
  end
110
110
  )
111
+ if EasyAttributes::Config.orm == :active_model
112
+ code += %Q(
113
+ def #{attribute}=(v)
114
+ self[:#{attribute}] = v.is_a?(Symbol) ? EasyAttributes.value_for_sym("#{attribute}", v) : v;
115
+ end
116
+ )
117
+ end
111
118
  #puts code
112
119
  class_eval code
113
120
  end
@@ -195,6 +202,7 @@ module EasyAttributes
195
202
  # Returns the defined symbol for the given value on the attribute
196
203
  def self.sym_for_value(attribute, value)
197
204
  EasyAttributes::Config.attributes[attribute].each {|k,v| return k if v==value}
205
+ raise "EasyAttribute #{attribute} symbol not found for #{value}"
198
206
  end
199
207
 
200
208
  def self.value_is?(attribute, value, *args)
@@ -212,7 +220,7 @@ module EasyAttributes
212
220
  #when :not, :not_in
213
221
  # ! args.include? EasyAttributes::Config.attributes[attribute].keys
214
222
  else
215
- args.include? EasyAttributes.sym_for_value(v)
223
+ args.include? EasyAttributes.sym_for_value(attribute, value)
216
224
  end
217
225
  end
218
226
 
@@ -21,6 +21,10 @@ class TestEasyAttributes < Test::Unit::TestCase
21
21
  self.tav_sym = :k2
22
22
  assert_equal tav, 2
23
23
  assert_equal tav_sym, :k2
24
+ assert_equal tav_is?(:k2), true
25
+ assert_equal tav_is?(:k1, :k3), false
26
+ #self.tav = :k1
27
+ #assert_equal tav, 1
24
28
  end
25
29
 
26
30
  def test_like
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_attributes
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 31
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 1
8
- - 0
9
- version: 0.1.0
9
+ - 2
10
+ version: 0.1.2
10
11
  platform: ruby
11
12
  authors:
12
13
  - Allen Fair
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-04-28 00:00:00 -04:00
18
+ date: 2010-07-29 00:00:00 -04:00
18
19
  default_executable:
19
20
  dependencies: []
20
21
 
@@ -48,23 +49,27 @@ rdoc_options:
48
49
  require_paths:
49
50
  - lib
50
51
  required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
51
53
  requirements:
52
54
  - - ">="
53
55
  - !ruby/object:Gem::Version
56
+ hash: 3
54
57
  segments:
55
58
  - 0
56
59
  version: "0"
57
60
  required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
58
62
  requirements:
59
63
  - - ">="
60
64
  - !ruby/object:Gem::Version
65
+ hash: 3
61
66
  segments:
62
67
  - 0
63
68
  version: "0"
64
69
  requirements: []
65
70
 
66
71
  rubyforge_project:
67
- rubygems_version: 1.3.6
72
+ rubygems_version: 1.3.7
68
73
  signing_key:
69
74
  specification_version: 3
70
75
  summary: Easy Attributes for Ruby