Class: ActiveApi::Definition
- Inherits:
-
Object
- Object
- ActiveApi::Definition
- Defined in:
- lib/active_api/definition.rb
Instance Attribute Summary collapse
-
#builder_class ⇒ Object
readonly
Returns the value of attribute builder_class.
-
#definition_name ⇒ Object
readonly
Returns the value of attribute definition_name.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Instance Method Summary collapse
- #attribute(*args) ⇒ Object
- #attributes ⇒ Object
- #belongs_to(name, options = {}) ⇒ Object
- #element(name, type = :string, options = {}) ⇒ Object
- #elements ⇒ Object
- #has_many(name, options = {}) ⇒ Object
- #has_one(name, options = {}) ⇒ Object
-
#initialize(options) ⇒ Definition
constructor
A new instance of Definition.
- #plural_name ⇒ Object
- #singular_name ⇒ Object
Constructor Details
#initialize(options) ⇒ Definition
Returns a new instance of Definition.
5 6 7 8 9 |
# File 'lib/active_api/definition.rb', line 5 def initialize() @definition_name = [:definition_name] @builder_class = [:builder_class] || ComplexType.to_s @fields = [:fields] || [] end |
Instance Attribute Details
#builder_class ⇒ Object (readonly)
Returns the value of attribute builder_class.
3 4 5 |
# File 'lib/active_api/definition.rb', line 3 def builder_class @builder_class end |
#definition_name ⇒ Object (readonly)
Returns the value of attribute definition_name.
3 4 5 |
# File 'lib/active_api/definition.rb', line 3 def definition_name @definition_name end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
3 4 5 |
# File 'lib/active_api/definition.rb', line 3 def fields @fields end |
Instance Method Details
#attribute(*args) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/active_api/definition.rb', line 11 def attribute(*args) = args. [:type] ||= :string .merge! :name => args.first, :field_type => :attribute field end |
#attributes ⇒ Object
51 52 53 54 55 |
# File 'lib/active_api/definition.rb', line 51 def attributes fields.select do |field| field.field_type == :attribute end end |
#belongs_to(name, options = {}) ⇒ Object
39 40 41 |
# File 'lib/active_api/definition.rb', line 39 def belongs_to(name, = {}) field .merge(:name => name, :type => :belongs_to, :klass => ComplexType) end |
#element(name, type = :string, options = {}) ⇒ Object
19 20 21 |
# File 'lib/active_api/definition.rb', line 19 def element(name, type = :string, = {}) send type, name, end |
#elements ⇒ Object
57 58 59 60 61 |
# File 'lib/active_api/definition.rb', line 57 def elements fields.select do |field| field.field_type == :element end end |
#has_many(name, options = {}) ⇒ Object
47 48 49 |
# File 'lib/active_api/definition.rb', line 47 def has_many(name, = {}) field .merge(:name => name, :type => :has_many, :klass => Collection) end |
#has_one(name, options = {}) ⇒ Object
43 44 45 |
# File 'lib/active_api/definition.rb', line 43 def has_one(name, = {}) field .merge(:name => name, :type => :has_one, :klass => ComplexType) end |
#plural_name ⇒ Object
67 68 69 |
# File 'lib/active_api/definition.rb', line 67 def plural_name name.to_s.pluralize end |
#singular_name ⇒ Object
63 64 65 |
# File 'lib/active_api/definition.rb', line 63 def singular_name name.to_s.singularize end |