apiway 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e359eb647d0797382fe8d4960a74390d9e453527
4
- data.tar.gz: a9bb742d1d44c02040161ed4332efe8cb5b425c1
3
+ metadata.gz: b0639d207553c6f64190cfee587fa464ce9eb729
4
+ data.tar.gz: db8521d27328c3438bab63f8893a131772f10cff
5
5
  SHA512:
6
- metadata.gz: 87bbe8b23efea6c9d3b9d97c41771e26331e139bcfe2bd122babd82481373093111deafdf7382da9f31c626d24617695c2f5877b170f3412ad1052056ae27145
7
- data.tar.gz: 2375c4599a6acbcbd3434fc205692cb2362582fd1afa6e71bae644d3b71ae93b7de2a0e11c0bc67435e6428fd5c0d0a99f5a0580eac67efcdab66ea614dd4ff0
6
+ metadata.gz: c1cb5448f5a7e551425f433fff45c1ef2f03c9aa6ce7a98d6cdcbfb64631ea320a6b04ded5e92d1cd29c8fed29928c920a00b6f6683519c57ebeee955856dfae
7
+ data.tar.gz: c331b332b90692217a269b86322f155fec29eeab2aec83e954a4e7d8d2792aec028ba39f4e11a03fae63cb64fd5e62af19d4f5c693ac97adc76aabd4d4a8a30f
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -37,11 +37,11 @@ module Apiway
37
37
  )
38
38
  .map{ |path| Dir[ File.join( root, path ) ] }
39
39
  .flatten.uniq.each{ |path| require path }
40
-
41
-
40
+
41
+
42
42
  LoggerBase::apiway_log_level apiway_log
43
43
  LoggerBase::activerecord_log_level activerecord_log
44
-
44
+
45
45
 
46
46
  def self.tasks
47
47
  require 'sinatra/activerecord/rake'
@@ -12,7 +12,7 @@ module Apiway
12
12
  create: [ '-n', 'n', 'new' ],
13
13
  help: [ '-h', 'h', 'help' ]
14
14
  }
