simple_model 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
+
3
4
  # Specify your gem's dependencies in simple_model.gemspec
4
5
  gemspec
6
+
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Joshua T. Mckinney
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = simple_model
2
+
3
+ Testing
4
+
5
+ == Contributing to simple_model
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Joshua T. Mckinney. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
@@ -50,12 +50,14 @@ module SimpleModel
50
50
  module ClassMethods
51
51
  def has_attributes(*attrs)
52
52
  attrs.each do |attr|
53
+
53
54
  attr_reader attr
54
55
 
55
56
  define_method("#{attr.to_s}=") do |val|
56
57
  instance_variable_set("@#{attr}", val)
57
58
  attributes[attr] = val
58
59
  val
60
+
59
61
  end
60
62
  end
61
63
  end
@@ -64,12 +66,14 @@ module SimpleModel
64
66
  def has_booleans(*attrs)
65
67
  options = attrs.extract_options!
66
68
  attrs.each do |attr|
69
+
67
70
  attr_reader attr
68
71
  define_reader_with_options(attr,options)
69
72
  define_method("#{attr.to_s}=") do |val|
70
73
  instance_variable_set("@#{attr}", val.to_s.to_b)
71
74
  attributes[attr] = val
72
75
  val
76
+
73
77
  end
74
78
 
75
79
  define_method ("#{attr.to_s}?") do
@@ -82,12 +86,14 @@ module SimpleModel
82
86
  def has_ints(*attrs)
83
87
  options = attrs.extract_options!
84
88
  attrs.each do |attr|
85
- attr_accessor attr
89
+ attr_accessor reader
86
90
  define_reader_with_options(attr,options)
91
+
87
92
  define_method("#{attr.to_s}=") do |val|
88
93
  instance_variable_set("@#{attr}", val.to_i)
89
94
  attributes[attr] = val
90
95
  val
96
+
91
97
  end
92
98
  end
93
99
  end
@@ -96,11 +102,13 @@ module SimpleModel
96
102
  def has_currency(*attrs)
97
103
  options = attrs.extract_options!
98
104
  attrs.each do |attr|
105
+ attr_reader attr
99
106
  define_reader_with_options(attr,options)
100
107
  define_method("#{attr.to_s}=") do |val|
101
- instance_variable_set("@#{attr}", val.to_currency)
108
+ instance_variable_set("@#{attr}", val.to_s.to_currency)
102
109
  attributes[attr] = val
103
110
  val
111
+
104
112
  end
105
113
  end
106
114
  end
@@ -108,6 +116,7 @@ module SimpleModel
108
116
  def has_floats(*attrs)
109
117
  options = attrs.extract_options!
110
118
  attrs.each do |attr|
119
+
111
120
  attr_reader attr
112
121
  define_reader_with_options(attr,options)
113
122
 
@@ -115,6 +124,7 @@ module SimpleModel
115
124
  instance_variable_set("@#{attr}", val.to_f)
116
125
  attributes[attr] = val
117
126
  val
127
+
118
128
  end
119
129
  end
120
130
  end
@@ -123,12 +133,14 @@ module SimpleModel
123
133
  def has_dates(*attrs)
124
134
  options = attrs.extract_options!
125
135
  attrs.each do |attr|
126
- attr_reader
136
+
137
+ attr_reader attr
127
138
  define_reader_with_options(attr,options)
128
139
  define_method("#{attr.to_s}=") do |val|
129
140
  instance_variable_set("@#{attr}", val.to_date)
130
141
  attributes[attr] = val
131
142
  val
143
+
132
144
  end
133
145
  end
134
146
  end
@@ -137,7 +149,8 @@ module SimpleModel
137
149
  def has_times(*attrs)
138
150
  options = attrs.extract_options!
139
151
  attrs.each do |attr|
140
- attr_reader
152
+
153
+ attr_reader attr
141
154
  define_reader_with_options(attr,options)
142
155
  define_method("#{attr.to_s}=") do |val|
143
156
 
@@ -148,9 +161,11 @@ module SimpleModel
148
161
  end
149
162
  end
150
163
 
164
+
151
165
  def fetch_alias_name(attr)
152
166
  alias_name = (attr.to_s << "_old=").to_sym
153
167
  self.module_eval("alias #{alias_name} #{attr}")
168
+
154
169
  alias_name
155
170
  end
156
171
 
@@ -1,6 +1,8 @@
1
1
  module ExtendCore
2
+
2
3
  require 'time'
3
4
  require 'date'
5
+
4
6
  Float.class_eval do
5
7
  def round_to(precision)
6
8
  split = precision.to_s.split(".")
@@ -104,5 +106,6 @@ require 'date'
104
106
  def to_b
105
107
  self > 0
106
108
  end
109
+
107
110
  end
108
111
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleModel
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -9,7 +9,9 @@ describe SimpleModel::Attributes do
9
9
  @init = TestInit.new(:test1 => "1", :test2 => '2')
10
10
  end
11
11
 
12
+
12
13
  it "should set provided attributes on initialize" do
14
+
13
15
  @init.test1.should eql("1")
14
16
  @init.test2.should eql("2")
15
17
  end
@@ -61,4 +61,3 @@ describe ExtendCore, 'String.rb' do
61
61
  end
62
62
 
63
63
  end
64
-
@@ -19,10 +19,12 @@ describe SimpleModel do
19
19
  #a.test.should be_false
20
20
  end
21
21
  it 'Should add a error setter' do
22
+
22
23
  class TestStuff < SimpleModel::Base
23
24
  has_attributes :test_attr
24
25
  end
25
26
  a = TestStuff.new
27
+
26
28
  a.errors.add(:test_attr, "test")
27
29
  a.errors?.should be_true
28
30
  end
data/spec/spec_helper.rb CHANGED
@@ -4,10 +4,14 @@ require 'simple_model'
4
4
  require 'spec'
5
5
 
6
6
 
7
+
7
8
  # Requires supporting files with custom matchers and macros, etc,
8
9
  # in ./support/ and its subdirectories.
9
10
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
11
 
12
+
11
13
  Spec::Runner.configure do |config|
12
-
14
+
15
+
13
16
  end
17
+
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 0
8
7
  - 1
9
- version: 0.0.1
8
+ - 0
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joshua T Mckinney
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-27 00:00:00 -06:00
17
+ date: 2010-12-28 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -45,6 +45,8 @@ files:
45
45
  - .autotest
46
46
  - .gitignore
47
47
  - Gemfile
48
+ - LICENSE.txt
49
+ - README.rdoc
48
50
  - Rakefile
49
51
  - lib/simple_model.rb
50
52
  - lib/simple_model/attributes.rb