flexible_api 0.0.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/flexible_api.rb CHANGED
@@ -16,6 +16,7 @@ module FlexibleApi
16
16
  end
17
17
 
18
18
  module ClassMethods
19
+ attr_accessor :levels
19
20
 
20
21
  def request_levels
21
22
  @levels.nil? ? [] : @levels.keys
@@ -60,6 +61,7 @@ module FlexibleApi
60
61
  def find_level(name = nil)
61
62
  @levels ||= {}
62
63
  level = name.nil? ? load_default_request_level : @levels[name.to_sym]
64
+ level = superclass.find_level(name) and @levels[name.to_sym] = level if level.nil? && superclass.present?
63
65
  raise NoSuchRequestLevelError.new(name, self.name) if level.nil?
64
66
  level
65
67
  end
@@ -39,6 +39,21 @@ module FlexibleApi
39
39
  requires *options[:requires]
40
40
  @notations[notation_name] = block
41
41
  end
42
+
43
+ def method(method_name, options = {})
44
+ options.assert_valid_keys :request_level, :as, :requires
45
+ method = @klass.instance_methods.detect { |m| m == method_name.to_sym }
46
+ raise "No such method on #{@klass.name}: #{method_name}" if method.nil?
47
+ notation_options = (options.has_key?(:requires) ? {:requires => options[:requires]} : {})
48
+ notation(options[:as] || method_name, notation_options) do
49
+ (method_contents = self.send(method_name)) or next
50
+ if method_contents.is_a?(Array)
51
+ method_contents.map {|content| content.to_hash(options[:request_level]) }
52
+ else
53
+ method_contents.to_hash(options[:request_level])
54
+ end
55
+ end
56
+ end
42
57
 
43
58
  def includes(association_name, options = {})
44
59
  options.assert_valid_keys :request_level, :as, :requires
@@ -1,5 +1,5 @@
1
1
  module FlexibleApi
2
2
 
3
- VERSION = '0.0.7'
3
+ VERSION = '0.1.0'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,112 +1,83 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: flexible_api
3
- version: !ruby/object:Gem::Version
4
- hash: 17
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 7
10
- version: 0.0.7
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - John Crepezzi
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-04-01 00:00:00 +01:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2011-10-07 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rspec
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70339779219960 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :development
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: sqlite3
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70339779219960
25
+ - !ruby/object:Gem::Dependency
26
+ name: sqlite3
27
+ requirement: &70339779218020 !ruby/object:Gem::Requirement
39
28
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
47
33
  type: :development
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: activerecord
51
34
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70339779218020
36
+ - !ruby/object:Gem::Dependency
37
+ name: activerecord
38
+ requirement: &70339779217220 !ruby/object:Gem::Requirement
53
39
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
61
44
  type: :runtime
62
- version_requirements: *id003
45
+ prerelease: false
46
+ version_requirements: *70339779217220
63
47
  description: API for making APIs
64
48
  email: john.crepezzi@gmail.com
65
49
  executables: []
66
-
67
50
  extensions: []
68
-
69
51
  extra_rdoc_files: []
70
-
71
- files:
52
+ files:
72
53
  - lib/flexible_api/no_such_request_level_error.rb
73
54
  - lib/flexible_api/request_level.rb
74
55
  - lib/flexible_api/version.rb
75
56
  - lib/flexible_api.rb
76
57
  - spec/spec_helper.rb
77
- has_rdoc: true
78
58
  homepage: http://github.com/seejohnrun/flexible_api
79
59
  licenses: []
80
-
81
60
  post_install_message:
82
61
  rdoc_options: []
83
-
84
- require_paths:
62
+ require_paths:
85
63
  - lib
86
- required_ruby_version: !ruby/object:Gem::Requirement
64
+ required_ruby_version: !ruby/object:Gem::Requirement
87
65
  none: false
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- hash: 3
92
- segments:
93
- - 0
94
- version: "0"
95
- required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
71
  none: false
97
- requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- hash: 3
101
- segments:
102
- - 0
103
- version: "0"
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
104
76
  requirements: []
105
-
106
77
  rubyforge_project: flexible_api
107
- rubygems_version: 1.4.1
78
+ rubygems_version: 1.8.10
108
79
  signing_key:
109
80
  specification_version: 3
110
81
  summary: A flexible API for making APIs
111
- test_files:
82
+ test_files:
112
83
  - spec/spec_helper.rb