15
-
15
+
16
16
  DESC = {
17
17
  version: 'Show gem version',
18
18
  server: 'Launch thin server, alias for `bundle exec thin start`',
@@ -46,10 +46,10 @@ module Apiway
46
46
  def create( *args )
47
47
  generate "app", *args
48
48
  end
49
-
49
+
50
50
  def help( *args )
51
51
  puts "\n Apiway commands: \n\n"
52
- HANDLERS.each do |handler, commands|
52
+ HANDLERS.each do |handler, commands|
53
53
  puts " [#{ commands.join( "], [" ) }]".ljust(30) << "# #{ DESC[ handler ] } "
54
54
  end
55
55
  end
@@ -1,124 +1,124 @@
1
- module Apiway
2
-
3
- module Controller
4
-
5
-
6
-
7
- class << self
8
-
9
- def included( base )
10
- base.class_eval do
11
- extend ClassMethods
12
- include InstanceMethods
13
- end
14
- end
15
-
16
- end
17
-
18
-
19
-
20
- module ClassMethods
21
-
22
- def action( name, &block )
23
- block_given? ? actions[ name ] = block : actions[ name ] or raise ControllerActionNotExists.new( self.name, name )
24
- end
25
-
26
- def before_action( method_name, only: [], except: [] )
27
- register_filter :before, method_name, only, except
28
- end
29
-
30
- def after_action( method_name, only: [], except: [] )
31
- register_filter :after, method_name, only, except
32
- end
33
-
34
- def select_filters( type, action_name )
35
- filters( type ).select do |method_name, only, except|
36
- ( only.empty? || only.include?( action_name ) ) && ( except.empty? || !except.include?( action_name ) )
37
- end
38
- end
39
-
40
-
41
- private
42
-
43
- def actions
44
- @actions ||= {}
45
- end
46
-
47
- def filters( type )
48
- ( @filters ||= {} )[ type ] ||= []
49
- end
50
-
51
- def register_filter( type, method_name, only, except )
52
- only = [].push( only ).flatten
53
- except = [].push( except ).flatten
54
- filters( type ) << [ method_name, only, except ]
55
- end
56
-
57
- end
58
-
59
-
60
-
61
- module InstanceMethods
62
-
63
- def initialize( action_name, client, params = {} )
64
- @action_name = action_name
65
- @action = self.class.action @action_name
66
- @client = client
67
- @params = params
68
- end
69
-
70
- def run
71
- begin
72
- run_filters :before
73
- result = run_action
74
- run_filters :after
75
- rescue ControllerError => e
76
- failure e.params
77
- else
78
- success result
79
- end
80
- end
81
-
82
-
83
- protected
84
-
85
- attr_reader :client, :params
86
-
87
- def trigger( *args )
88
- add_method_to_call :trigger, args
89
- end
90
-
91
- def error( params )
92
- raise ControllerError, params
93
- end
94
-
95
-
96
- private
97
-
98
- def run_action
99
- instance_eval &@action
100
- end
101
-
102
- def run_filters( type )
103
- self.class.select_filters( type, @action_name ).each { |method_name, only, except| send method_name }
104
- end
105
-
106
- def add_method_to_call( method, args )
107
- Thread.current[ :methods_to_call ] << [ method, args ]
108
- end
109
-
110
- def success( *args )
111
- add_method_to_call :success, args
112
- end
113
-
114
- def failure( *args )
115
- add_method_to_call :failure, args
116
- end
117
-
118
- end
119
-
120
-
121
-
122
- end
123
-
124
- end
1
+ module Apiway
2
+
3
+ module Controller
4
+
5
+
6
+
7
+ class << self
8
+
9
+ def included( base )
10
+ base.class_eval do
11
+ extend ClassMethods
12
+ include InstanceMethods
13
+ end
14
+ end
15
+
16
+ end
17
+
18
+
19
+
20
+ module ClassMethods
21
+
22
+ def action( name, &block )
23
+ block_given? ? actions[ name ] = block : actions[ name ] or raise ControllerActionNotExists.new( self.name, name )
24
+ end
25
+
26
+ def before_action( method_name, only: [], except: [] )
27
+ register_filter :before, method_name, only, except
28
+ end
29
+
30
+ def after_action( method_name, only: [], except: [] )
31
+ register_filter :after, method_name, only, except
32
+ end
33
+
34
+ def select_filters( type, action_name )
35
+ filters( type ).select do |method_name, only, except|
36
+ ( only.empty? || only.include?( action_name ) ) && ( except.empty? || !except.include?( action_name ) )
37
+ end
38
+ end
39
+
40
+
41
+ private
42
+
43
+ def actions
44
+ @actions ||= {}
45
+ end
46
+
47
+ def filters( type )
48
+ ( @filters ||= {} )[ type ] ||= []
49
+ end
50
+
51
+ def register_filter( type, method_name, only, except )
52
+ only = [].push( only ).flatten
53
+ except = [].push( except ).flatten
54
+ filters( type ) << [ method_name, only, except ]
55
+ end
56
+
57
+ end
58
+
59
+
60
+
61
+ module InstanceMethods
62
+
63
+ def initialize( action_name, client, params = {} )
64
+ @action_name = action_name
65
+ @action = self.class.action @action_name
66
+ @client = client
67
+ @params = params
68
+ end
69
+
70
+ def run
71
+ begin
72
+ run_filters :before
73
+ result = run_action
74
+ run_filters :after
75
+ rescue ControllerError => e
76
+ failure e.params
77
+ else
78
+ success result
79
+ end
80
+ end
81
+
82
+
83
+ protected
84
+
85
+ attr_reader :client, :params
86
+
87
+ def trigger( *args )
88
+ add_method_to_call :trigger, args
89
+ end
90
+
91
+ def error( params )
92
+ raise ControllerError, params
93
+ end
94
+
95
+
96
+ private
97
+
98
+ def run_action
99
+ instance_eval &@action
100
+ end
101
+
102
+ def run_filters( type )
103
+ self.class.select_filters( type, @action_name ).each { |method_name, only, except| send method_name }
104
+ end
105
+
106
+ def add_method_to_call( method, args )
107
+ Thread.current[ :methods_to_call ] << [ method, args ]
108
+ end
109
+
110
+ def success( *args )
111
+ add_method_to_call :success, args
112
+ end
113
+
114
+ def failure( *args )
115
+ add_method_to_call :failure, args
116
+ end
117
+
118
+ end
119
+
120
+
121
+
122
+ end
123
+
124
+ end
data/lib/apiway/diff.rb CHANGED
@@ -28,7 +28,7 @@ module Apiway
28
28
  else
29
29
 
30
30
  unless source.empty?
31
- @del[ @del_c ] = source.size
31
+ @del[ @del_c ] = @del_c + source.size
32
32
  end
33
33
 
34
34
  unless target.empty?
@@ -12,7 +12,7 @@ module Apiway
12
12
  create_model: [ '-m', 'm', 'model' ],
13
13
  help: [ '-h', 'h', 'help' ]
14
14
  }
