spik 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -260,13 +260,13 @@ After that you can work with variables @post and @posts:
260
260
  Puts this line into `Gemfile` then run `$ bundle`:
261
261
 
262
262
  ``` ruby
263
- gem 'spik', '0.0.2'
263
+ gem 'spik', '0.0.3'
264
264
  ```
265
265
 
266
266
  Or if you are old-school Rails 2 developer put this into `config/environment.rb` and run `$ rake gems:install`:
267
267
 
268
268
  ``` ruby
269
- config.gem 'spik', :version => '0.0.2'
269
+ config.gem 'spik', :version => '0.0.3'
270
270
  ```
271
271
 
272
272
  Or manually install spik gem: `$ gem install spik`
@@ -1,50 +1,17 @@
1
1
  require 'spik/models'
2
2
  require 'spik/execution'
3
+ require 'spik/validators'
3
4
 
4
5
  module Spik
5
6
  include Models
6
7
  include Execution
7
-
8
- WHICH_NAMES = %w(all first)
9
- METHOD_NAMES = %w(find delete)
8
+ include Validators
10
9
 
11
10
  def method_missing(method, *args)
12
11
  args.flatten! if args.is_a? Array
13
12
  method = method.to_s
14
- if model_names.include?(method)
15
- [method, args]
16
- elsif model_names.include?(method[0..-2])
17
- [method[0..-2], args]
18
- elsif WHICH_NAMES.include?(method)
19
- if args[0] !~ /@/
20
- [method, args].flatten
21
- else
22
- args[0]
23
- end
24
- elsif METHOD_NAMES.include?(method)
25
- if args[0] !~ /@/
26
- execute_method(method, args)
27
- else
28
- instance_variable_get(args[0])
29
- end
30
- elsif !attributes.select{ |k,v| v.include? method }.empty?
31
- if args[0] == 'like'
32
- method + ' LIKE "%' + args[1] + '%"'
33
- elsif args[0].is_a? String
34
- method + ' = \'' + args[0] + '\''
35
- else
36
- method + ' = ' + args[0].to_s
37
- end
38
- elsif !class_methods.select{ |k,v| v.include? method.to_sym }.empty?
39
- execute_class_method(method, args[0], args[1])
40
- elsif method == 'like'
41
- [method, args]
42
- elsif %w(with which has have who from).include? method
43
- args.flatten
44
- elsif method == 'as'
45
- ['as__' + args[0], args[1..-1]]
46
- else
47
- [method, args]
48
- end
13
+
14
+ # TODO: catch methods, which cannot be variable name
15
+ spik_method(method, args) # or raise NoMethodError.new('There is no method "' + method + '"')
49
16
  end
50
17
  end
@@ -0,0 +1,63 @@
1
+ module Spik
2
+ module Validators
3
+ WHICH_NAMES = %w(all first)
4
+ METHOD_NAMES = %w(find delete)
5
+
6
+ def spik_method(method, args)
7
+ if model_names.include?(method)
8
+ return_value_of(:model, method, args)
9
+ elsif model_names.include?(method[0..-2])
10
+ return_value_of(:model, method[0..-2], args)
11
+ elsif WHICH_NAMES.include?(method)
12
+ return_value_of(:which, method, args)
13
+ elsif METHOD_NAMES.include?(method)
14
+ return_value_of(:method, method, args)
15
+ elsif !attributes.select{ |k,v| v.include? method }.empty?
16
+ return_value_of(:attribute, method, args)
17
+ elsif !class_methods.select{ |k,v| v.include? method.to_sym }.empty?
18
+ return_value_of(:class_method, method, args)
19
+ elsif method == 'like'
20
+ return_value_of(:like, method, args)
21
+ elsif %w(with which has have who from).include? method
22
+ return_value_of(:keyword, method, args)
23
+ elsif method == 'as'
24
+ return_value_of(:alias, method, args)
25
+ else
26
+ return_value_of(:variable, method, args)
27
+ end
28
+ end
29
+
30
+ def return_value_of(type, method, args)
31
+ case type
32
+ when :model, :like, :variable
33
+ [method, args]
34
+ when :which
35
+ if args[0] !~ /@/
36
+ [method, args].flatten
37
+ else
38
+ args[0]
39
+ end
40
+ when :sql_method
41
+ if args[0] !~ /@/
42
+ execute_method(method, args)
43
+ else
44
+ instance_variable_get(args[0])
45
+ end
46
+ when :attribute
47
+ if args[0] == 'like'
48
+ method + ' LIKE "%' + args[1] + '%"'
49
+ elsif args[0].is_a? String
50
+ method + ' = \'' + args[0] + '\''
51
+ else
52
+ method + ' = ' + args[0].to_s
53
+ end
54
+ when :class_method
55
+ execute_class_method(method, args[0], args[1])
56
+ when :keyword
57
+ args.flatten
58
+ when :alias
59
+ ['as__' + args[0], args[1..-1]]
60
+ end
61
+ end
62
+ end
63
+ end
@@ -1,3 +1,3 @@
1
1
  module Spik
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1363,3 +1363,16 @@ NameError (uninitialized constant Posts):
1363
1363
  Rendered /Users/gazay/.rvm/gems/ruby-1.9.3-head/gems/actionpack-3.1.1/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.5ms)
1364
1364
  Rendered /Users/gazay/.rvm/gems/ruby-1.9.3-head/gems/actionpack-3.1.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms)
1365
1365
  Rendered /Users/gazay/.rvm/gems/ruby-1.9.3-head/gems/actionpack-3.1.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (4.9ms)
