Class: Model

Inherits:
Object
  • Object
show all
Defined in:
lib/model-visualizer/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Model

Returns a new instance of Model.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/model-visualizer/model.rb', line 22

def initialize(name)
    @name = name
    @belongs_to = Array.new
    @has_one = Array.new
    @has_many = Array.new
    @has_and_belongs_to_many = Array.new
    @integer_attributes = Array.new
    @string_attributes = Array.new
    @primary_key_attributes = Array.new
    @text_attributes = Array.new
    @float_attributes = Array.new
    @decimal_attributes = Array.new
    @datetime_attributes = Array.new
    @timestamp_attributes = Array.new
    @time_attributes = Array.new
    @date_attributes = Array.new
    @binary_attributes = Array.new
    @boolean_attributes = Array.new
    @foreign_keys = Array.new
end

Instance Attribute Details

#belongs_toObject (readonly)

Returns the value of attribute belongs_to.



4
5
6
# File 'lib/model-visualizer/model.rb', line 4

def belongs_to
  @belongs_to
end

#binary_attributesObject (readonly)

Returns the value of attribute binary_attributes.



18
19
20
# File 'lib/model-visualizer/model.rb', line 18

def binary_attributes
  @binary_attributes
end

#boolean_attributesObject (readonly)

Returns the value of attribute boolean_attributes.



19
20
21
# File 'lib/model-visualizer/model.rb', line 19

def boolean_attributes
  @boolean_attributes
end

#date_attributesObject (readonly)

Returns the value of attribute date_attributes.



17
18
19
# File 'lib/model-visualizer/model.rb', line 17

def date_attributes
  @date_attributes
end

#datetime_attributesObject (readonly)

Returns the value of attribute datetime_attributes.



14
15
16
# File 'lib/model-visualizer/model.rb', line 14

def datetime_attributes
  @datetime_attributes
end

#decimal_attributesObject (readonly)

Returns the value of attribute decimal_attributes.



13
14
15
# File 'lib/model-visualizer/model.rb', line 13

def decimal_attributes
  @decimal_attributes
end

#float_attributesObject (readonly)

Returns the value of attribute float_attributes.



12
13
14
# File 'lib/model-visualizer/model.rb', line 12

def float_attributes
  @float_attributes
end

#foreign_keysObject (readonly)

Returns the value of attribute foreign_keys.



20
21
22
# File 'lib/model-visualizer/model.rb', line 20

def foreign_keys
  @foreign_keys
end

#has_and_belongs_to_manyObject (readonly)

Returns the value of attribute has_and_belongs_to_many.



7
8
9
# File 'lib/model-visualizer/model.rb', line 7

def has_and_belongs_to_many
  @has_and_belongs_to_many
end

#has_manyObject (readonly)

Returns the value of attribute has_many.



6
7
8
# File 'lib/model-visualizer/model.rb', line 6

def has_many
  @has_many
end

#has_oneObject (readonly)

Returns the value of attribute has_one.



5
6
7
# File 'lib/model-visualizer/model.rb', line 5

def has_one
  @has_one
end

#integer_attributesObject (readonly)

Returns the value of attribute integer_attributes.



8
9
10
# File 'lib/model-visualizer/model.rb', line 8

def integer_attributes
  @integer_attributes
end

#primary_key_attributesObject (readonly)

Returns the value of attribute primary_key_attributes.



10
11
12
# File 'lib/model-visualizer/model.rb', line 10

def primary_key_attributes
  @primary_key_attributes
end

#string_attributesObject (readonly)

Returns the value of attribute string_attributes.



9
10
11
# File 'lib/model-visualizer/model.rb', line 9

def string_attributes
  @string_attributes
end

#text_attributesObject (readonly)

Returns the value of attribute text_attributes.



11
12
13
# File 'lib/model-visualizer/model.rb', line 11

def text_attributes
  @text_attributes
end

#time_attributesObject (readonly)

Returns the value of attribute time_attributes.



16
17
18
# File 'lib/model-visualizer/model.rb', line 16

def time_attributes
  @time_attributes
end

#timestamp_attributesObject (readonly)

Returns the value of attribute timestamp_attributes.



15
16
17
# File 'lib/model-visualizer/model.rb', line 15

def timestamp_attributes
  @timestamp_attributes
end

Instance Method Details

#add_belongs_to(model) ⇒ Object



43
44
45
# File 'lib/model-visualizer/model.rb', line 43

def add_belongs_to(model)
    @belongs_to << model
end

#add_binary_attribute(binary) ⇒ Object



99
100
101
# File 'lib/model-visualizer/model.rb', line 99

def add_binary_attribute(binary)
    @binary_attributes << binary
end

#add_boolean_attribute(boolean) ⇒ Object



103
104
105
# File 'lib/model-visualizer/model.rb', line 103

def add_boolean_attribute(boolean)
    @boolean_attributes << boolean
