Class: ActiveApi::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/active_api/definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options)
  @definition_name  = options[:definition_name]
  @builder_class    = options[:builder_class] || ComplexType.to_s
  @fields           = options[:fields] || []
end

Instance Attribute Details

#builder_classObject (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_nameObject (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

#fieldsObject (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(name, type = :string, options = {}) ⇒ Object



11
12
13
# File 'lib/active_api/definition.rb', line 11

def attribute(name, type = :string, options = {})
  field options.merge(:name => name, :type => type, :field_type => :attribute)
end

#attributesObject



47
48
49
50
51
# File 'lib/active_api/definition.rb', line 47

def attributes
  fields.select do |field|
    field.field_type == :attribute
  end
end

#belongs_to(name, options = {}) ⇒ Object



35
36
37
# File 'lib/active_api/definition.rb', line 35

def belongs_to(name, options = {})
  field options.merge(:name => name, :type => :belongs_to, :klass => ComplexType)
end

#element(name, type = :string, options = {}) ⇒ Object



15
16
17
# File 'lib/active_api/definition.rb', line 15

def element(name, type = :string, options = {})
  send type, name, options
end

#elementsObject



53
54
55
56
57
# File 'lib/active_api/definition.rb', line 53

def elements
  fields.select do |field|
    field.field_type == :element
  end
end

#has_many(name, options = {}) ⇒ Object



43
44
45
# File 'lib/active_api/definition.rb', line 43

def has_many(name, options = {})
  field options.merge(:name => name, :type => :has_many, :klass => Collection)
end

#has_one(name, options = {}) ⇒ Object



39
40
41
# File 'lib/active_api/definition.rb', line 39

def has_one(name, options = {})
  field options.merge(:name => name, :type => :has_one, :klass => ComplexType)
end

#plural_nameObject



63
64
65
# File 'lib/active_api/definition.rb', line 63

def plural_name
  name.to_s.pluralize
end

#singular_nameObject



59
60
61
# File 'lib/active_api/definition.rb', line 59

def singular_name
  name.to_s.singularize
end