15
-
15
+
16
16
  DESC = {
17
17
  create_application: 'Creating a new application (`apiway generate app Chat`)',
18
18
  create_controller: 'Creating a new controller (`apiway generate controller Messages`)',
@@ -74,10 +74,10 @@ module Apiway
74
74
  end
75
75
  end
76
76
  end
77
-
77
+
78
78
  def help( *args )
79
79
  puts "\n Apiway generator commands: \n\n"
80
- HANDLERS.each do |handler, commands|
80
+ HANDLERS.each do |handler, commands|
81
81
  puts " [#{ commands.join( "], [" ) }]".ljust(30) << "# #{ DESC[ handler ] } "
82
82
  end
83
83
  end
data/lib/apiway/logger.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  module Apiway
2
-
2
+
3
3
  module LoggerBase
4
-
5
-
4
+
5
+
6
6
  class << self
7
-
7
+
8
8
  def apiway_log_level( level )
9
9
  set_log_level( Log, level || :unknown )
10
10
  end
@@ -20,22 +20,22 @@ module Apiway
20
20
  end
21
21
  logger
22
22
  end
23
-
24
-
23
+
24
+
25
25
  private
26
26
 
27
27
  def set_log_level( logger, level )
28
28
  logger.level = Logger.const_get level.to_s.upcase
29
29
  logger
30
30
  end
31
-
32
- end
33
-
34
-
31
+
32
+ end
33
+
34
+
35
35
  end
36
36
 
37
37
 
38
38
  Log = LoggerBase::new_logger
39
-
39
+
40
40
 
41
41
  end
data/lib/apiway/model.rb CHANGED
@@ -1,58 +1,58 @@
1
- module Apiway
2
-
3
- module Model
4
-
5
-
6
-
7
- class << self
8
-
9
- def included( base )
10
- all << base
11
- base.class_eval do
12
- extend ClassMethods
13
- include InstanceMethods
14
- end
15
- end
16
-
17
- def all
18
- @all ||= []
19
- end
20
-
21
- end
22
-
23
-
24
-
25
- module ClassMethods
26
-
27
- def self.extended( base )
28
- base.class_eval do
29
-
30
- if self.ancestors.include? ActiveRecord::Base
31
- after_save :sync
32
- after_destroy :sync
33
- end
34
-
35
- end
36
- end
37
-
38
- def sync
39
- Thread.current[ :changed_models ] << self
40
- end
41
-
42
- end
43
-
44
-
45
-
46
- module InstanceMethods
47
-
48
- def sync
49
- self.class.sync
50
- end
51
-
52
- end
53
-
54
-
55
-
56
- end
57
-
58
- end
1
+ module Apiway
2
+
3
+ module Model
4
+
5
+
6
+
7
+ class << self
8
+
9
+ def included( base )
10
+ all << base
11
+ base.class_eval do
12
+ extend ClassMethods
13
+ include InstanceMethods
14
+ end
15
+ end
16
+
17
+ def all
18
+ @all ||= []
19
+ end
20
+
21
+ end
22
+
23
+
24
+
25
+ module ClassMethods
26
+
27
+ def self.extended( base )
28
+ base.class_eval do
29
+
30
+ if self.ancestors.include? ActiveRecord::Base
31
+ after_save :sync
32
+ after_destroy :sync
33
+ end
34
+
35
+ end
36
+ end
37
+
38
+ def sync
39
+ Thread.current[ :changed_models ] << self
40
+ end
41
+
42
+ end
43
+
44
+
45
+
46
+ module InstanceMethods
47
+
48
+ def sync
49
+ self.class.sync
50
+ end
51
+
52
+ end
53
+
54
+
55
+
56
+ end
57
+
58
+ end
data/lib/apiway/path.rb CHANGED
@@ -1,7 +1,7 @@
1
- module Apiway
2
-
3
- def self.path
4
- @gem_path ||= File.expand_path '..', File.dirname( __FILE__ )
5
- end
6
-
7
- end
1
+ module Apiway
2
+
3
+ def self.path
4
+ @gem_path ||= File.expand_path '..', File.dirname( __FILE__ )
5
+ end
6
+
7
+ end
@@ -1,5 +1,5 @@
1
1
  module Apiway
2
2
 
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
 
5
5
  end
@@ -6,4 +6,4 @@ gem 'apiway'
6
6
  # Use sqlite3 as the database for Active Record
7
7
  group :development, :test do
8
8
  gem 'sqlite3'
9
- end
9
+ end
@@ -1,3 +1,3 @@
1
- require './config/application'
2
-
3
- Apiway::Application.tasks
1
+ require './config/application'
2
+
3
+ Apiway::Application.tasks
@@ -1,5 +1,5 @@
1
1
  class Base
2
-
2
+
3
3
  protected
4
-
5
- end
4
+
5
+ end
@@ -1,5 +1,5 @@
1
1
  class ApplicationController < Base
2
-
2
+
3
3
  protected
4
4
 
5
5
  end
@@ -1,5 +1,5 @@
1
1
  class ApplicationResource < Base
2
-
2
+
3
3
  protected
4
4
 
5
5
  end
@@ -2,7 +2,7 @@ Apiway::Application.configure :development do |config|
2
2
 
3
3
 
4
4
  config.set apiway_log: :info
5
-
5
+
6
6
  config.set activerecord_log: :info
7
7
 
8
8
 
@@ -2,7 +2,7 @@ Apiway::Application.configure :production do |config|
2
2
 
3
3
 
4
4
  config.set apiway_log: false
5
-
5
+
6
6
  config.set activerecord_log: false
7
7
 
8
8
 
@@ -2,7 +2,7 @@ Apiway::Application.configure :test do |config|
2
2
 
3
3
 
4
4
  config.set apiway_log: :error
5
-
5
+
6
6
  config.set activerecord_log: :error
7
7
 
8
8
 
@@ -1,18 +1,18 @@
1
1
  class <%= classname %>Controller < ApplicationController
2
2
 
3
3
  include Apiway::Controller
4
-
5
-
4
+
5
+
6
6
  # before_action :auth?
7
-
7
+
8
8
  # action :new do
9
- #
9
+ #
10
10
  # begin
11
11
  # <%= modelname %>.create! params
12
12
  # rescue Exception => e
13
13
  # error e.message
14
14
  # end
15
- #
15
+ #
16
16
  # end
17
17
 
18
18
  # def auth?
@@ -11,17 +11,17 @@ class <%= classname %>Resource < ApplicationResource
11
11
 
12
12
 
13
13
  data do
14
-
14
+
15
15
  # <%= modelname %>.limit( params[ :limit ] ).map do |<%= varname %>|
16
16
  # {
17
17
  # id: <%= varname %>.id,
18
18
  # name: <%= varname %>.name
19
19
  # }
20
- # end
21
-
20
+ # end
21
+
22
22
  end
23
-
24
-
23
+
24
+
25
25
  # def auth?
26
26
  # error :auth_error unless client[ :user_id ]
27
27
  # end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apiway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - 4urbanoff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-13 00:00:00.000000000 Z
11
+ date: 2015-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thin