end

#add_date_attribute(date) ⇒ Object



95
96
97
# File 'lib/model-visualizer/model.rb', line 95

def add_date_attribute(date)
    @date_attributes << date
end

#add_datetime_attribute(datetime) ⇒ Object



83
84
85
# File 'lib/model-visualizer/model.rb', line 83

def add_datetime_attribute(datetime)
    @datetime_attributes << datetime
end

#add_decimal_attribute(decimal) ⇒ Object



79
80
81
# File 'lib/model-visualizer/model.rb', line 79

def add_decimal_attribute(decimal)
    @decimal_attributes << decimal
end

#add_float_attribute(float) ⇒ Object



75
76
77
# File 'lib/model-visualizer/model.rb', line 75

def add_float_attribute(float)
    @float_attributes << float
end

#add_foreign_key_attribute(key) ⇒ Object



107
108
109
# File 'lib/model-visualizer/model.rb', line 107

def add_foreign_key_attribute(key)
    @foreign_keys << key
end

#add_has_and_belongs_to_many(model) ⇒ Object



55
56
57
# File 'lib/model-visualizer/model.rb', line 55

def add_has_and_belongs_to_many(model)
    @has_and_belongs_to_many << model
end

#add_has_many(model) ⇒ Object



51
52
53
# File 'lib/model-visualizer/model.rb', line 51

def add_has_many(model)
    @has_many << model
end

#add_has_one(model) ⇒ Object



47
48
49
# File 'lib/model-visualizer/model.rb', line 47

def add_has_one(model)
    @has_one << model
end

#add_integer_attribute(integer) ⇒ Object



59
60
61
# File 'lib/model-visualizer/model.rb', line 59

def add_integer_attribute(integer)
    @integer_attributes << integer
end

#add_primary_key_attribute(primary_key) ⇒ Object



67
68
69
# File 'lib/model-visualizer/model.rb', line 67

def add_primary_key_attribute(primary_key)
    @primary_key_attributes << primary_key
end

#add_string_attribute(string) ⇒ Object



63
64
65
# File 'lib/model-visualizer/model.rb', line 63

def add_string_attribute(string)
    @string_attributes << string
end

#add_text_attribute(text) ⇒ Object



71
72
73
# File 'lib/model-visualizer/model.rb', line 71

def add_text_attribute(text)
    @text_attributes << text
end

#add_time_attribute(time) ⇒ Object



91
92
93
# File 'lib/model-visualizer/model.rb', line 91

def add_time_attribute(time)
    @time_attributes << time
end

#add_timestamp_attribute(timestamp) ⇒ Object



87
88
89
# File 'lib/model-visualizer/model.rb', line 87

def add_timestamp_attribute(timestamp)
    @timestamp_attributes << timestamp
end

#to_json(options = {}) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/model-visualizer/model.rb', line 111

def to_json(options = {})
    json = {
        'name' => @name,
        'associations' => {},
        'schema_info' => {}
    }

    if not @belongs_to.empty?
        json['associations']['belongs_to'] = @belongs_to
    end
    if not @has_one.empty?
        json['associations']['has_one'] = @has_one
    end
    if not @has_many.empty?
        json['associations']['has_many'] = @has_many
    end
    if not @has_and_belongs_to_many.empty?
        json['associations']['has_and_belongs_to_many'] = @has_and_belongs_to_many
    end

    if not @integer_attributes.empty?
        json['schema_info']['integer_attributes'] = @integer_attributes
    end
    if not @string_attributes.empty?
        json['schema_info']['string_attributes'] = @string_attributes
    end
    if not @primary_key_attributes.empty?
        json['schema_info']['primary_key_attributes'] = @primary_key_attributes
    end
    if not @text_attributes.empty?
        json['schema_info']['text_attributes'] = @text_attributes
    end
    if not @float_attributes.empty?
        json['schema_info']['float_attributes'] = @float_attributes
    end
    if not @decimal_attributes.empty?
        json['schema_info']['decimal_attributes'] = @decimal_attributes
    end
    if not @date_attributes.empty?
        json['schema_info']['date_attributes'] = @date_attributes
    end
    if not @datetime_attributes.empty?
        json['schema_info']['datetime_attributes'] = @datetime_attributes
    end
    if not @time_attributes.empty?
        json['schema_info']['time_attributes'] = @time_attributes
    end
    if not @timestamp_attributes.empty?
        json['schema_info']['timestamp_attributes'] = @timestamp_attributes
    end
    if not @binary_attributes.empty?
        json['schema_info']['binary_attributes'] = @binary_attributes
    end
    if not @boolean_attributes.empty?
        json['schema_info']['boolean_attributes'] = @boolean_attributes
    end
    if not @foreign_keys.empty?
        json['schema_info']['foreign_keys'] = @foreign_keys
    end

    json.to_json
end