1366
+  (0.4ms) select sqlite_version(*)
1367
+  (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
1368
+  (0.0ms) PRAGMA index_list("notices")
1369
+  (0.0ms) PRAGMA index_list("posts")
1370
+  (0.2ms) select sqlite_version(*)
1371
+  (1.0ms) CREATE TABLE "notices" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "body" text, "created_at" datetime, "updated_at" datetime)
1372
+  (7.9ms) CREATE TABLE "posts" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "body" text, "created_at" datetime, "updated_at" datetime) 
1373
+  (1.2ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
1374
+  (0.0ms) PRAGMA index_list("schema_migrations")
1375
+  (1.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
1376
+  (0.1ms) SELECT version FROM "schema_migrations"
1377
+  (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('20111022090628')
1378
+  (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('20111022073857')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spik
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-26 00:00:00.000000000 Z
12
+ date: 2011-10-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &2153723280 !ruby/object:Gem::Requirement
16
+ requirement: &2153494400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.1
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2153723280
24
+ version_requirements: *2153494400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &2153722860 !ruby/object:Gem::Requirement
27
+ requirement: &2153493980 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2153722860
35
+ version_requirements: *2153493980
36
36
  description: You can say something and controller understands you
37
37
  email:
38
38
  - alex.gaziev@gmail.com
@@ -42,7 +42,7 @@ extra_rdoc_files: []
42
42
  files:
43
43
  - lib/spik/execution.rb
44
44
  - lib/spik/models.rb
45
- - lib/spik/tmp.rb
45
+ - lib/spik/validators.rb
46
46
  - lib/spik/version.rb
47
47
  - lib/spik.rb
48
48
  - lib/tasks/spik_tasks.rake
@@ -80,6 +80,7 @@ files:
80
80
  - test/dummy/db/migrate/20111022090628_create_notices.rb
81
81
  - test/dummy/db/production.sqlite3
82
82
  - test/dummy/db/schema.rb
83
+ - test/dummy/db/test.sqlite3
83
84
  - test/dummy/log/development.log
84
85
  - test/dummy/log/production.log
85
86
  - test/dummy/log/test.log
@@ -97,10 +98,7 @@ files:
97
98
  - test/dummy/tmp/cache/assets/DD0/030/sprockets%2F6fea4f8c8ac6003482feb9df8afa0361
98
99
  - test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af
99
100
  - test/dummy/tmp/cache/assets/E54/940/sprockets%2Fe5c4f565eaabc3ea3cc4006bf5b9c6ce
100
- - test/integration/missing_method_test.rb
101
- - test/spik_test.rb
102
- - test/test_helper.rb
103
- homepage:
101
+ homepage: https://github.com/gazay/spik
104
102
  licenses: []
105
103
  post_install_message:
106
104
  rdoc_options: []
@@ -156,6 +154,7 @@ test_files:
156
154
  - test/dummy/db/migrate/20111022090628_create_notices.rb
157
155
  - test/dummy/db/production.sqlite3
158
156
  - test/dummy/db/schema.rb
157
+ - test/dummy/db/test.sqlite3
159
158
  - test/dummy/log/development.log
160
159
  - test/dummy/log/production.log
161
160
  - test/dummy/log/test.log
@@ -173,6 +172,3 @@ test_files:
173
172
  - test/dummy/tmp/cache/assets/DD0/030/sprockets%2F6fea4f8c8ac6003482feb9df8afa0361
174
173
  - test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af
175
174
  - test/dummy/tmp/cache/assets/E54/940/sprockets%2Fe5c4f565eaabc3ea3cc4006bf5b9c6ce
176
- - test/integration/missing_method_test.rb
177
- - test/spik_test.rb
178
- - test/test_helper.rb
@@ -1,50 +0,0 @@
1
-
2
- # def can(*args)
3
- # p args.first
4
- # end
5
- #
6
- # def you(*args)
7
- # args.first
8
- # end
9
- #
10
- # def say(*args)
11
- # args.first
12
- # end
13
-
14
- def method_missing(m, *a)
15
- m.to_s
16
- end
17
-
18
- # can you say please?
19
-
20
- def make(*args)
21
- p args.first
22
- end
23
-
24
- def me(*args)
25
- case args.first
26
- when 'happy!'
27
- 'smile, bitch ^_^'
28
- else
29
- "r u sad bastard? c'mon!!!"
30
- end
31
- end
32
-
33
- def girl(*args)
34
- case args.first
35
- when /happy/
36
- ':P'
37
- else
38
- 'SLAP!'
39
- end
40
- end
41
-
42
- make me happy!
43
-
44
- make girl happy
45
-
46
- chain = Proc.new do |*methods|
47
- p methods.to_s + '123'
48
- end
49
-
50
- p chain.call(make.to_proc)
@@ -1,12 +0,0 @@
1
- # require 'test_helper'
2
- #
3
- # class MissingMethodTest < ActiveSupport::IntegrationCase
4
- # test 'pdf request sends a pdf as file' do
5
- # visit home_path
6
- # end
7
- #
8
- # protected
9
- # def headers
10
- # page.response_headers
11
- # end
12
- # end
@@ -1,13 +0,0 @@
1
- require 'test_helper'
2
-
3
- class SpikTest < ActiveSupport::TestCase
4
- test "truth" do
5
- assert_kind_of Module, Spik
6
- end
7
-
8
- test "should return first post" do
9
- include Spik
10
- find first post
11
- assert_not_nil @post
12
- end
13
- end
@@ -1,10 +0,0 @@
1
- # Configure Rails Environment
2
- ENV["RAILS_ENV"] = "test"
3
-
4
- require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
- require "rails/test_help"
6
-
7
- Rails.backtrace_cleaner.remove_silencers!
8
-
9
- # Load support files
10
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }